alpaka
Abstraction Library for Parallel Kernel Acceleration
Common.hpp File Reference

Go to the source code of this file.

Macros

#define ALPAKA_DEVICE_VOLATILE
 This macro disables memory optimizations for annotated device memory. More...
 
#define ALPAKA_FN_EXTERN
 All functions marked with ALPAKA_FN_ACC or ALPAKA_FN_HOST_ACC that are exported to / imported from different translation units have to be attributed with ALPAKA_FN_EXTERN. Note that this needs to be applied to both the declaration and the definition. More...
 
#define ALPAKA_FN_INLINE   [[gnu::always_inline]] inline
 Macro defining the inline function attribute. More...
 
#define ALPAKA_NO_HOST_ACC_WARNING
 Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC function_declaration() WARNING: Only use this method if there is no other way. Most cases can be solved by #if BOOST_ARCH_PTX or #if BOOST_LANG_CUDA. More...
 
#define ALPAKA_STATIC_ACC_MEM_CONSTANT
 This macro defines a variable lying in constant accelerator device memory. More...
 
#define ALPAKA_STATIC_ACC_MEM_GLOBAL
 This macro defines a variable lying in global accelerator device memory. More...
 
#define ALPAKA_FN_ACC
 All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_FN_HOST_ACC. More...
 
#define ALPAKA_FN_HOST
 
#define ALPAKA_FN_HOST_ACC
 

Macro Definition Documentation

◆ ALPAKA_DEVICE_VOLATILE

#define ALPAKA_DEVICE_VOLATILE

This macro disables memory optimizations for annotated device memory.

Example: ALPAKA_DEVICE_VOLATILE float* ptr;

This is useful for pointers, (shared) variables and shared memory which are used in combination with the alpaka::mem_fence() function. It ensures that memory annotated with this macro will always be written directly to memory (and not to a register or cache because of compiler optimizations).

Definition at line 208 of file Common.hpp.

◆ ALPAKA_FN_ACC

#define ALPAKA_FN_ACC

All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_FN_HOST_ACC.

Usage:
auto add(std::int32_t a, std::int32_t b)
-> std::int32_t;
#define ALPAKA_FN_ACC
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
Definition: Common.hpp:38

Definition at line 38 of file Common.hpp.

◆ ALPAKA_FN_EXTERN

#define ALPAKA_FN_EXTERN

All functions marked with ALPAKA_FN_ACC or ALPAKA_FN_HOST_ACC that are exported to / imported from different translation units have to be attributed with ALPAKA_FN_EXTERN. Note that this needs to be applied to both the declaration and the definition.

Usage: ALPAKA_FN_ACC ALPAKA_FN_EXTERN auto add(std::int32_t a, std::int32_t b) -> std::int32_t;

Warning: If this is used together with the SYCL back-end make sure that your SYCL runtime supports generic address spaces. Otherwise it is forbidden to use pointers as parameter or return type for functions marked with ALPAKA_FN_EXTERN.

Definition at line 65 of file Common.hpp.

◆ ALPAKA_FN_HOST

#define ALPAKA_FN_HOST

Definition at line 40 of file Common.hpp.

◆ ALPAKA_FN_HOST_ACC

#define ALPAKA_FN_HOST_ACC

Definition at line 39 of file Common.hpp.

◆ ALPAKA_FN_INLINE

#define ALPAKA_FN_INLINE   [[gnu::always_inline]] inline

Macro defining the inline function attribute.

The macro should stay on the left hand side of keywords, e.g. 'static', 'constexpr', 'explicit' or the return type.

Definition at line 95 of file Common.hpp.

◆ ALPAKA_NO_HOST_ACC_WARNING

#define ALPAKA_NO_HOST_ACC_WARNING

Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC function_declaration() WARNING: Only use this method if there is no other way. Most cases can be solved by #if BOOST_ARCH_PTX or #if BOOST_LANG_CUDA.

Definition at line 82 of file Common.hpp.

◆ ALPAKA_STATIC_ACC_MEM_CONSTANT

#define ALPAKA_STATIC_ACC_MEM_CONSTANT
Value:
template<typename TAcc> \
inline

This macro defines a variable lying in constant accelerator device memory.

Example: ALPAKA_STATIC_ACC_MEM_CONSTANT alpaka::DevGlobal<TAcc, const int> variable;

Those variables behave like ordinary variables when used in file-scope, but inside kernels the get() method must be used to access the variable. They are declared inline to resolve to a single instance across multiple translation units. Like ordinary variables, only one definition is allowed (ODR) Failure to do so might lead to linker errors.

In contrast to ordinary variables, you can not define such variables as static compilation unit local variables with internal linkage because this is forbidden by CUDA.

Attention
It is not allowed to initialize the variable together with the declaration. To initialize the variable alpaka::memcpy must be used.
struct DeviceMemoryKernel
{
template<typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc) const
{
auto a = foo<TAcc>.get();
}
}
void initFoo() {
auto extent = alpaka::Vec<alpaka::DimInt<1u>, size_t>{1};
int initialValue = 42;
alpaka::ViewPlainPtr<DevHost, int, alpaka::DimInt<1u>, size_t> bufHost(&initialValue, devHost, extent);
alpaka::memcpy(queue, foo<Acc>, bufHost, extent);
}
A n-dimensional vector.
Definition: Vec.hpp:38
#define ALPAKA_STATIC_ACC_MEM_CONSTANT
This macro defines a variable lying in constant accelerator device memory.
Definition: Common.hpp:191
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
Definition: Common.hpp:82
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void
typename detail::DevGlobalTrait< typename alpaka::trait::AccToTag< TAcc >::type, T >::Type DevGlobal
Definition: Traits.hpp:44
The memory view to wrap plain pointers.

Definition at line 191 of file Common.hpp.

◆ ALPAKA_STATIC_ACC_MEM_GLOBAL

#define ALPAKA_STATIC_ACC_MEM_GLOBAL
Value:
template<typename TAcc> \
inline

This macro defines a variable lying in global accelerator device memory.

Example: ALPAKA_STATIC_ACC_MEM_GLOBAL alpaka::DevGlobal<TAcc, int> variable;

Those variables behave like ordinary variables when used in file-scope, but inside kernels the get() method must be used to access the variable. They are declared inline to resolve to a single instance across multiple translation units. Like ordinary variables, only one definition is allowed (ODR) Failure to do so might lead to linker errors.

In contrast to ordinary variables, you can not define such variables as static compilation unit local variables with internal linkage because this is forbidden by CUDA.

Attention
It is not allowed to initialize the variable together with the declaration. To initialize the variable alpaka::memcpy must be used.
struct DeviceMemoryKernel
{
template<typename TAcc>
ALPAKA_FN_ACC void operator()(TAcc const& acc) const
{
auto a = foo<TAcc>.get();
}
}
void initFoo() {
auto extent = alpaka::Vec<alpaka::DimInt<1u>, size_t>{1};
int initialValue = 42;
alpaka::ViewPlainPtr<DevHost, int, alpaka::DimInt<1u>, size_t> bufHost(&initialValue, devHost, extent);
alpaka::memcpy(queue, foo<Acc>, bufHost, extent);
}
#define ALPAKA_STATIC_ACC_MEM_GLOBAL
This macro defines a variable lying in global accelerator device memory.
Definition: Common.hpp:142

Definition at line 142 of file Common.hpp.