Skip to content

Commit e3b34f7

Browse files
GregoryComerfacebook-github-bot
authored andcommitted
Build CPUBLAS as a separate CMake target (#2601)
Summary: Split out CPUBLAS build from optimized kernel to promote reuse. Overriding pre-existing CI failures in llama runner and mac unit test. bypass-github-export-checks bypass-github-executorch-ci-checks Pull Request resolved: #2601 Test Plan: External CI. Ran add model with executor_runner. Reviewed By: mcr229, larryliu0820 Differential Revision: D55263773 Pulled By: GregoryComer fbshipit-source-id: 8bcf3e14547166c551843ee7c51c59176632ec56
1 parent 00be112 commit e3b34f7

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

build/Utils.cmake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@
2020
# It should also be cmake-lint clean.
2121
#
2222

23+
# Platform-specific definitions.
24+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
25+
set(arm64 ON)
26+
else()
27+
set(arm64 OFF)
28+
endif()
29+
30+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
31+
set(x86 ON)
32+
else()
33+
set(x86 OFF)
34+
endif()
35+
2336
# Public function to print summary for all configurations. For new variables,
2437
# it's recommended to add them here.
2538
function(executorch_print_configuration_summary)
@@ -32,6 +45,8 @@ function(executorch_print_configuration_summary)
3245
message(STATUS " BUCK2 : ${BUCK2}")
3346
message(STATUS " PYTHON_EXECUTABLE : ${PYTHON_EXECUTABLE}")
3447
message(STATUS " FLATC_EXECUTABLE : ${FLATC_EXECUTABLE}")
48+
message(STATUS " X86 : ${x86}")
49+
message(STATUS " ARM64 : ${arm64}")
3550
message(
3651
STATUS " EXECUTORCH_ENABLE_LOGGING : ${EXECUTORCH_ENABLE_LOGGING}")
3752
message(
@@ -120,4 +135,4 @@ function(extract_sources sources_file)
120135
message(FATAL_ERROR "executorch: source list generation failed")
121136
endif()
122137
endif()
123-
endfunction()
138+
endfunction()

build/cmake_deps.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ excludes = [
5656
# Exclude the codegen templates, which are picked up because the buck target
5757
# is the generated_lib and not the unwrapped set of kernels.
5858
"^codegen/templates",
59+
# Exclude blas, since it's built as a separate target.
60+
"^kernels/optimized/blas",
5961
]
6062
deps = [
6163
"executorch",
@@ -85,6 +87,19 @@ filters = [
8587
".fbs$",
8688
]
8789

90+
[targets.optimized_cpublas]
91+
buck_targets = [
92+
"//kernels/optimized:libblas",
93+
]
94+
filters = [
95+
".cpp$",
96+
]
97+
excludes = [
98+
]
99+
deps = [
100+
"executorch",
101+
]
102+
88103
# ---------------------------------- core end ----------------------------------
89104
# ---------------------------------- extension start ----------------------------------
90105

kernels/optimized/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,24 @@ endif()
3030

3131
set(_common_compile_options -Wno-deprecated-declarations)
3232

33+
# Set platform-specific definitions.
34+
if(arm64)
35+
list(APPEND _common_compile_options -DET_BUILD_WITH_BLAS)
36+
elseif(x86)
37+
# TODO(T183193812) Enable once sleef is built in OSS.
38+
# list(APPEND _common_compile_options -DCPU_CAPABILITY_AVX2)
39+
endif()
40+
3341
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
3442
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
3543

44+
# Build cpublas.
45+
list(TRANSFORM _optimized_cpublas__srcs PREPEND "${EXECUTORCH_ROOT}/")
46+
add_library(cpublas ${_optimized_cpublas__srcs})
47+
target_link_libraries(cpublas PRIVATE executorch)
48+
target_compile_options(cpublas PUBLIC ${_common_compile_options})
49+
50+
3651
# Generate C++ bindings to register kernels into both PyTorch (for AOT) and
3752
# Executorch (for runtime). Here select all ops in optimized.yaml
3853
set(_yaml "${CMAKE_CURRENT_LIST_DIR}/optimized-oss.yaml")
@@ -44,7 +59,7 @@ message("Generated files ${gen_command_sources}")
4459

4560
list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
4661
add_library(optimized_kernels ${_optimized_kernels__srcs})
47-
target_link_libraries(optimized_kernels PRIVATE executorch)
62+
target_link_libraries(optimized_kernels PRIVATE executorch cpublas)
4863
target_compile_options(optimized_kernels PUBLIC ${_common_compile_options})
4964
# Build a library for _optimized_kernels_srcs
5065
#

0 commit comments

Comments
 (0)