diff --git a/.bazelrc b/.bazelrc index 6ec5ec3aa0c..26decfcf779 100644 --- a/.bazelrc +++ b/.bazelrc @@ -19,6 +19,20 @@ build:android_x86_64 --fat_apk_cpu=x86_64 # Sets the default Apple platform to macOS. build --apple_platform_type=macos +# iOS configs for each architecture and the fat binary builds. +build:ios --apple_platform_type=ios +build:ios --apple_bitcode=embedded --copt=-fembed-bitcode +build:ios_armv7 --config=ios +build:ios_armv7 --cpu=ios_armv7 +build:ios_armv7 --cops -Wno-c++11-narrowing +build:ios_arm64 --config=ios +build:ios_arm64 --cpu=ios_arm64 +build:ios_x86_64 --config=ios +build:ios_x86_64 --cpu=ios_x86_64 +build:ios_fat --config=ios +build:ios_fat --ios_multi_cpus=armv7,arm64 +build:ios_fat --copt -Wno-c++11-narrowing + # Config to use a mostly-static build and disable modular op registration # support (this will revert to loading TensorFlow with RTLD_GLOBAL in Python). # By default, TensorFlow will build with a dependence on diff --git a/tensorflow/core/platform/default/env.cc b/tensorflow/core/platform/default/env.cc index b025e9c95da..fcc35d6ffc3 100644 --- a/tensorflow/core/platform/default/env.cc +++ b/tensorflow/core/platform/default/env.cc @@ -210,7 +210,7 @@ class PosixEnv : public Env { } // namespace -#if defined(PLATFORM_POSIX) || defined(__ANDROID__) +#if defined(PLATFORM_POSIX) || defined(__APPLE__) || defined(__ANDROID__) REGISTER_FILE_SYSTEM("", PosixFileSystem); REGISTER_FILE_SYSTEM("file", LocalPosixFileSystem); Env* Env::Default() { diff --git a/tensorflow/core/platform/dynamic_annotations.h b/tensorflow/core/platform/dynamic_annotations.h index 61c69c3ac8a..6d5e8e6ccd1 100644 --- a/tensorflow/core/platform/dynamic_annotations.h +++ b/tensorflow/core/platform/dynamic_annotations.h @@ -21,8 +21,9 @@ limitations under the License. // Include appropriate platform-dependent implementation. #if defined(PLATFORM_GOOGLE) #include "tensorflow/core/platform/google/dynamic_annotations.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_WINDOWS) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/default/dynamic_annotations.h" #else #error Define the appropriate PLATFORM_ macro for this platform diff --git a/tensorflow/core/platform/mutex.h b/tensorflow/core/platform/mutex.h index 0777ddeb497..16b4a992df7 100644 --- a/tensorflow/core/platform/mutex.h +++ b/tensorflow/core/platform/mutex.h @@ -28,8 +28,9 @@ limitations under the License. // Include appropriate platform-dependent implementation details of mutex etc. #if defined(PLATFORM_GOOGLE) #include "tensorflow/core/platform/google/mutex_data.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_WINDOWS) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/default/mutex_data.h" #else #error Define the appropriate PLATFORM_ macro for this platform @@ -301,8 +302,9 @@ inline Condition::Condition(const bool* flag) // Include appropriate platform-dependent implementation details of mutex etc. #if defined(PLATFORM_GOOGLE) #include "tensorflow/core/platform/google/mutex.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_WINDOWS) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/default/mutex.h" #else #error Define the appropriate PLATFORM_ macro for this platform diff --git a/tensorflow/core/platform/notification.h b/tensorflow/core/platform/notification.h index 0d477e8e1c2..97701a3ab55 100644 --- a/tensorflow/core/platform/notification.h +++ b/tensorflow/core/platform/notification.h @@ -21,8 +21,9 @@ limitations under the License. // Include appropriate platform-dependent implementations of Notification. #if defined(PLATFORM_GOOGLE) #include "tensorflow/core/platform/google/notification.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_WINDOWS) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/default/notification.h" #else #error Define the appropriate PLATFORM_ macro for this platform diff --git a/tensorflow/core/platform/platform.h b/tensorflow/core/platform/platform.h index b9ab596e3fe..2a5df8296b8 100644 --- a/tensorflow/core/platform/platform.h +++ b/tensorflow/core/platform/platform.h @@ -29,12 +29,12 @@ limitations under the License. #define IS_MOBILE_PLATFORM #elif defined(__APPLE__) -#define PLATFORM_POSIX #include "TargetConditionals.h" -#if TARGET_IPHONE_SIMULATOR -#define IS_MOBILE_PLATFORM -#elif TARGET_OS_IPHONE +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +#define PLATFORM_POSIX_IOS #define IS_MOBILE_PLATFORM +#else +#define PLATFORM_POSIX #endif #elif defined(_WIN32) diff --git a/tensorflow/core/platform/stacktrace.h b/tensorflow/core/platform/stacktrace.h index 3853fd49033..0489a516c3c 100644 --- a/tensorflow/core/platform/stacktrace.h +++ b/tensorflow/core/platform/stacktrace.h @@ -21,8 +21,9 @@ limitations under the License. // Include appropriate platform-dependent implementation. #if defined(PLATFORM_GOOGLE) #include "tensorflow/core/platform/google/stacktrace.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) #include "tensorflow/core/platform/default/stacktrace.h" #elif defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/windows/stacktrace.h" diff --git a/tensorflow/core/platform/subprocess.h b/tensorflow/core/platform/subprocess.h index d18b69a16a0..b2947f3944e 100644 --- a/tensorflow/core/platform/subprocess.h +++ b/tensorflow/core/platform/subprocess.h @@ -60,8 +60,9 @@ std::unique_ptr CreateSubProcess(const std::vector& argv); #if defined(PLATFORM_GOOGLE) #include "tensorflow/core/platform/google/subprocess.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) #include "tensorflow/core/platform/default/subprocess.h" #elif defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/windows/subprocess.h" diff --git a/tensorflow/core/platform/types.h b/tensorflow/core/platform/types.h index ef6a8f93332..a9cf98792f4 100644 --- a/tensorflow/core/platform/types.h +++ b/tensorflow/core/platform/types.h @@ -26,8 +26,9 @@ limitations under the License. #include "tensorflow/core/platform/google/integral_types.h" #elif defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/windows/integral_types.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) #include "tensorflow/core/platform/default/integral_types.h" #else #error Define the appropriate PLATFORM_ macro for this platform diff --git a/tensorflow/core/platform/unbounded_work_queue.h b/tensorflow/core/platform/unbounded_work_queue.h index 242980dafa9..f2405f0921e 100644 --- a/tensorflow/core/platform/unbounded_work_queue.h +++ b/tensorflow/core/platform/unbounded_work_queue.h @@ -23,8 +23,9 @@ limitations under the License. #if defined(PLATFORM_GOOGLE) #include "tensorflow/core/platform/google/unbounded_work_queue.h" -#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ - defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_WINDOWS) +#elif defined(PLATFORM_POSIX) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) || defined(PLATFORM_POSIX_IOS) || \ + defined(PLATFORM_GOOGLE_IOS) || defined(PLATFORM_WINDOWS) #include "tensorflow/core/platform/default/unbounded_work_queue.h" #else #error Define the appropriate PLATFORM_ macro for this platform diff --git a/tensorflow/lite/delegates/flex/BUILD b/tensorflow/lite/delegates/flex/BUILD index a8d0ad8f0df..2365b1e88dc 100644 --- a/tensorflow/lite/delegates/flex/BUILD +++ b/tensorflow/lite/delegates/flex/BUILD @@ -24,6 +24,9 @@ cc_library( "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", ], + "//tensorflow:ios": [ + "//tensorflow/core:ios_tensorflow_lib_lite", + ], "//conditions:default": [ "//tensorflow/c:c_api_internal", "//tensorflow/core:framework", @@ -61,6 +64,9 @@ cc_library( "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib", ], + "//tensorflow:ios": [ + "//tensorflow/core:ios_tensorflow_lib", + ], "//conditions:default": [ "//tensorflow/core:tensorflow", "//tensorflow/lite/c:c_api_internal", @@ -95,6 +101,9 @@ cc_library( "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", ], + "//tensorflow:ios": [ + "//tensorflow/core:ios_tensorflow_lib_lite", + ], "//conditions:default": [ "//tensorflow/core:lib", ], @@ -126,6 +135,9 @@ cc_library( "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", ], + "//tensorflow:ios": [ + "//tensorflow/core:ios_tensorflow_lib_lite", + ], "//conditions:default": [ "//tensorflow/core/common_runtime/eager:context", "//tensorflow/core:core_cpu", @@ -168,6 +180,9 @@ cc_library( "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", ], + "//tensorflow:ios": [ + "//tensorflow/core:ios_tensorflow_lib_lite", + ], "//conditions:default": [ "//tensorflow/core/common_runtime/eager:context", "//tensorflow/core/common_runtime/eager:execute", @@ -193,6 +208,9 @@ tf_cc_test( "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib", ], + "//tensorflow:ios": [ + "//tensorflow/core:ios_tensorflow_lib", + ], "//conditions:default": [ "//tensorflow/core:tensorflow", ], @@ -224,6 +242,9 @@ cc_library( "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", ], + "//tensorflow:ios": [ + "//tensorflow/core:ios_tensorflow_lib_lite", + ], "//conditions:default": [ "//tensorflow/c:c_api_internal", "//tensorflow/core:lib", diff --git a/tensorflow/lite/experimental/ios/BUILD.apple b/tensorflow/lite/experimental/ios/BUILD.apple index 6e5966d2638..58a57c00ba9 100644 --- a/tensorflow/lite/experimental/ios/BUILD.apple +++ b/tensorflow/lite/experimental/ios/BUILD.apple @@ -8,13 +8,18 @@ package( licenses = ["notice"], # Apache 2.0 ) +TFL_LIBRARY_HDRS = [ + "//tensorflow/lite/delegates/gpu:metal_delegate.h", + "//tensorflow/lite/experimental/c:c_api.h", +] + +TFL_FRAMEWORK_HDRS = TFL_LIBRARY_HDRS + [ + "//tensorflow/lite/experimental/c:c_api_types.h", +] + ios_static_framework( name = "TensorFlowLiteC_framework", - hdrs = [ - "//tensorflow/lite/delegates/gpu:metal_delegate.h", - "//tensorflow/lite/experimental/c:c_api.h", - "//tensorflow/lite/experimental/c:c_api_types.h", - ], + hdrs = TFL_FRAMEWORK_HDRS, bundle_name = "TensorFlowLiteC", minimum_os_version = TFL_MINIMUM_OS_VERSION, deps = [ @@ -22,16 +27,43 @@ ios_static_framework( ], ) +ios_static_framework( + name = "TensorFlowLiteCWithSelectTfOps_framework", + hdrs = TFL_FRAMEWORK_HDRS, + bundle_name = "TensorFlowLiteC", + minimum_os_version = TFL_MINIMUM_OS_VERSION, + deps = [ + ":TensorFlowLiteC", + "//tensorflow/lite/delegates/flex:delegate", + ], +) + objc_library( name = "TensorFlowLiteC", - hdrs = [ - "//tensorflow/lite/delegates/gpu:metal_delegate.h", - "//tensorflow/lite/experimental/c:c_api.h", - ], + hdrs = TFL_LIBRARY_HDRS, module_name = "TensorFlowLiteC", weak_sdk_frameworks = [ "Metal", ], + deps = [ + ":tensorflow_lite_c", + ], +) + +# Using this intermediate target is a workaround for a bug in bazel build rules +# involving mixed objc_library & cc_library deps mentioned in (b/74809458). +# When these dependencies are declared directly under the "TensorFlowLiteC" +# target above, the resulting static library incorrectly contains duplicate +# symbols from some ObjC code in the transitive dependencies. +# +# When a new dependency should be added to the TensorFlowLiteC framework, the +# dependency should be added under this target instead. +# When a new header file needs to be exposed, the header should be added to the +# TFL_LIBRARY_HDRS list above. +cc_library( + name = "tensorflow_lite_c", + hdrs = TFL_LIBRARY_HDRS, + tags = ["nobuilder"], deps = [ "//tensorflow/lite/delegates/gpu:metal_delegate", "//tensorflow/lite/experimental/c:c_api", diff --git a/tensorflow/lite/tools/evaluation/tasks/coco_object_detection/README.md b/tensorflow/lite/tools/evaluation/tasks/coco_object_detection/README.md index aa7905a2996..bc06e49b6c0 100644 --- a/tensorflow/lite/tools/evaluation/tasks/coco_object_detection/README.md +++ b/tensorflow/lite/tools/evaluation/tasks/coco_object_detection/README.md @@ -197,10 +197,8 @@ for configuring NDK and SDK. ``` bazel build -c opt \ - --config=android_arm \ + --config=android_arm64 \ --cxxopt='--std=c++11' \ - --copt=-D__ANDROID_TYPES_FULL__ \ - --copt=-DSUPPORT_SELECTIVE_REGISTRATION \ //tensorflow/lite/tools/evaluation/tasks/coco_object_detection:run_eval ``` diff --git a/tensorflow/lite/tools/evaluation/tasks/imagenet_image_classification/README.md b/tensorflow/lite/tools/evaluation/tasks/imagenet_image_classification/README.md index 382719f012d..90c3cfda5da 100644 --- a/tensorflow/lite/tools/evaluation/tasks/imagenet_image_classification/README.md +++ b/tensorflow/lite/tools/evaluation/tasks/imagenet_image_classification/README.md @@ -142,10 +142,8 @@ for configuring NDK and SDK. ``` bazel build -c opt \ - --config=android_arm \ + --config=android_arm64 \ --cxxopt='--std=c++11' \ - --copt=-D__ANDROID_TYPES_FULL__ \ - --copt=-DSUPPORT_SELECTIVE_REGISTRATION \ //tensorflow/lite/tools/evaluation/tasks/imagenet_image_classification:run_eval ```