alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
globalMem.hpp
Go to the documentation of this file.
1/* Copyright 2024 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include "alpaka/core/PP.hpp"
9
10/** Forward declare an external device global variable.
11 *
12 * The variable is only forward declared as external symbol.
13 *
14 * @attention If you compile with a CUDA or HIP compiler and not compile with the option device repeatable code
15 * (-rdc=true) no symbol will be exposed due to the fact that device linking is disabled.
16 *
17 * @param attributes The keyword 'extern' is automatically set and the attribute 'inline' is allowed.
18 * @param dataType Type of the variable, if the type contains comma it must be wrapped in parentheses
19 * @param name Name of the variable you would use later to access the data.
20 */
21#define ALPAKA_DEVICE_GLOBAL_EXTERN(attributes, dataType, name) \
22 ALPAKA_DEVICE_GLOBAL_DATA_HOST_EXTERN(attributes, dataType, name) \
23 ALPAKA_DEVICE_GLOBAL_DATA_CUDA_HIP_EXTERN(attributes, dataType, name) \
24 ALPAKA_DEVICE_GLOBAL_DATA_ONEAPI_EXTERN(attributes, dataType, name)
25
26/** Define a device global variable.
27 *
28 * Initialize the variable with the given values.
29 * A type 'name_t' is created as alias to the wrapper type.
30 * To get access to the data you should call name.get(). If the dataType is a multidimensional C array with compile
31 * time extents the return type of '.get()' is an alpaka::MdSpanArray.
32 *
33 * @param attributes Attributes for the variable definition, can be empty or 'inline', 'static', 'const', 'constexpr',
34 * etc. If oneAPI with AMD backend is used attributes must be empty or 'inline' due to compiler limitations.
35 * @param dataType Type of the variable, if the type contains comma it must be wrapped in parentheses
36 * @param name Name of the variable you would use later to access the data.
37 * @param ... Initializer values for the variable, can be empty. The arguments will be forwarded to the constructor of
38 * dataType. If dataType is a C array the values must be provided in curly braces.
39 */
40#define ALPAKA_DEVICE_GLOBAL(attributes, dataType, name, ...) \
41 ALPAKA_DEVICE_GLOBAL_DATA_HOST(attributes, dataType, name, __VA_ARGS__) \
42 ALPAKA_DEVICE_GLOBAL_DATA_CUDA_HIP(attributes, dataType, name, __VA_ARGS__) \
43 ALPAKA_DEVICE_GLOBAL_DATA_ONEAPI(attributes, dataType, name, __VA_ARGS__) \
44 \
45 struct ALPAKA_PP_CAT(AlpakaGlobalStorage, name) \
46 { \
47 constexpr auto& get(alpaka::api::Host) const \
48 { \
49 return alpaka_onHost::name.value; \
50 } \
51 constexpr auto& getHandle(alpaka::api::Host) const \
52 { \
53 return alpaka_onHost::name; \
54 } \
55 ALPAKA_DEVICE_GLOBAL_GET_CUDA_HIP(attributes, dataType, name, __VA_ARGS__) \
56 ALPAKA_DEVICE_GLOBAL_GET_ONEAPI(attributes, dataType, name, __VA_ARGS__) \
57 }; \
58 \
59 using ALPAKA_PP_CAT(name, _t) = alpaka::onAcc::internal:: \
60 GlobalDeviceMemoryWrapper<ALPAKA_PP_CAT(AlpakaGlobalStorage, name), ALPAKA_PP_REMOVE_BRACKETS(dataType)>; \
61 [[maybe_unused]] constexpr auto name = ALPAKA_PP_CAT(name, _t) \
62 { \
63 }