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# Kernel library for optimized kernels. Please this file formatted by running: 8# ~~~ 9# cmake-format -i CMakeLists.txt 10# ~~~ 11 12cmake_minimum_required(VERSION 3.19) 13 14set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 15if(NOT CMAKE_CXX_STANDARD) 16 set(CMAKE_CXX_STANDARD 17) 17endif() 18 19# Source root directory for executorch. 20if(NOT EXECUTORCH_ROOT) 21 set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) 22endif() 23 24set(_common_compile_options -Wno-deprecated-declarations) 25 26# Note for apple platform we can rely on Accelerate framework Will come back to 27# this 28include(${CMAKE_CURRENT_LIST_DIR}/External/EigenBLAS.cmake) 29list(APPEND _common_compile_options -DET_BUILD_WITH_BLAS) 30 31# For us to set CPU_CAPABILITY_AVX2 we need to detect architecture plus 32# processor. The way aten has implemented this is slightly different. We 33# probably need to figure out how to detect compiler flag that suggest we are 34# compiling for avx2 for now punting this to come back 35 36include(${EXECUTORCH_ROOT}/build/Utils.cmake) 37include(${EXECUTORCH_ROOT}/build/Codegen.cmake) 38 39if(NOT PYTHON_EXECUTABLE) 40 resolve_python_executable() 41endif() 42# Build cpublas. 43list(TRANSFORM _optimized_cpublas__srcs PREPEND "${EXECUTORCH_ROOT}/") 44add_library(cpublas STATIC ${_optimized_cpublas__srcs}) 45target_link_libraries( 46 cpublas PRIVATE executorch_core eigen_blas extension_threadpool 47) 48target_compile_options(cpublas PUBLIC ${_common_compile_options}) 49 50# Generate C++ bindings to register kernels into both PyTorch (for AOT) and 51# Executorch (for runtime). Here select all ops in optimized.yaml 52set(_yaml "${CMAKE_CURRENT_LIST_DIR}/optimized-oss.yaml") 53gen_selected_ops(LIB_NAME "optimized_ops_lib" OPS_SCHEMA_YAML "${_yaml}") 54 55generate_bindings_for_kernels( 56 LIB_NAME "optimized_ops_lib" FUNCTIONS_YAML 57 ${CMAKE_CURRENT_SOURCE_DIR}/optimized-oss.yaml 58) 59message("Generated files ${gen_command_sources}") 60 61list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/") 62add_library(optimized_kernels ${_optimized_kernels__srcs}) 63target_link_libraries( 64 optimized_kernels PRIVATE executorch_core cpublas extension_threadpool 65) 66target_compile_options(optimized_kernels PUBLIC ${_common_compile_options}) 67# Build a library for _optimized_kernels_srcs 68# 69# optimized_ops_lib: Register optimized ops kernels into Executorch runtime 70gen_operators_lib( 71 LIB_NAME "optimized_ops_lib" KERNEL_LIBS optimized_kernels DEPS executorch 72) 73 74install( 75 TARGETS cpublas optimized_kernels optimized_ops_lib 76 DESTINATION lib 77 PUBLIC_HEADER DESTINATION include/executorch/kernels/optimized/ 78) 79 80install(TARGETS cpublas DESTINATION lib) 81