Skip to content

Commit 8d16ffe

Browse files
committed
GPU CMake: Add check that RTC source files do not contain system headers
1 parent 2f22584 commit 8d16ffe

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

GPU/GPUTracking/Base/cuda/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,20 @@ if(NOT ALIGPU_BUILD_TYPE STREQUAL "ALIROOT")
6969
add_custom_command(
7070
OUTPUT ${GPU_RTC_BIN}.src
7171
COMMAND cat ${GPUDIR}/Base/cuda/GPUReconstructionCUDAIncludes.h > ${GPU_RTC_BIN}.src
72-
COMMAND ${CMAKE_CXX_COMPILER} ${GPU_RTC_DEFINES} ${GPU_RTC_INCLUDES} -std=c++${CMAKE_CUDA_STANDARD} -D__CUDA_ARCH__=${RTC_CUDA_ARCH} -D__CUDACC__ -x c++ -E ${GPU_RTC_SRC} >> ${GPU_RTC_BIN}.src
72+
COMMAND ${CMAKE_CXX_COMPILER} ${GPU_RTC_DEFINES} ${GPU_RTC_INCLUDES} -std=c++${CMAKE_CUDA_STANDARD} -D__CUDA_ARCH__=${RTC_CUDA_ARCH} -D__CUDACC__ -x c++ -nostdinc -E ${GPU_RTC_SRC} >> ${GPU_RTC_BIN}.src
7373
MAIN_DEPENDENCY ${GPU_RTC_SRC}
7474
IMPLICIT_DEPENDS CXX ${GPU_RTC_SRC}
7575
COMMAND_EXPAND_LISTS
7676
COMMENT "Preparing CUDA RTC source file ${GPU_RTC_BIN}.src"
7777
)
7878
create_binary_resource(${GPU_RTC_BIN}.src ${GPU_RTC_BIN}.src.o)
7979

