Merge remote-tracking branch 'aosp/upstream-master' to 'aosp/master' for external/tensorflow.

Most of the changes are automatically merged, while the following files have conflicts that need to be manually resolved. When conflicts occur, 'aosp/upstream-master' is always preferred.

added by them:   tensorflow/compiler/mlir/hlo/include/mlir-hlo/Transforms/CMakeLists.txt
both modified:   tensorflow/core/platform/tstring.h
both modified:   tensorflow/lite/delegates/nnapi/nnapi_delegate.cc
both modified:   tensorflow/lite/kernels/BUILD
both modified:   tensorflow/lite/kernels/custom_ops_register.h
both added:      tensorflow/lite/kernels/random_uniform.cc
both added:      tensorflow/lite/kernels/random_uniform_test.cc
added by them:   third_party/absl/com_google_absl.BUILD
added by them:   third_party/farmhash/farmhash.BUILD

Also the following change are made:
1. Convert absl::string_view to std::string_view in tensorflow/core/platform/stringpiece.h
2. Include "fp16.h" in tensorflow/lite/delegates/nnapi/nnapi_delegate.cc and add "fp16_headers" in libtflite_framework.
3. Add missing dep files to libtflite_framework and libtflite_static including
"core/shims/jni/jni_utils.cc",
"delegates/serialization.cc",
"delegates/utils.cc",
"experimental/resource/initialization_status.cc",
"experimental/resource/static_hashtable.cc",
"interpreter_experimental.cc",
"kernels/assign_variable.cc",
"kernels/broadcast_args.cc",
"kernels/conv3d_transpose.cc",
"kernels/hashtable.cc",
"kernels/hashtable_find.cc",
"kernels/hashtable_import.cc",
"kernels/hashtable_size.cc",
"kernels/read_variable.cc",
"kernels/var_handle.cc",
"signature_runner.cc",
"simple_planner.cc",
"tools/versioning/op_signature.cc",
"tools/delegates/delegate_provider.cc",
"-Wno-missing-field-initializers",
"-Wno-user-defined-warnings",
4. Add "jni_headers" in libtflite_static.
5. Use "utils/hash/farmhash.h" instead of <farmash.h> in tensorflow/lite/delegates/serialization.cc
6. Add "guava-android-annotation-stubs" to tensorflowlite_java.

Bug: 196532440
Test: mma, NeuralNetworksTest_static

Change-Id: Ia1464753cfe38274b94fca992d757907985bd2c3
diff --git a/configure.py b/configure.py
index de564d5..df86b09 100644
--- a/configure.py
+++ b/configure.py
@@ -39,7 +39,9 @@
 _DEFAULT_TENSORRT_VERSION = '6'
 _DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,7.0'
 
-_SUPPORTED_ANDROID_NDK_VERSIONS = [10, 11, 12, 13, 14, 15, 16, 17, 18]
+_SUPPORTED_ANDROID_NDK_VERSIONS = [
+    10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
+]
 
 _DEFAULT_PROMPT_ASK_ATTEMPTS = 10
 
@@ -48,7 +50,7 @@
 _TF_BAZELRC = ''
 _TF_CURRENT_BAZEL_VERSION = None
 _TF_MIN_BAZEL_VERSION = '3.7.2'
