|
| 1 | +# Copyright 2019-2026 CERN and copyright holders of ALICE O2. |
| 2 | +# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +# All rights not expressly granted are reserved. |
| 4 | +# |
| 5 | +# This software is distributed under the terms of the GNU General Public |
| 6 | +# License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +# |
| 8 | +# In applying this license CERN does not waive the privileges and immunities |
| 9 | +# granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +# or submit itself to any jurisdiction. |
| 11 | + |
| 12 | +set(MODULE GPUTrackingCPUDevice) |
| 13 | + |
| 14 | +set(SRCS GPUReconstructionCPUDevice.cxx GPUReconstructionCPUDeviceGenRTC.cxx GPUReconstructionCPUDeviceRTCCalls.cxx) |
| 15 | +set(HDRS GPUReconstructionCPUDevice.h GPUReconstructionCPUDeviceInternals.h) |
| 16 | + |
| 17 | +# -------------------------------- RTC: compile the host kernels with clang at runtime (Linux only) ------------------------------------------------------- |
| 18 | +if(NOT LLVM_CLANG) # Normally detected in FindO2GPU.cmake for OpenCL, repeat the detection if OpenCL is disabled |
| 19 | + find_package(LLVM QUIET) |
| 20 | + if(LLVM_FOUND) |
| 21 | + find_package(Clang QUIET) |
| 22 | + endif() |
| 23 | + if(Clang_FOUND) |
| 24 | + find_program(LLVM_CLANG clang HINTS "${Clang_DIR}/../../../bin-safe") |
| 25 | + endif() |
| 26 | +endif() |
| 27 | +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LLVM_CLANG) |
| 28 | + set(GPUCA_CPUDEVICE_RTC ON) |
| 29 | + message(STATUS "Building GPUTracking with CPUDevice support (RTC with ${LLVM_CLANG})") |
| 30 | +else() |
| 31 | + set(GPUCA_CPUDEVICE_RTC OFF) |
| 32 | + message(STATUS "Building GPUTracking with CPUDevice support (no RTC, requires Linux and clang)") |
| 33 | +endif() |
| 34 | + |
| 35 | +if(ALIGPU_BUILD_TYPE STREQUAL "O2") |
| 36 | + set(defineIncludeSrc "O2::${MODULE}") |
| 37 | +else() |
| 38 | + set(defineIncludeSrc "${MODULE}") |
| 39 | +endif() |
| 40 | + |
| 41 | +if(GPUCA_CPUDEVICE_RTC) |
| 42 | + enable_language(ASM) |
| 43 | + if(ALIGPU_BUILD_TYPE STREQUAL "Standalone") |
| 44 | + get_filename_component(GPUDIR ${CMAKE_SOURCE_DIR}/../ ABSOLUTE) |
| 45 | + else() |
| 46 | + set(GPUDIR ${CMAKE_SOURCE_DIR}/GPU/GPUTracking) |
| 47 | + endif() |
| 48 | + |
| 49 | + # Use the same C++ standard library as the host compiler, since the RTC code is loaded into the same process |
| 50 | + set(GPU_RTC_GCC_TOOLCHAIN "") |
| 51 | + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 52 | + get_filename_component(TMP_GCC_BIN_DIR "${CMAKE_CXX_COMPILER}" DIRECTORY) |
| 53 | + get_filename_component(TMP_GCC_ROOT "${TMP_GCC_BIN_DIR}" DIRECTORY) |
| 54 | + set(GPU_RTC_GCC_TOOLCHAIN "--gcc-toolchain=${TMP_GCC_ROOT}") |
| 55 | + endif() |
| 56 | + string(TOUPPER "${CMAKE_BUILD_TYPE}" TMP_BUILD_TYPE_UPPER) |
| 57 | + if(DEFINED CMAKE_CXX_STANDARD) |
| 58 | + set(GPU_RTC_CXX_STANDARD ${CMAKE_CXX_STANDARD}) |
| 59 | + else() |
| 60 | + set(GPU_RTC_CXX_STANDARD 20) |
| 61 | + endif() |
| 62 | + |
| 63 | + set(GPU_RTC_DEFINES "-D$<JOIN:$<TARGET_PROPERTY:${defineIncludeSrc},COMPILE_DEFINITIONS>,$<SEMICOLON>-D>") |
| 64 | + set(GPU_RTC_INCLUDES "-I$<JOIN:$<FILTER:$<TARGET_PROPERTY:${defineIncludeSrc},INCLUDE_DIRECTORIES>,EXCLUDE,^/usr/include/?>,$<SEMICOLON>-I>" |
| 65 | + -I${CMAKE_SOURCE_DIR}/Detectors/Base/src |
| 66 | + -I${CMAKE_SOURCE_DIR}/Detectors/TRD/base/src |
| 67 | + ) |
| 68 | + set(GPU_RTC_FLAGS "${GPU_RTC_GCC_TOOLCHAIN} -std=c++${GPU_RTC_CXX_STANDARD} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${TMP_BUILD_TYPE_UPPER}} -w") |
| 69 | + separate_arguments(GPU_RTC_FLAGS_SEPARATED NATIVE_COMMAND "${GPU_RTC_FLAGS}") |
| 70 | + # Self-contained shared library: static C++ runtime, all symbols hidden and bound locally, only the kernels are exported (via version script at runtime) |
| 71 | + set(GPU_RTC_LINK_FLAGS -fPIC -shared -fvisibility=hidden -fvisibility-inlines-hidden -static-libstdc++ -static-libgcc -Wl,--exclude-libs,ALL -Wl,-Bsymbolic) |
| 72 | + |
| 73 | + set(GPU_RTC_SRC ${GPUDIR}/Base/cpudevice/GPUReconstructionCPUDevicertc.cxx) |
| 74 | + set(GPU_RTC_BIN ${CMAKE_CURRENT_BINARY_DIR}/GPUReconstructionCPUDevicertc) |
| 75 | + |
| 76 | + # Preprocess the RTC source with the flags used for the RTC compilation, since they affect system headers |
| 77 | + add_custom_command( |
| 78 | + OUTPUT ${GPU_RTC_BIN}.src |
| 79 | + COMMAND ${LLVM_CLANG} --driver-mode=g++ ${GPU_RTC_DEFINES} ${GPU_RTC_INCLUDES} ${GPU_RTC_FLAGS_SEPARATED} -x c++ -E -MD -MT ${GPU_RTC_BIN}.src -MF ${GPU_RTC_BIN}.src.d ${GPU_RTC_SRC} -o ${GPU_RTC_BIN}.src |
| 80 | + DEPENDS ${GPU_RTC_SRC} |
| 81 | + DEPFILE ${GPU_RTC_BIN}.src.d |
| 82 | + COMMAND_EXPAND_LISTS |
| 83 | + COMMENT "Preparing CPUDevice RTC source file ${GPU_RTC_BIN}.src" |
| 84 | + ) |
| 85 | + create_binary_resource(${GPU_RTC_BIN}.src ${GPU_RTC_BIN}.src.o) |
| 86 | + |
| 87 | + add_custom_command( |
| 88 | + OUTPUT ${GPU_RTC_BIN}.command |
| 89 | + COMMAND echo -n "${LLVM_CLANG} --driver-mode=g++ ${GPU_RTC_FLAGS_SEPARATED} ${GPU_RTC_LINK_FLAGS}" > ${GPU_RTC_BIN}.command |
| 90 | + COMMAND_EXPAND_LISTS VERBATIM |
| 91 | + COMMENT "Preparing CPUDevice RTC command file ${GPU_RTC_BIN}.command" |
| 92 | + ) |
| 93 | + create_binary_resource(${GPU_RTC_BIN}.command ${GPU_RTC_BIN}.command.o) |
| 94 | + |
| 95 | + add_custom_command( |
| 96 | + OUTPUT ${GPU_RTC_BIN}.command.no_fast_math |
| 97 | + COMMAND echo -n "${GPUCA_CXX_NO_FAST_MATH_FLAGS}" > ${GPU_RTC_BIN}.command.no_fast_math |
| 98 | + COMMAND_EXPAND_LISTS VERBATIM |
| 99 | + COMMENT "Preparing CPUDevice RTC NO_FAST_MATH command file ${GPU_RTC_BIN}.command.no_fast_math" |
| 100 | + ) |
| 101 | + create_binary_resource(${GPU_RTC_BIN}.command.no_fast_math ${GPU_RTC_BIN}.command.no_fast_math.o) |
| 102 | + |
| 103 | + set(SRCS ${SRCS} ${GPU_RTC_BIN}.src.o ${GPU_RTC_BIN}.command.o ${GPU_RTC_BIN}.command.no_fast_math.o) |
| 104 | +endif() |
| 105 | + |
| 106 | +if(ALIGPU_BUILD_TYPE STREQUAL "O2") |
| 107 | + o2_add_library( |
| 108 | + ${MODULE} |
| 109 | + SOURCES ${SRCS} |
| 110 | + PUBLIC_LINK_LIBRARIES O2::GPUTracking |
| 111 | + PRIVATE_INCLUDE_DIRECTORIES |
| 112 | + ${CMAKE_SOURCE_DIR}/Detectors/Base/src |
| 113 | + ${CMAKE_SOURCE_DIR}/Detectors/TRD/base/src |
| 114 | + ${CMAKE_SOURCE_DIR}/DataFormats/Reconstruction/src |
| 115 | + ${CMAKE_CURRENT_SOURCE_DIR} |
| 116 | + TARGETVARNAME targetName) |
| 117 | +endif() |
| 118 | + |
| 119 | +if(ALIGPU_BUILD_TYPE STREQUAL "Standalone") |
| 120 | + set(targetName "${MODULE}") |
| 121 | + add_library(${MODULE} SHARED ${SRCS}) |
| 122 | + add_library(O2::${MODULE} ALIAS ${MODULE}) |
| 123 | + target_link_libraries(${MODULE} PUBLIC O2::GPUTracking) |
| 124 | + install(TARGETS ${MODULE}) |
| 125 | + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
| 126 | +endif() |
| 127 | + |
| 128 | +install(FILES ${HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GPU) |
| 129 | + |
| 130 | +target_compile_definitions(${targetName} PRIVATE $<TARGET_PROPERTY:O2::GPUTracking,COMPILE_DEFINITIONS>) |
| 131 | +target_link_libraries(${targetName} PRIVATE TBB::tbb) |
| 132 | +if(GPUCA_CPUDEVICE_RTC) |
| 133 | + target_compile_definitions(${targetName} PRIVATE GPUCA_CPUDEVICE_RTC) |
| 134 | + target_link_libraries(${targetName} PRIVATE ${CMAKE_DL_LIBS}) |
| 135 | +endif() |
0 commit comments