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__) || defined(__CPUDEVICE__)
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__) || defined(__CPUDEVICE__)
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 #elif defined(__CPUDEVICE__)
51 #define GPUCA_GPUTYPE CPUDEVICE
52 #endif
53 #endif
54#endif
55#ifndef GPUCA_GPUTYPE
56 #define GPUCA_GPUTYPE CPU
57#endif
58
59#if defined(GPUCA_STANDALONE) || (defined(GPUCA_O2_LIB) && !defined(GPUCA_O2_INTERFACE)) || defined (GPUCA_GPUCODE)
60 #define GPUCA_ALIGPUCODE // Part of GPUTracking library but not of interface
61#endif
62
63// __METAL__ unconditionally: the MSL generic address space does not span
64// `constant`, so a generic member function cannot be called on an object living
65// there, and the shared code is generic throughout.
66#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__)
67 #define GPUCA_NO_CONSTANT_MEMORY
68#elif (defined(__CUDACC__) || defined(__HIPCC__)) && !defined(GPUCA_GPUCODE_HOSTONLY)
69 #define GPUCA_HAS_GLOBAL_SYMBOL_CONSTANT_MEM
70#endif
71
72#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && defined(DEBUG_STREAMER)
73 #define GPUCA_DEBUG_STREAMER_CHECK(...) __VA_ARGS__
74#else
75 #define GPUCA_DEBUG_STREAMER_CHECK(...)
76#endif
77
78#ifndef GPUCA_RTC_SPECIAL_CODE // By default, we ignore special RTC code
79 #define GPUCA_RTC_SPECIAL_CODE(...)
80#endif
81
82#ifndef GPUCA_RTC_CONSTEXPR
83 #define GPUCA_RTC_CONSTEXPR
84#endif
85
86#if defined(GPUCA_DETERMINISTIC_MODE) && defined(__METAL__)
87 // The deterministic paths compute the transcendentals in double (see
88 // GPUCommonMath::SinCos). The emulated double is bit-exact for + - * / but
89 // its sin and cos are within 2 ulp of libm, not identical to it, so the
90 // results could not match the other backends.
91 #error "GPUCA_DETERMINISTIC_MODE is not supported on Metal"
92#endif
93
94#ifndef GPUCA_DETERMINISTIC_CODE
95 #ifdef GPUCA_DETERMINISTIC_MODE
96 #define GPUCA_DETERMINISTIC_CODE(det, indet) det // In deterministic mode, take deterministic code path
97 #else
98 #define GPUCA_DETERMINISTIC_CODE(det, indet) indet // otherwise the fast default code path
99 #endif
100#endif
101
102// API Definitions for GPU Compilation
103#include "GPUCommonDefAPI.h"
104
105// clang-format on
106
107#endif