Skip to content

Commit a25444c

Browse files
committed
Use c10 version of half/bfloat16 in executorch
Pull Request resolved: #7040 Accomplished by importing relevant files from c10 into executorch/runtime/core/portable_type/c10, and then using `using` in the top-level ExecuTorch headers. This approach should keep the ExecuTorch build hermetic for embedded use cases. In the future, we should add a CI job to ensure the c10 files stay identical to the PyTorch ones. ghstack-source-id: 258553928 @exported-using-ghexport Differential Revision: [D66106969](https://our.internmc.facebook.com/intern/diff/D66106969/)
1 parent 571d200 commit a25444c

File tree

22 files changed

+2525
-1361
lines changed

22 files changed

+2525
-1361
lines changed

.lintrunner.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ exclude_patterns = [
7878
# File contains @generated
7979
'extension/llm/custom_ops/spinquant/fast_hadamard_transform_special.h',
8080
'extension/llm/custom_ops/spinquant/test/fast_hadamard_transform_special_unstrided_cpu.h',
81+
# Want to be able to keep c10 in sync with PyTorch core.
82+
'runtime/core/portable_type/c10/**',
8183
]
8284
command = [
8385
'python',
@@ -261,6 +263,8 @@ exclude_patterns = [
261263
'extension/**',
262264
'kernels/optimized/**',
263265
'runtime/core/exec_aten/**',
266+
# Want to be able to keep c10 in sync with PyTorch core.
267+
'runtime/core/portable_type/c10/**',
264268
'runtime/executor/tensor_parser_aten.cpp',
265269
'scripts/**',
266270
'test/**',

CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
367367
"fix for this restriction."
368368
)
369369
endif()
370-
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/..)
370+
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type)
371371

