diff --git a/kernels/optimized/TARGETS b/kernels/optimized/TARGETS index 2341af9282f..beaebb81eeb 100644 --- a/kernels/optimized/TARGETS +++ b/kernels/optimized/TARGETS @@ -5,4 +5,4 @@ load(":targets.bzl", "define_common_targets") oncall("executorch") -define_common_targets() +define_common_targets(True) diff --git a/kernels/optimized/lib_defs.bzl b/kernels/optimized/lib_defs.bzl index c3799f7db51..fb1c9a17f99 100644 --- a/kernels/optimized/lib_defs.bzl +++ b/kernels/optimized/lib_defs.bzl @@ -43,12 +43,56 @@ def get_vec_fbcode_preprocessor_flags(): ] return preprocessor_flags +def get_apple_framework_deps_kwargs(is_fbcode): + # various ovr_configs are not available in oss + if not runtime.is_oss and not is_fbcode: + # Jump through few hoops since 'frameworks' is not a valid kwarg + # for some buck rules + frameworks = {'frameworks': select({ + "DEFAULT": [], + "ovr_config//os:iphoneos": ["$SDKROOT/System/Library/Frameworks/Accelerate.framework"], + "ovr_config//os:macos-arm64": ["$SDKROOT/System/Library/Frameworks/Accelerate.framework"], + "ovr_config//os:macos-x86_64": ["$SDKROOT/System/Library/Frameworks/Accelerate.framework"], + })} + return frameworks + return {'fbobjc_frameworks': ["Accelerate"]} + +def get_preprocessor_flags(): + # various ovr_configs are not available in oss + preprocessor_flags = select({ + ":linux-x86_64": [ + "-DET_BUILD_WITH_BLAS", + ] if not runtime.is_oss else [], + "DEFAULT": [], + }) + + if not runtime.is_oss: + # various ovr_configs are not available in oss + additional_preprocessor_flags = select({ + "ovr_config//os:iphoneos": [ + "-DET_BUILD_WITH_BLAS", + "-DET_BUILD_FOR_APPLE", + ] if not runtime.is_oss else [], + "ovr_config//os:macos-arm64": [ + "-DET_BUILD_WITH_BLAS", + "-DET_BUILD_FOR_APPLE", + ] if not runtime.is_oss else [], + "ovr_config//os:macos-x86_64": [ + "-DET_BUILD_WITH_BLAS", + "-DET_BUILD_FOR_APPLE", + ] if not runtime.is_oss else [], + "DEFAULT": [], + }) + preprocessor_flags = preprocessor_flags + additional_preprocessor_flags + return preprocessor_flags + + # Currently, having a dependency on fbsource//third-party/sleef:sleef may cause # duplicate symbol errors when linking fbcode targets in opt mode that also # depend on ATen. This is because ATen accesses sleef via the third-party folder # in caffe2 (caffe2/third-party//sleef:sleef). # TODO(ssjia): Enable -DCPU_CAPABILITY_AVX2 in fbcode, which requires sleef. -def define_libs(): +def define_libs(is_fbcode=False): runtime.cxx_library( name = "libvec", srcs = [], @@ -131,12 +175,7 @@ def define_libs(): "//executorch/...", "@EXECUTORCH_CLIENTS", ], - preprocessor_flags = select({ - ":linux-x86_64": [ - "-DET_BUILD_WITH_BLAS", - ] if not runtime.is_oss else [], - "DEFAULT": [], - }), + preprocessor_flags = get_preprocessor_flags(), fbandroid_platform_preprocessor_flags = [ ( "^android-arm64.*$", @@ -157,9 +196,6 @@ def define_libs(): "-DET_BUILD_WITH_BLAS", "-DET_BUILD_FOR_APPLE", ], - fbobjc_frameworks = [ - "Accelerate", - ], deps = select({ ":linux-x86_64": [mkl_dep] if not runtime.is_oss else [], "DEFAULT": [], @@ -169,4 +205,5 @@ def define_libs(): "//executorch/kernels/optimized:libutils", "//executorch/runtime/core/exec_aten:lib", ], + **get_apple_framework_deps_kwargs(is_fbcode), ) diff --git a/kernels/optimized/targets.bzl b/kernels/optimized/targets.bzl index 88afe5011d3..9978d4196dd 100644 --- a/kernels/optimized/targets.bzl +++ b/kernels/optimized/targets.bzl @@ -2,14 +2,14 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") load("@fbsource//xplat/executorch/codegen:codegen.bzl", "et_operator_library", "executorch_generated_lib") load(":lib_defs.bzl", "define_libs") -def define_common_targets(): +def define_common_targets(is_fbcode=False): """Defines targets that should be shared between fbcode and xplat. The directory containing this targets.bzl file should also contain both TARGETS and BUCK files that call this function. """ - define_libs() + define_libs(is_fbcode) runtime.export_file( name = "optimized.yaml",