Project
Loading...
Searching...
No Matches
GPUReconstructionCUDAGenRTC.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 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
14
15#define GPUCA_GPUCODE_HOSTONLY
16
18#include "GPUReconstructionRTCHelpers.inc"
19#include "GPUKernelsWith1Warp.inc"
20#include <algorithm>
21
22using namespace o2::gpu;
23namespace rtc = o2::gpu::internal::rtc;
24
26QGET_LD_BINARY_SYMBOLS(GPUReconstructionCUDArtc_src);
27QGET_LD_BINARY_SYMBOLS(GPUReconstructionCUDArtc_command);
28QGET_LD_BINARY_SYMBOLS(GPUReconstructionCUDArtc_command_arch);
29QGET_LD_BINARY_SYMBOLS(GPUReconstructionCUDArtc_command_no_fast_math);
30
31int32_t GPUReconstructionCUDA::genRTC(std::string& filename, uint32_t& nCompile)
32{
33 const auto& proc = GetProcessingSettings();
34 const std::string_view rtcSource(_binary_GPUReconstructionCUDArtc_src_start, _binary_GPUReconstructionCUDArtc_src_len);
35 const std::string rtcparam = rtc::paramCode(proc, param());
36 rtc::tmpFilename(filename, "/tmp/o2cagpu_rtc_");
37
38 std::vector<std::string> kernels;
39 getRTCKernelCalls(kernels);
40 const std::string kernelsall = rtc::joinKernels(kernels);
41
42 const std::string baseCommand = rtc::baseCommand(proc, std::string_view(_binary_GPUReconstructionCUDArtc_command_start, _binary_GPUReconstructionCUDArtc_command_len)) + " " +
43 (proc.rtctech.overrideArchitecture != "" ? proc.rtctech.overrideArchitecture : std::string(_binary_GPUReconstructionCUDArtc_command_arch_start, _binary_GPUReconstructionCUDArtc_command_arch_len));
44 const std::string noFastMath(_binary_GPUReconstructionCUDArtc_command_no_fast_math_start, _binary_GPUReconstructionCUDArtc_command_no_fast_math_len);
45
46 rtc::loadLaunchBounds(proc, *mParDevice);
47 if constexpr (std::string_view("CUDA") == "HIP") { // Check if we are RTC-compiling for HIP
48 if (proc.hipOverrideAMDEUSperCU > 0) {
49 mParDevice->par_AMD_EUS_PER_CU = proc.hipOverrideAMDEUSperCU;
50 } else if (mParDevice->par_AMD_EUS_PER_CU <= 0) {
51 GPUFatal("AMD_EUS_PER_CU not set in the parameters provided for the AMD GPU, you can override this via --PROChipOverrideAMDEUSperCU [n]");
52 }
53 }
54 for (uint32_t i = 0; i < GetNKernels(); i++) {
55 if (std::find(gpuKernelsWith1Warp.begin(), gpuKernelsWith1Warp.end(), GetKernelName(i)) != gpuKernelsWith1Warp.end()) {
57 }
58 }
59 const std::string launchBounds = rtc::launchBoundsCode(proc, *mParDevice, mParDevice->par_AMD_EUS_PER_CU ? (mParDevice->par_AMD_EUS_PER_CU * mWarpSize) : 0, mWarpSize);
60 if (proc.rtctech.printLaunchBounds >= 2) {
61 return 1;
62 }
63
64 nCompile = proc.rtc.compilePerKernel ? kernels.size() : 1;
65 const std::string compilerVersions = getBackendVersions();
66 rtc::Cache cache(proc, "cuda", {rtcSource, rtcparam, baseCommand, kernelsall, launchBounds, compilerVersions});
67 if (!cache.load(filename, mRtcBinExtension, nCompile)) {
68 rtc::compile(proc, nCompile, "CUDA", [&](uint32_t i) {
69 const std::string fileBase = filename + "_" + std::to_string(i);
70 if (proc.debugLevel >= 3) {
71 printf("Compiling %s\n", (fileBase + mRtcSrcExtension).c_str());
72 }
73 const bool deterministic = rtc::deterministic(proc, GetKernelName(i));
74 const std::string kernel = std::string("extern \"C\" {") + (proc.rtc.compilePerKernel ? kernels[i] : kernelsall) + "}";
75 rtc::writeSource(fileBase + mRtcSrcExtension, deterministic, rtcparam, launchBounds, rtcSource, kernel);
76 const std::string command = baseCommand + (deterministic ? " " + noFastMath : "") + " -c " + fileBase + mRtcSrcExtension + " -o " + fileBase + mRtcBinExtension;
77 rtc::runCommand(proc, command, fileBase + mRtcSrcExtension, "Error during CUDA compilation");
78 });
79 cache.store(filename, mRtcBinExtension, nCompile);
80 }
81 return 0;
82}
int32_t i
static const char * GetKernelName()
const GPUSettingsProcessing & GetProcessingSettings() const
GLenum GLfloat param
Definition glcorearb.h:271
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string filename()
#define QGET_LD_BINARY_SYMBOLS(filename)
int32_t par_LB_maxThreads[$< LIST:LENGTH, $< TARGET_PROPERTY:O2_GPU_KERNELS, O2_GPU_KERNEL_NAMES > >]