DDC
0.0.0
a
d
iscrete
d
omain
c
omputation library
About
Commented example
API reference
Contribute on Github
transform_reduce.hpp
1
// Copyright (C) The DDC development team, see COPYRIGHT.md file
2
//
3
// SPDX-License-Identifier: MIT
4
5
#pragma once
6
7
#include <cstddef>
8
#include <type_traits>
9
#include <utility>
10
11
#include <Kokkos_Core.hpp>
12
13
#include "ddc/detail/kokkos.hpp"
14
#include "ddc/detail/macros.hpp"
15
#include "ddc/discrete_domain.hpp"
16
#include "ddc/discrete_element.hpp"
17
#include "ddc/reducer.hpp"
18
19
namespace
ddc
{
20
21
namespace
detail {
22
32
template
<
33
class
...
DDims
,
34
class
T,
35
class
BinaryReductionOp
,
36
class
UnaryTransformOp
,
37
class
...
DCoords
>
38
T transform_reduce_serial(
39
DiscreteDomain<DDims...>
const
& domain,
40
[[
maybe_unused
]] T
const
neutral
,
41
BinaryReductionOp
const
&
reduce
,
42
UnaryTransformOp
const
&
transform
,
43
DCoords
const
&...
dcoords
)
noexcept
44
{
45
DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS
(
implicit_return_from_non_void_function
)
46
if
constexpr
(
sizeof
...(DCoords) ==
sizeof
...(
DDims
)) {
47
return
transform
(DiscreteElement<DDims...>(
dcoords
...));
48
}
else
{
49
using
CurrentDDim
=
type_seq_element_t
<
sizeof
...(DCoords), detail::TypeSeq<DDims...>>;
50
T
result
=
neutral
;
51
for
(
DiscreteElement<CurrentDDim>
const
ii
:
select
<
CurrentDDim
>(domain)) {
52
result
=
reduce
(
53
result
,
54
transform_reduce_serial(domain,
neutral
,
reduce
,
transform
,
dcoords
...,
ii
));
55
}
56
return
result
;
57
}
58
DDC_IF_NVCC_THEN_POP
59
}
60
61
}
// namespace detail
62
71
template
<
class
...
DDims
,
class
T,
class
BinaryReductionOp
,
class
UnaryTransformOp
>
72
T
transform_reduce
(
73
DiscreteDomain<DDims...>
const
& domain,
74
T
neutral
,
75
BinaryReductionOp
&&
reduce
,
76
UnaryTransformOp
&&
transform
)
noexcept
77
{
78
return
detail::transform_reduce_serial(
79
domain,
80
neutral
,
81
std::forward<BinaryReductionOp>(
reduce
),
82
std::forward<UnaryTransformOp>(
transform
));
83
}
84
85
}
// namespace ddc
ddc::DiscreteDomain
Definition
discrete_domain.hpp:51
ddc
The top-level namespace of DDC.
Definition
aligned_allocator.hpp:11
ddc::enable_chunk
constexpr bool enable_chunk
Definition
chunk_traits.hpp:16
ddc::transform_reduce
T transform_reduce(DiscreteDomain< DDims... > const &domain, T neutral, BinaryReductionOp &&reduce, UnaryTransformOp &&transform) noexcept
A reduction over a nD domain in serial.
Definition
transform_reduce.hpp:72
ddc::select
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > select(DiscreteDomain< DDims... > const &domain)
Definition
discrete_domain.hpp:385