Project
Loading...
Searching...
No Matches
GPUCommonDef.h
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// This is the base header to be included by all files that should feature GPU suppurt.
16// Incompatible code that cannot compile on GPU must be protected by one of the checks below.
17// The usual approach would be to protect with GPUCA_GPUCODE. This will be sufficient for all functions. If header includes still show errors, use GPUCA_ALIGPUCODE
18
19// The following checks are increasingly more strict hiding the code in more and more cases:
20// #ifndef __OPENCL__ : Hide from OpenCL kernel code. All system headers and usage thereof must be protected like this, or stronger.
21// #ifndef GPUCA_GPUCODE_DEVICE : Hide from kernel code on all GPU architectures. This includes the __OPENCL__ case and bodies of all GPU device functions (GPUd(), etc.)
22// #ifndef GPUCA_GPUCODE : Hide from compilation with GPU compiler. This includes the kernel case of GPUCA_GPUCODE_DEVICE but also all host code compiled by the GPU compiler, e.g. for management.
23// #ifndef GPUCA_ALIGPUCODE : Code is completely invisible to the GPUCATracking library, irrespective of GPU or CPU compilation or which compiler.
24
25#ifndef GPUCOMMONDEF_H
26#define GPUCOMMONDEF_H
27
28// clang-format off
29
30//Some GPU configuration settings, must be included first
32
33#if !defined(__CLING__) && !defined(G__ROOT) // No GPU code for ROOT
34 #if defined(__CUDACC__) || defined(__OPENCL__) || defined(__HIPCC__) || defined(__OPENCL_HOST__) || defined(__METAL__) || defined(__METAL_HOST__)
35 #define GPUCA_GPUCODE // Compiled by GPU compiler
36 #endif
37
38 #if defined(GPUCA_GPUCODE)
39 #if defined(__CUDA_ARCH__) || defined(__OPENCL__) || defined(__HIP_DEVICE_COMPILE__) || defined(__METAL_VERSION__)
40 #define GPUCA_GPUCODE_DEVICE // Executed on device
41 #endif
42 #if defined(__CUDACC__)
43 #define GPUCA_GPUTYPE CUDA
44 #elif defined(__HIPCC__)
45 #define GPUCA_GPUTYPE HIP
46 #elif defined(__OPENCL__) || defined(__OPENCL_HOST__)
47 #define GPUCA_GPUTYPE OCL
48 #elif defined(__METAL__) || defined(__METAL_HOST__)
49 #define GPUCA_GPUTYPE METAL
50 #endif
51 #endif
52#endif
53#ifndef GPUCA_GPUTYPE
54 #define GPUCA_GPUTYPE CPU
55#endif
56
57#if defined(GPUCA_STANDALONE) || (defined(GPUCA_O2_LIB) && !defined(GPUCA_O2_INTERFACE)) || defined (GPUCA_GPUCODE)
58 #define GPUCA_ALIGPUCODE // Part of GPUTracking library but not of interface
59#endif
60
61// __METAL__ unconditionally: the MSL generic address space does not span
62// `constant`, so a generic member function cannot be called on an object living
63// there, and the shared code is generic throughout.
64#if (defined(__CUDACC__) && defined(GPUCA_CUDA_NO_CONSTANT_MEMORY)) || (defined(__HIPCC__) && defined(GPUCA_HIP_NO_CONSTANT_MEMORY)) || (defined(__OPENCL__) && defined(GPUCA_OPENCL_NO_CONSTANT_MEMORY)) || defined(__METAL__)
65 #define GPUCA_NO_CONSTANT_MEMORY
66#elif (defined(__CUDACC__) || defined(__HIPCC__)) && !defined(GPUCA_GPUCODE_HOSTONLY)
67 #define GPUCA_HAS_GLOBAL_SYMBOL_CONSTANT_MEM
68#endif
69
70#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && defined(DEBUG_STREAMER)
71 #define GPUCA_DEBUG_STREAMER_CHECK(...) __VA_ARGS__
72#else
73 #define GPUCA_DEBUG_STREAMER_CHECK(...)
74#endif
75
76#ifndef GPUCA_RTC_SPECIAL_CODE // By default, we ignore special RTC code
77 #define GPUCA_RTC_SPECIAL_CODE(...)
78#endif
79
80#ifndef GPUCA_RTC_CONSTEXPR
81 #define GPUCA_RTC_CONSTEXPR
82#endif
83
84#ifndef GPUCA_DETERMINISTIC_CODE
85 #ifdef GPUCA_DETERMINISTIC_MODE
86 #define GPUCA_DETERMINISTIC_CODE(det, indet) det // In deterministic mode, take deterministic code path
87 #else
88 #define GPUCA_DETERMINISTIC_CODE(det, indet) indet // otherwise the fast default code path
89 #endif
90#endif
91
92// API Definitions for GPU Compilation
93#include "GPUCommonDefAPI.h"
94
95// clang-format on
96
97#endif