mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
CMake: Include instead of copying cpu kernel files (#67656)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f6f1b580f8
commit
e534c5efd7
@ -67,7 +67,7 @@ if(INTERN_BUILD_ATEN_OPS)
|
||||
set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/MapAllocator.cpp PROPERTIES COMPILE_FLAGS "-fno-openmp")
|
||||
endif()
|
||||
|
||||
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")
|
||||
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")
|
||||
|
||||
list(APPEND CPU_CAPABILITY_NAMES "DEFAULT")
|
||||
list(APPEND CPU_CAPABILITY_FLAGS "${OPT_FLAG}")
|
||||
@ -129,10 +129,10 @@ if(INTERN_BUILD_ATEN_OPS)
|
||||
# See NOTE [ Linking AVX and non-AVX files ]
|
||||
foreach(i RANGE ${NUM_CPU_CAPABILITY_NAMES})
|
||||
foreach(IMPL ${cpu_kernel_cpp_in})
|
||||
string(REPLACE "${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/" "" NAME ${IMPL})
|
||||
file(RELATIVE_PATH NAME "${PROJECT_SOURCE_DIR}/aten/src/ATen/" "${IMPL}")
|
||||
list(GET CPU_CAPABILITY_NAMES ${i} CPU_CAPABILITY)
|
||||
set(NEW_IMPL ${CMAKE_BINARY_DIR}/aten/src/ATen/${NAME}.${CPU_CAPABILITY}.cpp)
|
||||
configure_file(${IMPL} ${NEW_IMPL} COPYONLY)
|
||||
configure_file("${PROJECT_SOURCE_DIR}/cmake/IncludeSource.cpp.in" ${NEW_IMPL})
|
||||
set(cpu_kernel_cpp ${NEW_IMPL} ${cpu_kernel_cpp}) # Create list of copies
|
||||
list(GET CPU_CAPABILITY_FLAGS ${i} FLAGS)
|
||||
if(MSVC)
|
||||
|
1
cmake/IncludeSource.cpp.in
Normal file
1
cmake/IncludeSource.cpp.in
Normal file
@ -0,0 +1 @@
|
||||
#include "@IMPL@"
|
Reference in New Issue
Block a user