Skip to content

Commit d9d0473

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

File tree

18 files changed

+2508
-1348
lines changed

18 files changed

+2508
-1348
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
356356
"fix for this restriction."
357357
)
358358
endif()
359-
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/..)
359+
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type)
360360

361361
#
362362
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
@@ -539,6 +539,7 @@ endif()
539539
target_include_directories(
540540
executorch_core PUBLIC ${_common_include_directories}
541541
)
542+
target_compile_definitions(executorch_core PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
542543
target_compile_options(executorch_core PUBLIC ${_common_compile_options})
543544
if(MAX_KERNEL_NUM)
544545
target_compile_definitions(
@@ -559,6 +560,7 @@ if(EXECUTORCH_BUILD_PYBIND AND APPLE)
559560
target_include_directories(
560561
executorch_core_shared PUBLIC ${_common_include_directories}
561562
)
563+
target_compile_definitions(executorch_core_shared PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
562564
target_compile_options(
563565
executorch_core_shared PUBLIC ${_common_compile_options}
564566
)
@@ -579,6 +581,7 @@ endif()
579581
add_library(executorch ${_executorch__srcs})
580582
target_link_libraries(executorch PRIVATE executorch_core)
581583
target_include_directories(executorch PUBLIC ${_common_include_directories})
584+
target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
582585
target_compile_options(executorch PUBLIC ${_common_compile_options})
583586
target_link_options_shared_lib(executorch)
584587

@@ -770,6 +773,8 @@ if(EXECUTORCH_BUILD_PYBIND)
770773
target_include_directories(
771774
util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
772775
)
776+
target_compile_definitions(util PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
777+
773778
target_compile_options(util PUBLIC ${_pybind_compile_options})
774779
target_link_libraries(util PRIVATE torch c10 executorch extension_tensor)
775780

0 commit comments

Comments
 (0)