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 portable 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 26include(${EXECUTORCH_ROOT}/build/Utils.cmake) 27include(${EXECUTORCH_ROOT}/build/Codegen.cmake) 28 29if(NOT PYTHON_EXECUTABLE) 30 resolve_python_executable() 31endif() 32 33# Portable kernel sources TODO(larryliu0820): use buck2 to gather the sources 34file(GLOB_RECURSE _portable_kernels__srcs 35 "${CMAKE_CURRENT_SOURCE_DIR}/cpu/*.cpp" 36) 37list(FILTER _portable_kernels__srcs EXCLUDE REGEX "test/*.cpp") 38list(FILTER _portable_kernels__srcs EXCLUDE REGEX "codegen") 39# Generate C++ bindings to register kernels into both PyTorch (for AOT) and 40# Executorch (for runtime). Here select all ops in functions.yaml 41set(_yaml "${CMAKE_CURRENT_SOURCE_DIR}/functions.yaml") 42gen_selected_ops(LIB_NAME "portable_ops_lib" OPS_SCHEMA_YAML "${_yaml}") 43# Expect gen_selected_ops output file to be selected_operators.yaml 44generate_bindings_for_kernels( 45 LIB_NAME "portable_ops_lib" FUNCTIONS_YAML "${_yaml}" 46) 47message("Generated files ${gen_command_sources}") 48 49# 50# portable_kernels: Pure-C++ kernel library for ATen ops 51# 52# Focused on portability and understandability rather than speed. 53# 54add_library(portable_kernels ${_portable_kernels__srcs}) 55target_link_libraries(portable_kernels PRIVATE executorch) 56target_compile_options(portable_kernels PUBLIC ${_common_compile_options}) 57 58# Build a library for _portable_kernels__srcs 59# 60# portable_ops_lib: Register portable_ops_lib ops kernels into Executorch 61# runtime 62gen_operators_lib( 63 LIB_NAME "portable_ops_lib" KERNEL_LIBS portable_kernels DEPS executorch 64) 65 66install( 67 TARGETS portable_kernels portable_ops_lib 68 DESTINATION lib 69 PUBLIC_HEADER DESTINATION include/executorch/kernels/portable/ 70) 71