Skip to content

Commit 40443a9

Browse files
authored
Make PyTorch headers available in optimized_portable_kernels, define ET_USE_PYTORCH_HEADERS (#9384)
Enables following diff. First real step of #9241.
1 parent 7d36e41 commit 40443a9

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,18 @@ target_link_options_shared_lib(executorch)
645645
# Real integrations should supply their own YAML file that only lists the
646646
# operators necessary for the models that will run.
647647
#
648+
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
649+
# find pytorch lib here to make it available to all
650+
# sub-directories. Find it before including portable so that
651+
# optimized_portable_kernels can use it.
652+
find_package_torch_headers()
653+
endif()
654+
648655
if(BUILD_EXECUTORCH_PORTABLE_OPS)
649656
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable)
650657
endif()
651658

652659
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
653-
# find pytorch lib here to make it available to all sub-directories
654-
find_package_torch_headers()
655660
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/optimized)
656661
endif()
657662

kernels/optimized/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ message("Generated files ${gen_command_sources}")
6262
list(TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT}/")
6363
add_library(optimized_kernels ${_optimized_kernels__srcs})
6464
target_include_directories(optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} "${EXECUTORCH_ROOT}/third-party/pocketfft")
65+
target_compile_definitions(optimized_kernels PRIVATE ET_USE_PYTORCH_HEADERS)
6566
target_link_libraries(
6667
optimized_kernels PUBLIC executorch_core cpublas extension_threadpool
6768
)

kernels/portable/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ if(BUILD_OPTIMIZED_PORTABLE_KERNELS)
7373
target_link_libraries(optimized_portable_kernels PRIVATE executorch)
7474
target_link_libraries(optimized_portable_kernels PUBLIC extension_threadpool)
7575
target_compile_options(optimized_portable_kernels PUBLIC ${_common_compile_options})
76+
target_include_directories(optimized_portable_kernels PRIVATE ${TORCH_INCLUDE_DIRS})
77+
target_compile_definitions(optimized_portable_kernels PRIVATE ET_USE_PYTORCH_HEADERS)
7678
install(
7779
TARGETS optimized_portable_kernels
7880
DESTINATION lib

runtime/core/portable_type/c10/c10/targets.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def define_common_targets():
7373
# -Wmacro-redefined, and we only care about getting
7474
# reasonable vectorization and Sleef support.
7575
"-DCPU_CAPABILITY_AVX2",
76+
"-DET_USE_PYTORCH_HEADERS",
7677
"-DHAVE_AVX2_CPU_DEFINITION",
7778
"-DSTANDALONE_TORCH_HEADER",
7879
] + get_sleef_preprocessor_flags(),
@@ -86,5 +87,5 @@ def define_common_targets():
8687
# linker failure.
8788
"ovr_config//cpu:arm64": get_sleef_preprocessor_flags(),
8889
"DEFAULT": [],
89-
}) + ["-DSTANDALONE_TORCH_HEADER"],
90+
}) + ["-DSTANDALONE_TORCH_HEADER"] + ([] if runtime.is_oss else ["-DET_USE_PYTORCH_HEADERS"]),
9091
)

0 commit comments

Comments
 (0)