Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU OpenCL: Fixes and workaround for undefined symbols that make the clang SPIRV code actually link correctly #13704

Merged
merged 6 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions GPU/Common/GPUCommonAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,29 @@ GPUdi() void GPUCommonAlgorithm::swap(T& a, T& b)
// Nothing to do, work_group functions available
#pragma OPENCL EXTENSION cl_khr_subgroups : enable

#define warp_scan_inclusive_add(v) sub_group_scan_inclusive_add(v)
#define warp_broadcast(v, i) sub_group_broadcast(v, i)
template <class T>
GPUdi() T work_group_scan_inclusive_add_FUNC(T v)
{
return sub_group_scan_inclusive_add(v);
}
template <> // FIXME: It seems OpenCL does not support 8 and 16 bit subgroup operations
GPUdi() uint8_t work_group_scan_inclusive_add_FUNC<uint8_t>(uint8_t v)
{
return sub_group_scan_inclusive_add((uint32_t)v);
}
template <class T>
GPUdi() T work_group_broadcast_FUNC(T v, int32_t i)
{
return sub_group_broadcast(v, i);
}
template <>
GPUdi() uint8_t work_group_broadcast_FUNC<uint8_t>(uint8_t v, int32_t i)
{
return sub_group_broadcast((uint32_t)v, i);
}

#define warp_scan_inclusive_add(v) work_group_scan_inclusive_add_FUNC(v)
#define warp_broadcast(v, i) work_group_broadcast_FUNC(v, i)

#elif (defined(__CUDACC__) || defined(__HIPCC__))
// CUDA and HIP work the same way using cub, need just different header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace gpu
} // namespace GPUCA_NAMESPACE
using namespace GPUCA_NAMESPACE::gpu;

#if !defined(GPUCA_OPENCL1) && (!defined(GPUCA_ALIROOT_LIB) || !defined(GPUCA_GPUCODE))
#define GPUCA_KRNL_NOOCL1
#endif

// clang-format off
$<JOIN:$<LIST:TRANSFORM,$<LIST:TRANSFORM,$<LIST:REMOVE_DUPLICATES,$<TARGET_PROPERTY:O2_GPU_KERNELS,O2_GPU_KERNEL_FILES>>,APPEND,">,PREPEND,#include ">,
>
Expand Down
9 changes: 5 additions & 4 deletions GPU/GPUTracking/Base/opencl-common/GPUReconstructionOCL.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,17 @@ int32_t GPUReconstructionOCL::InitDevice_Runtime()
clGetPlatformInfo(mInternals->platforms[i_platform], CL_PLATFORM_VERSION, sizeof(platform_version), platform_version, nullptr);
clGetPlatformInfo(mInternals->platforms[i_platform], CL_PLATFORM_NAME, sizeof(platform_name), platform_name, nullptr);
clGetPlatformInfo(mInternals->platforms[i_platform], CL_PLATFORM_VENDOR, sizeof(platform_vendor), platform_vendor, nullptr);
if (mProcessingSettings.debugLevel >= 2) {
GPUInfo("Available Platform %d: (%s %s) %s %s", i_platform, platform_profile, platform_version, platform_vendor, platform_name);
}
const char* platformUsageInfo = "";
if (!found && CheckPlatform(i_platform)) {
found = true;
mInternals->platform = mInternals->platforms[i_platform];
if (mProcessingSettings.debugLevel >= 2) {
GPUInfo(" Using this platform");
platformUsageInfo = " !!! Using this platform !!!";
}
}
if (mProcessingSettings.debugLevel >= 2) {
GPUInfo("Available Platform %d: (%s %s) %s %s%s", i_platform, platform_profile, platform_version, platform_vendor, platform_name, platformUsageInfo);
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions GPU/GPUTracking/Base/opencl2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if(OPENCL2_ENABLED_SPIRV) # BUILD OpenCL2 intermediate code for SPIR-V target
MAIN_DEPENDENCY ${CL_SRC}
IMPLICIT_DEPENDS CXX ${CL_SRC}
COMMAND_EXPAND_LISTS
COMMENT "Compiling OpenCL2 CL source file ${CL_SRC} to SPIRV")
COMMENT "Compiling OpenCL2 CL source file ${CL_SRC} to SPIRV ${CL_BIN}.spirv")