80+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_CUDA_SRC_CHK.done
81+
COMMAND ! grep "# [0-9]* \"\\(/usr/\\|.*GCC-Toolchain\\)" ${GPU_RTC_BIN}.src > ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_CUDA_SRC_CHK.done || bash -c "echo ERROR: CUDA RTC sources contain standard headers 1>&2 && exit 1"
82+
COMMENT Checking CUDA RTC File ${GPU_RTC_BIN}.src
83+
DEPENDS ${GPU_RTC_BIN}.src VERBATIM)
84+
add_custom_target(${MODULE}_CUDA_SRC_CHK ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_CUDA_SRC_CHK.done)
85+
8086
add_custom_command(
8187
OUTPUT ${GPU_RTC_BIN}.command
8288
COMMAND echo -n "${CMAKE_CUDA_COMPILER} ${GPU_RTC_FLAGS_SEPARATED} ${GPU_RTC_DEFINES} -fatbin" > ${GPU_RTC_BIN}.command

GPU/GPUTracking/Base/hip/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ if(NOT DEFINED GPUCA_HIP_HIPIFY_FROM_CUDA OR "${GPUCA_HIP_HIPIFY_FROM_CUDA}")
5252
list(APPEND HIP_SOURCES "${GPUCA_HIP_SOURCE_DIR}/${HIP_SOURCE}")
5353
endforeach()
5454

55-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIPIFIED_CHK.done COMMAND diff -u ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip ${CMAKE_CURRENT_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip && touch ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIPIFIED_CHK.done DEPENDS ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip ${CMAKE_CURRENT_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip)
56-
add_custom_target(${MODULE}_HIPIFIED_CHK DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIPIFIED_CHK.done)
55+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIPIFIED_CHK.done
56+
COMMAND diff -u ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip ${CMAKE_CURRENT_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip > ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIPIFIED_CHK.done
57+
DEPENDS ${GPUCA_HIP_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip ${CMAKE_CURRENT_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip
58+
COMMENT Checking HIPified file ${CMAKE_CURRENT_SOURCE_DIR}/GPUReconstructionHIPkernel.template.hip)
59+
add_custom_target(${MODULE}_HIPIFIED_CHK ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIPIFIED_CHK.done)
5760
else()
5861
get_filename_component(GPUCA_HIP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
5962
endif()
@@ -103,14 +106,20 @@ if(NOT ALIGPU_BUILD_TYPE STREQUAL "ALIROOT")
103106
add_custom_command(
104107
OUTPUT ${GPU_RTC_BIN}.src
105108
COMMAND cat ${GPUDIR}/Base/hip/GPUReconstructionHIPIncludes.h > ${GPU_RTC_BIN}.src
106-
COMMAND ${CMAKE_CXX_COMPILER} ${GPU_RTC_DEFINES} ${GPU_RTC_INCLUDES} -std=c++${CMAKE_HIP_STANDARD} -D__HIPCC__ -D__HIP_DEVICE_COMPILE__ -x c++ -E ${GPU_RTC_SRC} >> ${GPU_RTC_BIN}.src
109+
COMMAND ${CMAKE_CXX_COMPILER} ${GPU_RTC_DEFINES} ${GPU_RTC_INCLUDES} -std=c++${CMAKE_HIP_STANDARD} -D__HIPCC__ -D__HIP_DEVICE_COMPILE__ -x c++ -nostdinc -E ${GPU_RTC_SRC} >> ${GPU_RTC_BIN}.src
107110
MAIN_DEPENDENCY ${GPU_RTC_SRC}
108111
IMPLICIT_DEPENDS CXX ${GPU_RTC_SRC}
109112
COMMAND_EXPAND_LISTS
110113
COMMENT "Preparing HIP RTC source file ${GPU_RTC_BIN}.src"
111114
)
112115
create_binary_resource(${GPU_RTC_BIN}.src ${GPU_RTC_BIN}.src.o)
113116

117+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIP_SRC_CHK.done
118+
COMMAND ! grep "# [0-9]* \"\\(/usr/\\|.*GCC-Toolchain\\)" ${GPU_RTC_BIN}.src > ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIP_SRC_CHK.done || bash -c "echo ERROR: HIP RTC sources contain standard headers 1>&2 && exit 1"
119+
COMMENT Checking HIP RTC File ${GPU_RTC_BIN}.src
120+
DEPENDS ${GPU_RTC_BIN}.src VERBATIM)
121+
add_custom_target(${MODULE}_HIP_SRC_CHK ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${MODULE}_HIP_SRC_CHK.done)
122+
114123
add_custom_command(
115124
OUTPUT ${GPU_RTC_BIN}.command
116125
COMMAND echo -n "${hip_HIPCC_EXECUTABLE} ${GPU_RTC_FLAGS_SEPARATED} ${GPU_RTC_DEFINES} --genco" > ${GPU_RTC_BIN}.command
@@ -202,7 +211,7 @@ target_include_directories(${MODULE}_CXX PRIVATE $<TARGET_PROPERTY:${TMP_BASELIB
202211
target_link_libraries(${targetName} PRIVATE ${MODULE}_CXX)
203212

204213
if(NOT DEFINED GPUCA_HIP_HIPIFY_FROM_CUDA OR "${GPUCA_HIP_HIPIFY_FROM_CUDA}")
205-
add_custom_target(${MODULE}_HIPIFIED DEPENDS ${HIP_SOURCES} ${MODULE}_HIPIFIED_CHK)
214+
add_custom_target(${MODULE}_HIPIFIED DEPENDS ${HIP_SOURCES})
206215
add_dependencies(${targetName} ${MODULE}_HIPIFIED)
207216
add_dependencies(${MODULE}_CXX ${MODULE}_HIPIFIED)
208217
endif()

GPU/GPUTracking/Base/opencl2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ if(OPENCL2_ENABLED) # BUILD OpenCL2 source code for runtime compilation target
7171
${OCL_FLAGS}
7272
${OCL_DEFINECL}
7373
-cl-no-stdinc
74+
-nostdinc
7475
-E ${CL_SRC} > ${CL_BIN}.src
7576
MAIN_DEPENDENCY ${CL_SRC}
7677
IMPLICIT_DEPENDS CXX ${CL_SRC}

0 commit comments

Comments
 (0)