diff --git a/tensorflow/lite/kernels/BUILD b/tensorflow/lite/kernels/BUILD index b16a85c65d8..9d3e5929d82 100644 --- a/tensorflow/lite/kernels/BUILD +++ b/tensorflow/lite/kernels/BUILD @@ -14,8 +14,8 @@ package( # This will cause TFLite to build with ruy only, providing a smaller binary. # WARNING: This build flag is experimental and subject to change. config_setting( - name = "tflite_with_ruy_only_explicit_true", - define_values = {"TFLITE_WITH_RUY_ONLY": "true"}, + name = "tflite_with_ruy_explicit_true", + define_values = {"tflite_with_ruy": "true"}, ) # Disables usage of ruy as the exclusive GEMM backend in TFLite kernels. @@ -23,14 +23,14 @@ config_setting( # the default GEMM option at runtime. # WARNING: This build flag is experimental and subject to change. config_setting( - name = "tflite_with_ruy_only_explicit_false", - define_values = {"TFLITE_WITH_RUY_ONLY": "false"}, + name = "tflite_with_ruy_explicit_false", + define_values = {"tflite_with_ruy": "false"}, ) ###### Beginning of config_setting's to match aarch64 ###### # # We need to identify the aarch64 instruction set to decide whether to enable -# TFLITE_WITH_RUY_ONLY by default. This is surprisingly hard to do because select() +# TFLITE_WITH_RUY by default. This is surprisingly hard to do because select() # can only consume config_setting's, these config_settings are not centralized, # and the "cpu" value which they define are free-form strings and there is no # standardization of the strings that we need to match for the aarch64 architecture. @@ -239,45 +239,45 @@ cc_test( ) cc_library( - name = "tflite_with_ruy_only_enabled", + name = "tflite_with_ruy_enabled", build_for_embedded = True, - defines = ["TFLITE_WITH_RUY_ONLY"], + defines = ["TFLITE_WITH_RUY"], visibility = ["//visibility:private"], ) cc_library( - name = "tflite_with_ruy_only_and_caching_enabled", + name = "tflite_with_ruy_and_caching_enabled", defines = [ - "TFLITE_WITH_RUY_ONLY", + "TFLITE_WITH_RUY", "TFLITE_WITH_RUY_GEMV", ], visibility = ["//visibility:private"], ) cc_library( - name = "tflite_with_ruy_only_default", + name = "tflite_with_ruy_default", build_for_embedded = True, select_deps = { - ":chromiumos_arm64": [":tflite_with_ruy_only_enabled"], - ":cpu_aarch64": [":tflite_with_ruy_only_enabled"], - ":cpu_arm64": [":tflite_with_ruy_only_enabled"], - ":cpu_arm64e": [":tflite_with_ruy_only_enabled"], - ":cpu_ios_arm64": [":tflite_with_ruy_only_enabled"], - ":cpu_ios_arm64e": [":tflite_with_ruy_only_enabled"], - ":cpu_arm64_v8a": [":tflite_with_ruy_only_enabled"], - "//tensorflow:android_arm": ["tflite_with_ruy_only_enabled"], + ":chromiumos_arm64": [":tflite_with_ruy_enabled"], + ":cpu_aarch64": [":tflite_with_ruy_enabled"], + ":cpu_arm64": [":tflite_with_ruy_enabled"], + ":cpu_arm64e": [":tflite_with_ruy_enabled"], + ":cpu_ios_arm64": [":tflite_with_ruy_enabled"], + ":cpu_ios_arm64e": [":tflite_with_ruy_enabled"], + ":cpu_arm64_v8a": [":tflite_with_ruy_enabled"], + "//tensorflow:android_arm": ["tflite_with_ruy_enabled"], "//conditions:default": [], }, visibility = ["//visibility:private"], ) cc_library( - name = "tflite_with_ruy_only", + name = "tflite_with_ruy", build_for_embedded = True, select_deps = { - ":tflite_with_ruy_only_explicit_true": [":tflite_with_ruy_only_enabled"], - ":tflite_with_ruy_only_explicit_false": [], - "//conditions:default": [":tflite_with_ruy_only_default"], + ":tflite_with_ruy_explicit_true": [":tflite_with_ruy_enabled"], + ":tflite_with_ruy_explicit_false": [], + "//conditions:default": [":tflite_with_ruy_default"], }, ) @@ -291,7 +291,7 @@ cc_library( ], copts = tflite_copts(), deps = [ - ":tflite_with_ruy_only", + ":tflite_with_ruy", ":op_macros", # For now this unconditionally depends on both ruy and gemmlowp. # See the comment inside class CpuBackendContext on the @@ -311,11 +311,11 @@ cc_library( copts = tflite_copts(), deps = [ ":cpu_backend_context", - ":tflite_with_ruy_only", + ":tflite_with_ruy", "//tensorflow/lite/kernels/internal:compatibility", "//tensorflow/lite/kernels/internal:types", # For now this unconditionally depends on both ruy and gemmlowp. - # We only need to depend on gemmlowp when tflite_with_ruy_only + # We only need to depend on gemmlowp when tflite_with_ruy # is false, but putting these dependencies in a select() seems to # defeat copybara's rewriting rules. "@ruy//ruy:context", @@ -349,20 +349,20 @@ cc_library( ], copts = tflite_copts(), deps = [ - ":tflite_with_ruy_only", + ":tflite_with_ruy", "//tensorflow/lite/kernels/internal:common", "//tensorflow/lite/kernels/internal:compatibility", "//tensorflow/lite/kernels/internal:cpu_check", "//tensorflow/lite/kernels/internal:types", ":cpu_backend_context", ":cpu_backend_threadpool", - # Depend on ruy regardless of `tflite_with_ruy_only`. See the comment in + # Depend on ruy regardless of `tflite_with_ruy`. See the comment in # cpu_backend_gemm.h about why ruy is the generic path. "@ruy//ruy", "@ruy//ruy:matrix", "@ruy//ruy:path", "@ruy//ruy/profiler:instrumentation", - # We only need to depend on gemmlowp and Eigen when tflite_with_ruy_only + # We only need to depend on gemmlowp and Eigen when tflite_with_ruy # is false, but putting these dependencies in a select() seems to # defeat copybara's rewriting rules. "@gemmlowp", @@ -605,7 +605,7 @@ cc_library( "//tensorflow/lite/kernels/internal:cppmath", "//tensorflow/lite:string", "@farmhash_archive//:farmhash", - ] + [":tflite_with_ruy_only_and_caching_enabled"], + ] + [":tflite_with_ruy_and_caching_enabled"], ) cc_library( diff --git a/tensorflow/lite/kernels/conv.cc b/tensorflow/lite/kernels/conv.cc index 88765b2f9c4..81069de1abe 100644 --- a/tensorflow/lite/kernels/conv.cc +++ b/tensorflow/lite/kernels/conv.cc @@ -26,7 +26,7 @@ limitations under the License. #include "tensorflow/lite/kernels/internal/compatibility.h" #include "tensorflow/lite/kernels/internal/types.h" // b/131835803 forces us to include multithreaded_conv.h before optimized_ops.h -#ifndef TFLITE_WITH_RUY_ONLY +#ifndef TFLITE_WITH_RUY #include "tensorflow/lite/kernels/internal/optimized/multithreaded_conv.h" #endif #include "tensorflow/lite/kernels/internal/optimized/optimized_ops.h" @@ -765,8 +765,8 @@ void EvalFloat(TfLiteContext* context, TfLiteNode* node, break; } case kMultithreadOptimized: { -#ifdef TFLITE_WITH_RUY_ONLY - // See Register_CONV_2D: we should never be here when TFLITE_WITH_RUY_ONLY +#ifdef TFLITE_WITH_RUY + // See Register_CONV_2D: we should never be here when TFLITE_WITH_RUY // was enabled. We #if out this code in order to get the corresponding // binary size benefits. TFLITE_DCHECK(false); @@ -1051,8 +1051,8 @@ TfLiteRegistration* Register_CONVOLUTION_CBLAS_OPT() { TfLiteRegistration* Register_CONV_2D() { #if defined TFLITE_USE_APPLE_ACCELERATE_FOR_CONV return Register_CONVOLUTION_CBLAS_OPT(); -#elif defined TFLITE_WITH_RUY_ONLY - // TFLITE_WITH_RUY_ONLY optimizes the generic kernel type. +#elif defined TFLITE_WITH_RUY + // TFLITE_WITH_RUY optimizes the generic kernel type. return Register_CONVOLUTION_GENERIC_OPT(); #else return Register_CONVOLUTION_MULTITHREADED_OPT(); @@ -1063,8 +1063,8 @@ TfLiteRegistration* Register_CONV_2D() { // models only need the UINT8 type. TFLite's op registration mechanism doesn't // yet allow for more nuanced registration mechanisms. TfLiteRegistration* Register_CONV_2D_UINT8() { -#if defined TFLITE_WITH_RUY_ONLY - // TFLITE_WITH_RUY_ONLY optimizes the generic kernel type. +#if defined TFLITE_WITH_RUY + // TFLITE_WITH_RUY optimizes the generic kernel type. return Register_CONVOLUTION_GENERIC_OPT_UINT8(); #else return Register_CONV_2D(); diff --git a/tensorflow/lite/kernels/conv_test.cc b/tensorflow/lite/kernels/conv_test.cc index a1fd34eb1cb..ac78bc6b353 100644 --- a/tensorflow/lite/kernels/conv_test.cc +++ b/tensorflow/lite/kernels/conv_test.cc @@ -148,7 +148,7 @@ class ConvolutionOpModel : public BaseConvolutionOpModel { const auto kKernelMap = new std::map({ {"Reference", ops::builtin::Register_CONVOLUTION_REF()}, {"GenericOptimized", ops::builtin::Register_CONVOLUTION_GENERIC_OPT()}, -#ifndef TFLITE_WITH_RUY_ONLY +#ifndef TFLITE_WITH_RUY {"MultithreadedOptimized", ops::builtin::Register_CONVOLUTION_MULTITHREADED_OPT()}, #endif diff --git a/tensorflow/lite/kernels/cpu_backend_context.h b/tensorflow/lite/kernels/cpu_backend_context.h index 19ef88bf8e3..124b9b849a2 100644 --- a/tensorflow/lite/kernels/cpu_backend_context.h +++ b/tensorflow/lite/kernels/cpu_backend_context.h @@ -56,7 +56,7 @@ class CpuBackendContext final : public TfLiteInternalBackendContext { // (see :cpu_backend_gemm), for now a CpuBackendContext always // stores both a gemmlowp context and a ruy context. // TODO(b/131416458): Once call sites all go through abstractions, - // elide what can be elided based on TFLITE_WITH_RUY_ONLY. + // elide what can be elided based on TFLITE_WITH_RUY. const std::unique_ptr ruy_context_; const std::unique_ptr gemmlowp_context_; diff --git a/tensorflow/lite/kernels/cpu_backend_gemm.h b/tensorflow/lite/kernels/cpu_backend_gemm.h index f4d20d8970a..a95c4d15a82 100644 --- a/tensorflow/lite/kernels/cpu_backend_gemm.h +++ b/tensorflow/lite/kernels/cpu_backend_gemm.h @@ -24,7 +24,7 @@ limitations under the License. #include "tensorflow/lite/kernels/cpu_backend_gemm_params.h" #include "tensorflow/lite/kernels/cpu_backend_gemm_ruy.h" -#ifndef TFLITE_WITH_RUY_ONLY +#ifndef TFLITE_WITH_RUY #include "tensorflow/lite/kernels/cpu_backend_gemm_eigen.h" #include "tensorflow/lite/kernels/cpu_backend_gemm_gemmlowp.h" #endif @@ -42,7 +42,7 @@ template {}; -#ifndef TFLITE_WITH_RUY_ONLY +#ifndef TFLITE_WITH_RUY /* Specializations using gemmlowp */ @@ -82,7 +82,7 @@ template <> struct GemmImpl : detail::GemmImplUsingEigen {}; -#endif // not TFLITE_WITH_RUY_ONLY +#endif // not TFLITE_WITH_RUY /* Public entry point */ diff --git a/tensorflow/lite/kernels/cpu_backend_gemm_custom_gemv.h b/tensorflow/lite/kernels/cpu_backend_gemm_custom_gemv.h index 224f8ecea41..2712d7d2cd1 100644 --- a/tensorflow/lite/kernels/cpu_backend_gemm_custom_gemv.h +++ b/tensorflow/lite/kernels/cpu_backend_gemm_custom_gemv.h @@ -591,10 +591,10 @@ struct CustomGemvImpl #include "tensorflow/lite/kernels/internal/compatibility.h" -#ifndef TFLITE_WITH_RUY_ONLY +#ifndef TFLITE_WITH_RUY #include #include @@ -190,6 +190,6 @@ struct GemmImplUsingGemmlowpmax_num_threads(); thread_count = std::max(1, std::min(thread_count, max_threads)); -#ifndef TFLITE_WITH_RUY_ONLY +#ifndef TFLITE_WITH_RUY // Cap the number of threads to 2 for float path to avoid regression in // performance (b/132294857). if (std::is_floating_point::value) { diff --git a/tensorflow/lite/tools/make/Makefile b/tensorflow/lite/tools/make/Makefile index 266aa94ad93..f8b67fbbe7d 100644 --- a/tensorflow/lite/tools/make/Makefile +++ b/tensorflow/lite/tools/make/Makefile @@ -187,7 +187,7 @@ ifeq ($(TARGET_ARCH),aarch64) BUILD_WITH_RUY=true endif ifeq ($(BUILD_WITH_RUY),true) - CXXFLAGS += -DTFLITE_WITH_RUY_ONLY + CXXFLAGS += -DTFLITE_WITH_RUY endif BUILD_WITH_RUY_PROFILER ?= false