Skip to content

Commit e534c5e

Browse files
peterbell10facebook-github-bot
authored andcommitted
CMake: Include instead of copying cpu kernel files (pytorch#67656)
Summary: Pull Request resolved: pytorch#67656 Currently, each cpu kernel file is copied into the build folder 3 times to give them different compilation flags. This changes it to instead generate 3 files that `#include` the original file. The biggest difference is that updating a copied file requires `cmake` to re-run, whereas include dependencies are natively handled by `ninja`. A side benefit is that included files show up directly in the build dependency graph, whereas `cmake` file copies don't. Test Plan: Imported from OSS Reviewed By: dagitses Differential Revision: D32566108 Pulled By: malfet fbshipit-source-id: ae75368fede37e7ca03be6ade3d4e4a63479440d
1 parent f6f1b58 commit e534c5e

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

cmake/Codegen.cmake

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ if(INTERN_BUILD_ATEN_OPS)
6767
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/MapAllocator.cpp PROPERTIES COMPILE_FLAGS "-fno-openmp")
6868
endif()
6969

70-
file(GLOB cpu_kernel_cpp_in "${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/cpu/*.cpp" "${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/native/quantized/cpu/kernels/*.cpp")
70+
file(GLOB cpu_kernel_cpp_in "${PROJECT_SOURCE_DIR}/aten/src/ATen/native/cpu/*.cpp" "${PROJECT_SOURCE_DIR}/aten/src/ATen/native/quantized/cpu/kernels/*.cpp")
7171

7272
list(APPEND CPU_CAPABILITY_NAMES "DEFAULT")
7373
list(APPEND CPU_CAPABILITY_FLAGS "${OPT_FLAG}")
@@ -129,10 +129,10 @@ if(INTERN_BUILD_ATEN_OPS)
129129
# See NOTE [ Linking AVX and non-AVX files ]
130130
foreach(i RANGE ${NUM_CPU_CAPABILITY_NAMES})
131131
foreach(IMPL ${cpu_kernel_cpp_in})
132-
string(REPLACE "${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/" "" NAME ${IMPL})
132+
file(RELATIVE_PATH NAME "${PROJECT_SOURCE_DIR}/aten/src/ATen/" "${IMPL}")
133133
list(GET CPU_CAPABILITY_NAMES ${i} CPU_CAPABILITY)
134134
set(NEW_IMPL ${CMAKE_BINARY_DIR}/aten/src/ATen/${NAME}.${CPU_CAPABILITY}.cpp)
135-
configure_file(${IMPL} ${NEW_IMPL} COPYONLY)
135+
configure_file("${PROJECT_SOURCE_DIR}/cmake/IncludeSource.cpp.in" ${NEW_IMPL})
136136
set(cpu_kernel_cpp ${NEW_IMPL} ${cpu_kernel_cpp}) # Create list of copies
137137
list(GET CPU_CAPABILITY_FLAGS ${i} FLAGS)
138138
if(MSVC)

cmake/IncludeSource.cpp.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "@IMPL@"

0 commit comments

Comments
 (0)