Skip to content

Commit b74e89c

Browse files
committed
Use c10 version of half/bfloat16 in executorch
Pull Request resolved: #7040 Pull Request resolved: pytorch/pytorch#144111 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: 260777713 @exported-using-ghexport Differential Revision: [D66106969](https://our.internmc.facebook.com/intern/diff/D66106969/)
1 parent e1c0bcf commit b74e89c

File tree

23 files changed

+2585
-1361
lines changed

23 files changed

+2585
-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
@@ -361,7 +361,7 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
361361
"fix for this restriction."
362362
)
363363
endif()
364-
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/..)
364+
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type)
365365

366366
#
367367
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
@@ -544,6 +544,7 @@ endif()
544544
target_include_directories(
545545
executorch_core PUBLIC ${_common_include_directories}
546546
)
547+
target_compile_definitions(executorch_core PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
547548
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
548549
if(MAX_KERNEL_NUM)
549550
target_compile_definitions(
@@ -564,6 +565,7 @@ if(EXECUTORCH_BUILD_PYBIND AND APPLE)
564565
target_include_directories(
565566
executorch_core_shared PUBLIC ${_common_include_directories}
566567
)
568+
target_compile_definitions(executorch_core_shared PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
567569
target_compile_options(
568570
executorch_core_shared PUBLIC ${_common_compile_options}
569571
)
@@ -584,6 +586,7 @@ endif()
584586
add_library(executorch ${_executorch__srcs})
585587
target_link_libraries(executorch PRIVATE executorch_core)
586588
target_include_directories(executorch PUBLIC ${_common_include_directories})
589+
target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
587590
target_compile_options(executorch PUBLIC ${_common_compile_options})
588591
target_link_options_shared_lib(executorch)
589592

@@ -617,6 +620,12 @@ endif()
617620

618621
# Install `executorch` library as well as `executorch-config.cmake` under
619622
# ${CMAKE_INSTALL_PREFIX}/
623+
install(DIRECTORY runtime/core/ DESTINATION include/executorch/runtime/core FILES_MATCHING PATTERN "*.h")
624+
install(DIRECTORY runtime/kernel/ DESTINATION include/executorch/runtime/kernel FILES_MATCHING PATTERN "*.h")
625+
install(DIRECTORY runtime/platform/ DESTINATION include/executorch/runtime/platform FILES_MATCHING PATTERN "*.h")
626+
install(DIRECTORY extension/kernel_util/ DESTINATION include/executorch/extension/kernel_util FILES_MATCHING PATTERN "*.h")
627+
install(DIRECTORY extension/tensor/ DESTINATION include/executorch/extension/tensor FILES_MATCHING PATTERN "*.h")
628+
install(DIRECTORY extension/threadpool/ DESTINATION include/executorch/extension/threadpool FILES_MATCHING PATTERN "*.h")
620629
install(
621630
TARGETS executorch executorch_core
622631
DESTINATION lib
@@ -775,6 +784,8 @@ if(EXECUTORCH_BUILD_PYBIND)
775784
target_include_directories(
776785
util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
777786
)
787+
target_compile_definitions(util PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
788+
778789
target_compile_options(util PUBLIC ${_pybind_compile_options})
779790
target_link_libraries(util PRIVATE torch c10 executorch extension_tensor)
780791

backends/qualcomm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ add_custom_command(
5353
)
5454

5555
add_compile_options("-Wall" "-Werror" "-Wno-sign-compare")
56+
add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS)
5657

5758
# GNU emit wanring for ignored attributes Unfortunately, we use [[maybe_unused]]
5859
# which can be ignored by GNU. So we make it a warning, not an error in GNU.
@@ -72,6 +73,7 @@ endif()
7273
include_directories(
7374
BEFORE ${_common_include_directories} ${QNN_SDK_ROOT}/include/QNN
7475
${EXECUTORCH_SOURCE_DIR}/third-party/flatbuffers/include
76+
${EXECUTORCH_SOURCE_DIR}/runtime/core/portable_type
7577
)
7678

7779
set(_qnn_schema__srcs

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()

0 commit comments

Comments
 (0)