Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions extension/llm/custom_ops/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load(
"@fbsource//xplat/executorch/kernels/optimized:lib_defs.bzl",
"get_vec_preprocessor_flags",
"get_vec_deps",
)
load(
"@fbsource//xplat/executorch/kernels/portable:op_registration_util.bzl",
"get_compiler_optimization_flags",
)


def define_common_targets():
"""Defines targets that should be shared between fbcode and xplat.
Expand All @@ -26,6 +30,7 @@ def define_common_targets():
"op_sdpa.h",
"op_update_quantized_cache.h",
],
preprocessor_flags = get_vec_preprocessor_flags(),
exported_deps = [
"//executorch/runtime/kernel:kernel_includes",
"//executorch/kernels/portable/cpu:scalar_utils",
Expand All @@ -38,7 +43,7 @@ def define_common_targets():
deps = [
"//executorch/kernels/portable/cpu/util:reduce_util",
"//executorch/extension/llm/custom_ops/spinquant:fast_hadamard_transform",
],
] + get_vec_deps(),
compiler_flags = ["-Wno-missing-prototypes", "-Wno-global-constructors"] + get_compiler_optimization_flags(),
visibility = [
"//executorch/...",
Expand Down
46 changes: 37 additions & 9 deletions kernels/optimized/lib_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,44 @@ load(
# functions in order to declare the required compiler flags needed in order to
# access CPU vector intrinsics.

def get_vec_android_preprocessor_flags():
preprocessor_flags = [
(
"^android-arm64.*$",
[
def get_vec_preprocessor_flags():
if not runtime.is_oss:
# various ovr_configs are not available in oss
preprocessor_flags = select({
"ovr_config//os:linux-x86_64": [
"-DET_BUILD_ARM_VEC256_WITH_SLEEF",
],
),
]
return preprocessor_flags
] if not runtime.is_oss else [],
"ovr_config//os:iphoneos-arm64": [
"-DET_BUILD_ARM_VEC256_WITH_SLEEF",
] if not runtime.is_oss else [],
"ovr_config//os:macos-arm64": [
"-DET_BUILD_ARM_VEC256_WITH_SLEEF",
] if not runtime.is_oss else [],
"ovr_config//os:android-arm64": [
"-DET_BUILD_ARM_VEC256_WITH_SLEEF",
] if not runtime.is_oss else [],
"DEFAULT": [],
})
return preprocessor_flags
return []

def get_vec_deps():
if not runtime.is_oss:
# various ovr_configs are not available in oss
deps = select({
"ovr_config//os:iphoneos-arm64": [
"fbsource//third-party/sleef:sleef_arm",
] if not runtime.is_oss else [],
"ovr_config//os:macos-arm64": [
"fbsource//third-party/sleef:sleef_arm",
] if not runtime.is_oss else [],
"ovr_config//os:android-arm64": [
"fbsource//third-party/sleef:sleef_arm",
] if not runtime.is_oss else [],
"DEFAULT": [],
})
return deps
return []

def get_vec_cxx_preprocessor_flags():
preprocessor_flags = [
Expand Down
7 changes: 4 additions & 3 deletions kernels/optimized/op_registration_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbsource//xplat/executorch/build:selects.bzl", "selects")
load(
"@fbsource//xplat/executorch/kernels/optimized:lib_defs.bzl",
"get_vec_android_preprocessor_flags",
"get_vec_preprocessor_flags",
"get_vec_deps",
)
load(
"@fbsource//xplat/executorch/kernels/portable:op_registration_util.bzl",
Expand Down Expand Up @@ -94,8 +95,8 @@ def define_op_library(name, deps):
compiler_flags = ["-Wno-missing-prototypes"] + get_compiler_optimization_flags(),
deps = [
"//executorch/runtime/kernel:kernel_includes",
] + augmented_deps,
fbandroid_platform_preprocessor_flags = get_vec_android_preprocessor_flags(),
] + augmented_deps + get_vec_deps(),
preprocessor_flags = get_vec_preprocessor_flags(),
# sleef needs to be added as a direct dependency of the operator target when building for Android,
# or a linker error may occur. Not sure why this happens; it seems that fbandroid_platform_deps of
# dependencies are not transitive
Expand Down
4 changes: 2 additions & 2 deletions kernels/optimized/test/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load(
"@fbsource//xplat/executorch/kernels/optimized:lib_defs.bzl",
"get_vec_android_preprocessor_flags",
"get_vec_preprocessor_flags",
"get_vec_cxx_preprocessor_flags",
)
load("@fbsource//xplat/executorch/kernels/test:util.bzl", "define_supported_features_lib")
Expand All @@ -27,7 +27,7 @@ def _lib_test_bin(name, extra_deps = [], in_cpu = False):
"//executorch/kernels/optimized{}:{}".format(cpu_path, lib_root),
] + extra_deps,
cxx_platform_preprocessor_flags = get_vec_cxx_preprocessor_flags(),
fbandroid_platform_preprocessor_flags = get_vec_android_preprocessor_flags(),
preprocessor_flags = get_vec_preprocessor_flags(),
)

def define_common_targets():
Expand Down
48 changes: 39 additions & 9 deletions shim/xplat/executorch/kernels/optimized/lib_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,46 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
# functions in order to declare the required compiler flags needed in order to
# access CPU vector intrinsics.

def get_vec_android_preprocessor_flags():
preprocessor_flags = [
(
"^android-arm64.*$",
[
# This oopy from kernels/optimized/lib_defs.bzl is not necessary.
# This file really needs to be removed
def get_vec_preprocessor_flags():
if not runtime.is_oss:
# various ovr_configs are not available in oss
preprocessor_flags = select({
"ovr_config//os:iphoneos": [
"-DET_BUILD_ARM_VEC256_WITH_SLEEF",
],
),
]
return preprocessor_flags
] if not runtime.is_oss else [],
"ovr_config//os:macos-arm64": [
"-DET_BUILD_ARM_VEC256_WITH_SLEEF",
] if not runtime.is_oss else [],
"ovr_config//os:android-arm64": [
"-DET_BUILD_ARM_VEC256_WITH_SLEEF",
] if not runtime.is_oss else [],
"DEFAULT": [],
})
return preprocessor_flags
return []

def get_vec_deps():
if not runtime.is_oss:
# various ovr_configs are not available in oss
deps = select({
"ovr_config//os:linux-x86_64": [
"fbsource//third-party/sleef:sleef",
] if not runtime.is_oss else [],
"ovr_config//os:iphoneos": [
"fbsource//third-party/sleef:sleef_arm",
] if not runtime.is_oss else [],
"ovr_config//os:macos-arm64": [
"fbsource//third-party/sleef:sleef_arm",
] if not runtime.is_oss else [],
"ovr_config//os:android-arm64": [
"fbsource//third-party/sleef:sleef_arm",
] if not runtime.is_oss else [],
"DEFAULT": [],
})
return deps
return []

def get_vec_cxx_preprocessor_flags():
preprocessor_flags = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
load("@fbsource//xplat/executorch/build:selects.bzl", "selects")
load(
"@fbsource//xplat/executorch/kernels/optimized:lib_defs.bzl",
"get_vec_android_preprocessor_flags",
"get_vec_preprocessor_flags",
)

def op_target(name, deps = []):
Expand Down Expand Up @@ -98,7 +98,7 @@ def define_op_library(name, deps):
deps = [
"//executorch/runtime/kernel:kernel_includes",
] + augmented_deps,
fbandroid_platform_preprocessor_flags = get_vec_android_preprocessor_flags(),
preprocessor_flags = get_vec_preprocessor_flags(),
# sleef needs to be added as a direct dependency of the operator target when building for Android,
# or a linker error may occur. Not sure why this happens; it seems that fbandroid_platform_deps of
# dependencies are not transitive
Expand Down
Loading