-_TF_MAX_BAZEL_VERSION = '3.99.0'
+_TF_MAX_BAZEL_VERSION = '4.99.0'
 
 NCCL_LIB_PATHS = [
     'lib64/', 'lib/powerpc64le-linux-gnu/', 'lib/x86_64-linux-gnu/', ''
@@ -477,12 +479,13 @@
   Returns:
     The bazel version detected.
   """
-  if which('bazel') is None:
+  bazel_executable = which('bazel')
+  if bazel_executable is None:
     print('Cannot find bazel. Please install bazel.')
     sys.exit(1)
 
   stderr = open(os.devnull, 'wb')
-  curr_version = run_shell(['bazel', '--version'],
+  curr_version = run_shell([bazel_executable, '--version'],
                            allow_non_zero=True,
                            stderr=stderr)
   if curr_version.startswith('bazel '):
@@ -542,7 +545,6 @@
   for opt in cc_opt_flags.split():
     write_to_bazelrc('build:opt --copt=%s' % opt)
     write_to_bazelrc('build:opt --host_copt=%s' % opt)
-  write_to_bazelrc('build:opt --define with_default_optimizations=true')
 
 
 def set_tf_cuda_clang(environ_cp):
@@ -848,7 +850,8 @@
       environ_cp,
       var_name='GCC_HOST_COMPILER_PATH',
       var_default=default_gcc_host_compiler_path,
-      ask_for_var='Please specify which gcc should be used by nvcc as the host compiler.',
+      ask_for_var='Please specify which gcc should be used by nvcc as the host '
+      'compiler.',
       check_success=os.path.exists,
       resolve_symlinks=True,
       error_msg='Invalid gcc path. %s cannot be found.',
@@ -1202,13 +1205,12 @@
   print('\t--config=%-12s\t# %s' % (name, help_text))
 
 
-def configure_ios():
-  """Configures TensorFlow for iOS builds.
-
-  This function will only be executed if `is_macos()` is true.
-  """
+def configure_ios(environ_cp):
+  """Configures TensorFlow for iOS builds."""
   if not is_macos():
     return
+  if not get_var(environ_cp, 'TF_CONFIGURE_IOS', 'iOS', False):
+    return
   for filepath in APPLE_BAZEL_FILES:
     existing_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath + '.apple')
     renamed_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath)
@@ -1327,11 +1329,11 @@
 
   if is_macos():
     environ_cp['TF_NEED_TENSORRT'] = '0'
-  else:
-    environ_cp['TF_CONFIGURE_IOS'] = '0'
 
-  if environ_cp.get('TF_ENABLE_XLA', '1') == '1':
-    write_to_bazelrc('build --config=xla')
+  with_xla_support = environ_cp.get('TF_ENABLE_XLA', None)
+  if with_xla_support is not None:
+    write_to_bazelrc('build --define=with_xla_support=%s' %
+                     ('true' if int(with_xla_support) else 'false'))
 
   set_action_env_var(
       environ_cp, 'TF_NEED_ROCM', 'ROCm', False, bazel_config_name='rocm')
@@ -1343,11 +1345,8 @@
 
   if (environ_cp.get('TF_NEED_ROCM') == '1' and environ_cp.get('ROCM_PATH')):
     write_action_env_to_bazelrc('ROCM_PATH', environ_cp.get('ROCM_PATH'))
-
-  if ((environ_cp.get('TF_NEED_ROCM') == '1') and
-      (environ_cp.get('TF_ENABLE_MLIR_GENERATED_GPU_KERNELS') == '1')):
-    write_to_bazelrc(
-        'build:rocm --define tensorflow_enable_mlir_generated_gpu_kernels=1')
+    write_action_env_to_bazelrc('ROCBLAS_TENSILE_LIBPATH',
+                                environ_cp.get('ROCM_PATH') + '/lib/library')
 
   environ_cp['TF_NEED_CUDA'] = str(
       int(get_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)))
@@ -1455,26 +1454,24 @@
 
   system_specific_test_config(environ_cp)
 
-  set_action_env_var(environ_cp, 'TF_CONFIGURE_IOS', 'iOS', False)
-  if environ_cp.get('TF_CONFIGURE_IOS') == '1':
-    configure_ios()
+  configure_ios(environ_cp)
 
   print('Preconfigured Bazel build configs. You can use any of the below by '
         'adding "--config=<>" to your build command. See .bazelrc for more '
         'details.')
   config_info_line('mkl', 'Build with MKL support.')
-  config_info_line('mkl_aarch64', 'Build with oneDNN support for Aarch64.')
+  config_info_line(
+      'mkl_aarch64',
+      'Build with oneDNN and Compute Library for the Arm Architecture (ACL).')
   config_info_line('monolithic', 'Config for mostly static monolithic build.')
   config_info_line('numa', 'Build with NUMA support.')
   config_info_line(
       'dynamic_kernels',
       '(Experimental) Build kernels into separate shared objects.')
-  config_info_line('v2', 'Build TensorFlow 2.x instead of 1.x.')
+  config_info_line('v1', 'Build with TensorFlow 1 API instead of TF 2 API.')
 
   print('Preconfigured Bazel build configs to DISABLE default on features:')
-  config_info_line('noaws', 'Disable AWS S3 filesystem support.')
   config_info_line('nogcp', 'Disable GCP support.')
-  config_info_line('nohdfs', 'Disable HDFS support.')
   config_info_line('nonccl', 'Disable NVIDIA NCCL support.')