Vlasiator
ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
arch_device_api.h
Go to the documentation of this file.
1
#include <stdint.h>
2
#ifndef ARCH_DEVICE_API_H
3
#define ARCH_DEVICE_API_H
4
5
/* Host-device function declarations */
6
#if (defined(USE_GPU) && (defined(__CUDACC__) || defined(__HIP_PLATFORM_HCC___)))
7
#define ARCH_HOSTDEV __host__ __device__
8
#define ARCH_DEV __device__
9
#else
10
#define ARCH_HOSTDEV
11
#define ARCH_DEV
12
#endif
13
14
/* Namespace for the common loop interface functions */
15
namespace
arch
{
16
/* Type definition used in the headers */
17
typedef
uint32_t
uint
;
18
/* Enums for different reduction types */
19
enum
reduce_op
{
max
,
min
,
sum
,
prod
,
null
};
20
}
21
22
/* Select the compiled architecture */
23
#if defined(USE_GPU) && defined(__CUDACC__)
24
#include "
arch_device_cuda.h
"
25
#elif defined(USE_GPU) && defined(__HIP_PLATFORM_HCC___)
26
#include "
arch_device_hip.h
"
27
#else
28
#include "
arch_device_host.h
"
29
#endif
30
31
/* The macro for the inner loop body definition */
32
#define ARCH_GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
33
#define ARCH_INNER_BODY(...) ARCH_GET_MACRO(__VA_ARGS__, ARCH_INNER_BODY4, ARCH_INNER_BODY3, ARCH_INNER_BODY2)(__VA_ARGS__)
34
35
/* Namespace for the common loop interface functions */
36
namespace
arch
{
37
38
/* Parallel reduce interface function - specialization for 1 reduction variable */
39
template
<reduce_op Op, u
int
NDim,
typename
Lambda,
typename
T>
40
inline
static
void
parallel_reduce
(
const
uint
(&limits)[NDim], Lambda loop_body, T &
sum
) {
41
constexpr
uint
NReductions = 1;
42
arch::parallel_reduce_driver<Op, NReductions, NDim>
(limits, loop_body, &
sum
, NReductions);
43
}
44
45
/* Parallel reduce interface function - specialization for a reduction variable array */
46
template
<reduce_op Op, u
int
NDim, u
int
NReductions,
typename
Lambda,
typename
T>
47
inline
static
void
parallel_reduce
(
const
uint
(&limits)[NDim], Lambda loop_body, T (&
sum
)[NReductions]) {
48
arch::parallel_reduce_driver<Op, NReductions, NDim>
(limits, loop_body, &
sum
[0], NReductions);
49
}
50
51
/* Parallel reduce interface function - specialization for a reduction variable vector */
52
template
<reduce_op Op, u
int
NDim,
typename
Lambda,
typename
T>
53
inline
static
void
parallel_reduce
(
const
uint
(&limits)[NDim], Lambda loop_body, std::vector<T> &
sum
) {
54
arch::parallel_reduce_driver<Op, 0, NDim>
(limits, loop_body,
sum
.data(),
sum
.size());
55
}
56
57
}
58
#endif
// !ARCH_DEVICE_API_H
arch_device_cuda.h
arch_device_hip.h
arch_device_host.h
arch
Definition
arch_device_api.h:15
arch::parallel_reduce_driver
static __forceinline__ void parallel_reduce_driver(const uint(&limits)[NDim], Lambda loop_body, T *sum, const uint n_redu_dynamic)
Definition
arch_device_cuda.h:442
arch::reduce_op
reduce_op
Definition
arch_device_api.h:19
arch::max
@ max
Definition
arch_device_api.h:19
arch::prod
@ prod
Definition
arch_device_api.h:19
arch::min
@ min
Definition
arch_device_api.h:19
arch::null
@ null
Definition
arch_device_api.h:19
arch::sum
@ sum
Definition
arch_device_api.h:19
arch::parallel_reduce
static void parallel_reduce(const uint(&limits)[NDim], Lambda loop_body, T &sum)
Definition
arch_device_api.h:40
arch::uint
uint32_t uint
Definition
arch_device_api.h:17
arch
arch_device_api.h
Generated on
for Vlasiator by
1.16.1