diff --git a/build/Codegen.cmake b/build/Codegen.cmake index 430c09258c..22bd5a5905 100644 --- a/build/Codegen.cmake +++ b/build/Codegen.cmake @@ -176,6 +176,10 @@ function(gen_operators_lib) endif() target_link_options_shared_lib(${GEN_LIB_NAME}) + set(_generated_headers ${_out_dir}/Functions.h ${_out_dir}/NativeFunctions.h) + set_target_properties( + ${GEN_LIB_NAME} PROPERTIES PUBLIC_HEADER "${_generated_headers}" + ) endfunction() # Merge two kernel yaml files, prioritizing functions from FUNCTIONS_YAML and diff --git a/kernels/optimized/CMakeLists.txt b/kernels/optimized/CMakeLists.txt index 01a7ac2452..0b0ecacbf4 100644 --- a/kernels/optimized/CMakeLists.txt +++ b/kernels/optimized/CMakeLists.txt @@ -67,6 +67,10 @@ gen_operators_lib( LIB_NAME "optimized_ops_lib" KERNEL_LIBS optimized_kernels DEPS executorch ) -install(TARGETS cpublas optimized_kernels optimized_ops_lib DESTINATION lib) +install( + TARGETS cpublas optimized_kernels optimized_ops_lib + DESTINATION lib + PUBLIC_HEADER DESTINATION include/optimized +) install(TARGETS cpublas DESTINATION lib) diff --git a/kernels/portable/CMakeLists.txt b/kernels/portable/CMakeLists.txt index a63e706391..e8c412c287 100644 --- a/kernels/portable/CMakeLists.txt +++ b/kernels/portable/CMakeLists.txt @@ -64,4 +64,8 @@ gen_operators_lib( LIB_NAME "portable_ops_lib" KERNEL_LIBS portable_kernels DEPS executorch ) -install(TARGETS portable_kernels portable_ops_lib DESTINATION lib) +install( + TARGETS portable_kernels portable_ops_lib + DESTINATION lib + PUBLIC_HEADER DESTINATION include/portable +) diff --git a/kernels/test/CMakeLists.txt b/kernels/test/CMakeLists.txt new file mode 100644 index 0000000000..0f9cdbaa8f --- /dev/null +++ b/kernels/test/CMakeLists.txt @@ -0,0 +1,69 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# This file should be formatted with +# ~~~ +# cmake-format -i CMakeLists.txt +# ~~~ +# It should also be cmake-lint clean. +# + +cmake_minimum_required(VERSION 3.19) +project(kernels_test) + +# Use C++17 for test. +set(CMAKE_CXX_STANDARD 17) + +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) + +include(${EXECUTORCH_ROOT}/build/Test.cmake) + +set(_kernels portable optimized) + +foreach(kernel ${_kernels}) + set(_wrapper_path + "${CMAKE_CURRENT_BINARY_DIR}/include/${kernel}/executorch/kernels/test/FunctionHeaderWrapper.h" + ) + add_custom_command( + OUTPUT "${_wrapper_path}" + COMMAND mkdir -p include/${kernel}/executorch/kernels/test + COMMAND echo "#include <${kernel}/Functions.h>" > "${_wrapper_path}" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + COMMENT "Generating ${_wrapper_path}" + VERBATIM + ) +endforeach() + +add_custom_target( + generate_wrapper + DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/include/portable/executorch/kernels/test/FunctionHeaderWrapper.h" + "${CMAKE_CURRENT_BINARY_DIR}/include/optimized/executorch/kernels/test/FunctionHeaderWrapper.h" +) + +set(_portable_kernels_test_sources op_abs_test.cpp) +set(_optimized_kernels_test_sources op_neg_test.cpp) + +et_cxx_test( + portable_kernels_test SOURCES ${_portable_kernels_test_sources} EXTRA_LIBS + portable_kernels portable_ops_lib +) +add_dependencies(portable_kernels_test generate_wrapper) +target_include_directories( + portable_kernels_test PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include/portable" + "${CMAKE_INSTALL_PREFIX}/include" +) + +et_cxx_test( + optimized_kernels_test SOURCES ${_optimized_kernels_test_sources} EXTRA_LIBS + optimized_kernels optimized_ops_lib +) +add_dependencies(optimized_kernels_test generate_wrapper) +# message(FATAL_ERROR "${CMAKE_INSTALL_PREFIX}/include") +target_include_directories( + optimized_kernels_test PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/include/optimized" + "${CMAKE_INSTALL_PREFIX}/include" +) diff --git a/test/run_oss_cpp_tests.sh b/test/run_oss_cpp_tests.sh index f353a7d30b..6bd1bab0ac 100755 --- a/test/run_oss_cpp_tests.sh +++ b/test/run_oss_cpp_tests.sh @@ -30,6 +30,7 @@ build_executorch() { cmake . \ -DCMAKE_INSTALL_PREFIX=cmake-out \ -DEXECUTORCH_USE_CPP_CODE_COVERAGE=ON \ + -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ @@ -48,7 +49,9 @@ build_gtest() { } export_test_add_model() { - python3 -m examples.portable.scripts.export --model_name="add" --output_dir="cmake-out" + if ! test -f cmake-out/add.pte; then + python3 -m examples.portable.scripts.export --model_name="add" --output_dir="cmake-out" + fi } build_and_run_test() {