372372
#
373373
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
@@ -550,6 +550,7 @@ endif()
550550
target_include_directories(
551551
executorch_core PUBLIC ${_common_include_directories}
552552
)
553+
target_compile_definitions(executorch_core PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
553554
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
554555
if(MAX_KERNEL_NUM)
555556
target_compile_definitions(
@@ -570,6 +571,7 @@ if(EXECUTORCH_BUILD_PYBIND AND APPLE)
570571
target_include_directories(
571572
executorch_core_shared PUBLIC ${_common_include_directories}
572573
)
574+
target_compile_definitions(executorch_core_shared PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
573575
target_compile_options(
574576
executorch_core_shared PUBLIC ${_common_compile_options}
575577
)
@@ -590,6 +592,7 @@ endif()
590592
add_library(executorch ${_executorch__srcs})
591593
target_link_libraries(executorch PRIVATE executorch_core)
592594
target_include_directories(executorch PUBLIC ${_common_include_directories})
595+
target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
593596
target_compile_options(executorch PUBLIC ${_common_compile_options})
594597
target_link_options_shared_lib(executorch)
595598

@@ -623,6 +626,12 @@ endif()
623626

624627
# Install `executorch` library as well as `executorch-config.cmake` under
625628
# ${CMAKE_INSTALL_PREFIX}/
629+
install(DIRECTORY runtime/core/ DESTINATION include/executorch/runtime/core FILES_MATCHING PATTERN "*.h")
630+
install(DIRECTORY runtime/kernel/ DESTINATION include/executorch/runtime/kernel FILES_MATCHING PATTERN "*.h")
631+
install(DIRECTORY runtime/platform/ DESTINATION include/executorch/runtime/platform FILES_MATCHING PATTERN "*.h")
632+
install(DIRECTORY extension/kernel_util/ DESTINATION include/executorch/extension/kernel_util FILES_MATCHING PATTERN "*.h")
633+
install(DIRECTORY extension/tensor/ DESTINATION include/executorch/extension/tensor FILES_MATCHING PATTERN "*.h")
634+
install(DIRECTORY extension/threadpool/ DESTINATION include/executorch/extension/threadpool FILES_MATCHING PATTERN "*.h")
626635
install(
627636
TARGETS executorch executorch_core
628637
DESTINATION lib
@@ -781,6 +790,8 @@ if(EXECUTORCH_BUILD_PYBIND)
781790
target_include_directories(
782791
util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
783792
)
793+
target_compile_definitions(util PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
794+
784795
target_compile_options(util PUBLIC ${_pybind_compile_options})
785796
target_link_libraries(util PRIVATE torch c10 executorch extension_tensor)
786797

backends/xnnpack/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$")
129129
list(TRANSFORM _xnn_executor_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
130130
add_executable(xnn_executor_runner ${_xnn_executor_runner__srcs})
131131
target_link_libraries(
132-
xnn_executor_runner xnnpack_backend gflags portable_ops_lib
132+
xnn_executor_runner xnnpack_backend gflags portable_ops_lib executorch
133133
)
134134
target_compile_options(xnn_executor_runner PUBLIC ${_common_compile_options})
135135
endif()

build/executorch-config.cmake

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@
2626

2727
cmake_minimum_required(VERSION 3.19)
2828

29-
set(_root "${CMAKE_CURRENT_LIST_DIR}/../..")
29+
set(_root "${CMAKE_CURRENT_LIST_DIR}/../../..")
3030
set(required_lib_list executorch executorch_core portable_kernels)
3131
set(EXECUTORCH_LIBRARIES)
32-
set(EXECUTORCH_INCLUDE_DIRS ${_root})
32+
set(EXECUTORCH_INCLUDE_DIRS ${_root}/include ${_root}/include/executorch/runtime/core/portable_type ${_root}/lib)
3333
foreach(lib ${required_lib_list})
3434
set(lib_var "LIB_${lib}")
3535
add_library(${lib} STATIC IMPORTED)
3636
find_library(
3737
${lib_var} ${lib}
38-
HINTS "${_root}"
38+
HINTS "${_root}/lib"
3939
CMAKE_FIND_ROOT_PATH_BOTH
4040
)
4141
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
42-
target_include_directories(${lib} INTERFACE ${_root})
42+
target_compile_definitions(${lib} INTERFACE C10_USING_CUSTOM_GENERATED_MACROS)
43+
target_include_directories(${lib} INTERFACE ${_root}/include ${_root}/include/executorch/runtime/core/portable_type ${_root}/lib)
4344
list(APPEND EXECUTORCH_LIBRARIES ${lib})
4445
endforeach()
4546

@@ -93,7 +94,7 @@ foreach(lib ${lib_list})
9394
set(lib_var "LIB_${lib}")
9495
find_library(
9596
${lib_var} ${lib}
96-
HINTS "${_root}"
97+
HINTS "${_root}/lib"
9798
CMAKE_FIND_ROOT_PATH_BOTH
9899
)
99100
if(NOT ${lib_var})
@@ -109,7 +110,7 @@ foreach(lib ${lib_list})
109110
add_library(${lib} STATIC IMPORTED)
110111
endif()
111112
set_target_properties(${lib} PROPERTIES IMPORTED_LOCATION "${${lib_var}}")
112-
target_include_directories(${lib} INTERFACE ${_root})
113+
target_include_directories(${lib} INTERFACE ${_root}/include ${_root}/include/executorch/runtime/core/portable_type ${_root}/lib)
113114
list(APPEND EXECUTORCH_LIBRARIES ${lib})
114115
endif()
115116
endforeach()

examples/models/llama/runner/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ include(${EXECUTORCH_SRCS_FILE})
3838
list(TRANSFORM _llama_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
3939

4040
target_include_directories(
41-
extension_module INTERFACE ${_common_include_directories}
41+
extension_module INTERFACE ${_common_include_directories} ${EXECUTORCH_INCLUDE_DIRS}
4242
)
4343

4444
list(
@@ -82,6 +82,6 @@ set(llama_runner_deps executorch extension_data_loader extension_module
8282
target_link_libraries(llama_runner PUBLIC ${llama_runner_deps})
8383

8484
target_include_directories(
85-
llama_runner INTERFACE ${_common_include_directories} ${EXECUTORCH_ROOT}
85+
llama_runner INTERFACE ${_common_include_directories} ${EXECUTORCH_INCLUDE_DIRS}
8686
)
8787
target_compile_options(llama_runner PUBLIC ${_preprocessor_flag})

0 commit comments

Comments
 (0)