Skip to content

Commit 33e13a2

Browse files
kimishpatelfacebook-github-bot
authored andcommitted
Enable blas and add eigen blas (#2670)
Summary: Pull Request resolved: #2670 Add eigen to third-party for optimized kernels and add cmake for eigen blas bypass-github-export-checks ghstack-source-id: 220378205 exported-using-ghexport bypass-github-pytorch-ci-checks Reviewed By: digantdesai, mcr229 Differential Revision: D55344018 fbshipit-source-id: 92563221a83496890f6ff2e31a3febeda219dc87
1 parent a197412 commit 33e13a2

7 files changed

Lines changed: 92 additions & 4 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@
5959
path = third-party/lm-evaluation-harness
6060
url = https://github.com/EleutherAI/lm-evaluation-harness
6161
branch = v0.4.1
62+
[submodule "kernels/optimized/third-party/eigen"]
63+
path = kernels/optimized/third-party/eigen
64+
url = https://gitlab.com/libeigen/eigen.git

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",
@@ -87,6 +89,19 @@ filters = [
8789
".fbs$",
8890
]
8991

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

build/executorch-config.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ endif()
4444
set(lib_list
4545
etdump bundled_program extension_data_loader ${FLATCC_LIB} mpsdelegate
4646
qnn_executorch_backend portable_ops_lib extension_module xnnpack_backend
47-
XNNPACK cpuinfo pthreadpool vulkan_backend optimized_kernels
47+
XNNPACK cpuinfo pthreadpool vulkan_backend optimized_kernels cpublas eigen_blas
4848
optimized_ops_lib optimized_native_cpu_ops_lib
4949
)
5050
foreach(lib ${lib_list})

examples/models/llama2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ set(link_libraries)
6060

6161
if(EXECUTORCH_BUILD_OPTIMIZED)
6262
list(APPEND link_libraries optimized_native_cpu_ops_lib optimized_kernels
63-
portable_kernels)
63+
portable_kernels cpublas eigen_blas)
6464
target_link_options_shared_lib(optimized_native_cpu_ops_lib)
6565
else()
6666
list(APPEND link_libraries portable_ops_lib portable_kernels)

kernels/optimized/CMakeLists.txt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,28 @@ endif()
2727

2828
set(_common_compile_options -Wno-deprecated-declarations)
2929

30+
# Note for apple platform we can rely on Accelerate framework
31+
# Will come back to this
32+
include(${CMAKE_CURRENT_LIST_DIR}/External/EigenBLAS.cmake)
33+
list(APPEND _common_compile_options -DET_BUILD_WITH_BLAS)
34+
35+
# For us to set CPU_CAPABILITY_AVX2 we need to detect architecture
36+
# plus processor. The way aten has implemented this is slightly
37+
# different. We probably need to figure out how to detect compiler
38+
# flag that suggest we are compiling for avx2
39+
# for now punting this to come back
40+
3041
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
3142
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
3243

3344
if(NOT PYTHON_EXECUTABLE)
3445
resolve_python_executable()
3546
endif()
47+
# Build cpublas.
48+
list(TRANSFORM _optimized_cpublas__srcs PREPEND "${EXECUTORCH_ROOT}/")
49+
add_library(cpublas ${_optimized_cpublas__srcs})
50+
target_link_libraries(cpublas PRIVATE executorch eigen_blas)
51+
target_compile_options(cpublas PUBLIC ${_common_compile_options})
3652

3753
# Generate C++ bindings to register kernels into both PyTorch (for AOT) and
3854
# Executorch (for runtime). Here select all ops in optimized.yaml
@@ -45,7 +61,7 @@ message("Generated files ${gen_command_sources}")
4561

4662
list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
4763
add_library(optimized_kernels ${_optimized_kernels__srcs})
48-
target_link_libraries(optimized_kernels PRIVATE executorch)
64+
target_link_libraries(optimized_kernels PRIVATE executorch cpublas)
4965
target_compile_options(optimized_kernels PUBLIC ${_common_compile_options})
5066
# Build a library for _optimized_kernels_srcs
5167
#
@@ -55,4 +71,4 @@ gen_operators_lib(
5571
KERNEL_LIBS optimized_kernels
5672
DEPS executorch)
5773

58-
install(TARGETS optimized_kernels optimized_ops_lib DESTINATION lib)
74+
install(TARGETS cpublas optimized_kernels optimized_ops_lib DESTINATION lib)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
if(__EIGEN_BLAS_INCLUDED)
8+
return()
9+
endif()
10+
set(__EIGEN_BLAS_INCLUDED TRUE)
11+
12+
##############################################################################
13+
# Eigen BLAS is built together with Libtorch mobile.
14+
# By default, it builds code from third-party/eigen/blas submodule.
15+
##############################################################################
16+
17+
set(EIGEN_BLAS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third-party/eigen/blas" CACHE STRING "Eigen BLAS source directory")
18+
19+
set(EigenBlas_SRCS
20+
${EIGEN_BLAS_SRC_DIR}/single.cpp
21+
${EIGEN_BLAS_SRC_DIR}/double.cpp
22+
${EIGEN_BLAS_SRC_DIR}/complex_single.cpp
23+
${EIGEN_BLAS_SRC_DIR}/complex_double.cpp
24+
${EIGEN_BLAS_SRC_DIR}/xerbla.cpp
25+
${EIGEN_BLAS_SRC_DIR}/f2c/srotm.c
26+
${EIGEN_BLAS_SRC_DIR}/f2c/srotmg.c
27+
${EIGEN_BLAS_SRC_DIR}/f2c/drotm.c
28+
${EIGEN_BLAS_SRC_DIR}/f2c/drotmg.c
29+
${EIGEN_BLAS_SRC_DIR}/f2c/lsame.c
30+
${EIGEN_BLAS_SRC_DIR}/f2c/dspmv.c
31+
${EIGEN_BLAS_SRC_DIR}/f2c/ssbmv.c
32+
${EIGEN_BLAS_SRC_DIR}/f2c/chbmv.c
33+
${EIGEN_BLAS_SRC_DIR}/f2c/sspmv.c
34+
${EIGEN_BLAS_SRC_DIR}/f2c/zhbmv.c
35+
${EIGEN_BLAS_SRC_DIR}/f2c/chpmv.c
36+
${EIGEN_BLAS_SRC_DIR}/f2c/dsbmv.c
37+
${EIGEN_BLAS_SRC_DIR}/f2c/zhpmv.c
38+
${EIGEN_BLAS_SRC_DIR}/f2c/dtbmv.c
39+
${EIGEN_BLAS_SRC_DIR}/f2c/stbmv.c
40+
${EIGEN_BLAS_SRC_DIR}/f2c/ctbmv.c
41+
${EIGEN_BLAS_SRC_DIR}/f2c/ztbmv.c
42+
${EIGEN_BLAS_SRC_DIR}/f2c/complexdots.c
43+
)
44+
45+
add_library(eigen_blas STATIC ${EigenBlas_SRCS})
46+
47+
#Dont know what to do with this
48+
# We build static versions of eigen blas but link into a shared library, so they need PIC.
49+
set_property(TARGET eigen_blas PROPERTY POSITION_INDEPENDENT_CODE ON)
50+
51+
install(TARGETS eigen_blas
52+
LIBRARY DESTINATION lib
53+
ARCHIVE DESTINATION lib)
Submodule eigen added at a39ade4

0 commit comments

Comments
 (0)