Skip to content

Commit add5d93

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: 255547406 @exported-using-ghexport Differential Revision: [D66106969](https://our.internmc.facebook.com/intern/diff/D66106969/)
1 parent f387d43 commit add5d93

18 files changed

+2508
-1348
lines changed

.lintrunner.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ exclude_patterns = [
7777
# File contains @generated
7878
'extension/llm/custom_ops/spinquant/fast_hadamard_transform_special.h',
7979
'extension/llm/custom_ops/spinquant/test/fast_hadamard_transform_special_unstrided_cpu.h',
80+
# Want to be able to keep c10 in sync with PyTorch core.
81+
'runtime/core/portable_type/c10/**',
8082
]
8183
command = [
8284
'python',
@@ -260,6 +262,8 @@ exclude_patterns = [
260262
'extension/**',
261263
'kernels/optimized/**',
262264
'runtime/core/exec_aten/**',
265+
# Want to be able to keep c10 in sync with PyTorch core.
266+
'runtime/core/portable_type/c10/**',
263267
'runtime/executor/tensor_parser_aten.cpp',
264268
'scripts/**',
265269
'test/**',

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
337337
"fix for this restriction."
338338
)
339339
endif()
340-
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/..)
340+
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type)
341341

342342
#
343343
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
@@ -520,6 +520,7 @@ endif()
520520
target_include_directories(
521521
executorch_core PUBLIC ${_common_include_directories}
522522
)
523+
target_compile_definitions(executorch_core PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
523524
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
524525
if(MAX_KERNEL_NUM)
525526
target_compile_definitions(
@@ -540,6 +541,7 @@ if(EXECUTORCH_BUILD_PYBIND AND APPLE)
540541
target_include_directories(
541542
executorch_core_shared PUBLIC ${_common_include_directories}
542543
)
544+
target_compile_definitions(executorch_core_shared PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
543545
target_compile_options(
544546
executorch_core_shared PUBLIC ${_common_compile_options}
545547
)
@@ -560,6 +562,7 @@ endif()
560562
add_library(executorch ${_executorch__srcs})
561563
target_link_libraries(executorch PRIVATE executorch_core)
562564
target_include_directories(executorch PUBLIC ${_common_include_directories})
565+
target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
563566
target_compile_options(executorch PUBLIC ${_common_compile_options})
564567
target_link_options_shared_lib(executorch)
565568

@@ -751,6 +754,8 @@ if(EXECUTORCH_BUILD_PYBIND)
751754
target_include_directories(
752755
util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
753756
)
757+
target_compile_definitions(util PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
758+
754759
target_compile_options(util PUBLIC ${_pybind_compile_options})
755760
target_link_libraries(util PRIVATE torch c10 executorch extension_tensor)
756761

0 commit comments

Comments
 (0)