create_binary_resource(${CL_BIN}.spirv ${CMAKE_CURRENT_BINARY_DIR}/GPUReconstructionOCLCode.spirv.o)
set(SRCS ${SRCS} ${CMAKE_CURRENT_BINARY_DIR}/GPUReconstructionOCLCode.spirv.o)
Expand All @@ -64,12 +64,14 @@ if(OPENCL2_ENABLED) # BUILD OpenCL2 source code for runtime compilation target
add_custom_command(
OUTPUT ${CL_BIN}.src
COMMAND ${LLVM_CLANG}
${OCL_DEFINECL} -cl-no-stdinc
${OCL_FLAGS}
${OCL_DEFINECL}
-cl-no-stdinc
-E ${CL_SRC} > ${CL_BIN}.src
MAIN_DEPENDENCY ${CL_SRC}
IMPLICIT_DEPENDS CXX ${CL_SRC}
COMMAND_EXPAND_LISTS
COMMENT "Preparing OpenCL2 CL source file for run time compilation")
COMMENT "Preparing OpenCL2 CL source file for run time compilation ${CL_BIN}.src")

create_binary_resource(${CL_BIN}.src ${CMAKE_CURRENT_BINARY_DIR}/GPUReconstructionOCLCode.src.o)
set(SRCS ${SRCS} ${CMAKE_CURRENT_BINARY_DIR}/GPUReconstructionOCLCode.src.o)
Expand Down
2 changes: 1 addition & 1 deletion GPU/GPUTracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ endif()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly)
file(GENERATE
OUTPUT include_gpu_onthefly/GPUReconstructionKernelList.h
INPUT Base/GPUReconstructionKernels.template.h
INPUT Base/GPUReconstructionKernelList.template.h
)
file(GENERATE
OUTPUT include_gpu_onthefly/GPUReconstructionKernelIncludes.h
Expand Down
6 changes: 5 additions & 1 deletion GPU/GPUTracking/Definitions/GPUDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
// Macros for masking ptrs in OpenCL kernel calls as uint64_t (The API only allows us to pass buffer objects)
#ifdef __OPENCL__
#define GPUPtr1(a, b) uint64_t b
#define GPUPtr2(a, b) ((__global a) (a) b)
#ifdef __OPENCLCPP__
#define GPUPtr2(a, b) ((__generic a) (a) b)
#else
#define GPUPtr2(a, b) ((__global a) (a) b)
#endif
#else
#define GPUPtr1(a, b) a b
#define GPUPtr2(a, b) b
Expand Down
4 changes: 2 additions & 2 deletions GPU/GPUTracking/Refit/GPUTrackingRefit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct refitTrackTypes<TrackParCov> {
} // anonymous namespace

template <>
GPUd() void GPUTrackingRefit::initProp<GPUTPCGMPropagator>(GPUTPCGMPropagator& prop)
GPUd() void GPUTrackingRefit::initProp<GPUgeneric() GPUTPCGMPropagator>(GPUTPCGMPropagator& prop) // FIXME: GPUgeneric() needed to make the clang spirv output link correctly
{
prop.SetMaterialTPC();
prop.SetMaxSinPhi(GPUCA_MAX_SIN_PHI);
Expand All @@ -91,7 +91,7 @@ GPUd() void GPUTrackingRefit::initProp<GPUTPCGMPropagator>(GPUTPCGMPropagator& p
}

template <>
GPUd() void GPUTrackingRefit::initProp<const Propagator*>(const Propagator*& prop)
GPUd() void GPUTrackingRefit::initProp<const Propagator * GPUgeneric()>(const Propagator*& prop) // FIXME: GPUgeneric() needed to make the clang spirv output link correctly
{
prop = mPpropagator;
}
Expand Down
4 changes: 2 additions & 2 deletions GPU/GPUTracking/SliceTracker/GPUTPCTrackletConstructor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ GPUd() int32_t GPUTPCTrackletConstructor::FetchTracklet(GPUconstantref() MEM_GLO
#endif // GPUCA_GPUCODE

#if !defined(__OPENCL1__)
template <>
GPUd() int32_t GPUTPCTrackletConstructor::GPUTPCTrackletConstructorGlobalTracking<GPUTPCGlobalTracking::GPUSharedMemory>(GPUconstantref() MEM_GLOBAL(GPUTPCTracker) & GPUrestrict() tracker, GPUsharedref() GPUTPCGlobalTracking::GPUSharedMemory& sMem, MEM_LG(GPUTPCTrackParam) & GPUrestrict() tParam, int32_t row, int32_t increment, int32_t iTracklet, calink* rowHits)
template <> // FIXME: GPUgeneric() needed to make the clang spirv output link correctly
GPUd() int32_t GPUTPCTrackletConstructor::GPUTPCTrackletConstructorGlobalTracking<GPUgeneric() GPUTPCGlobalTracking::GPUSharedMemory>(GPUconstantref() MEM_GLOBAL(GPUTPCTracker) & GPUrestrict() tracker, GPUsharedref() GPUTPCGlobalTracking::GPUSharedMemory& sMem, MEM_LG(GPUTPCTrackParam) & GPUrestrict() tParam, int32_t row, int32_t increment, int32_t iTracklet, calink* rowHits)
{
GPUTPCThreadMemory rMem;
rMem.mISH = iTracklet;
Expand Down
Loading