Block-Structured AMR Software Framework
 
Loading...
Searching...
No Matches
AMReX_SIMD.H
Go to the documentation of this file.
1#ifndef AMREX_SIMD_H_
2#define AMREX_SIMD_H_
3
4#include <AMReX_Config.H>
5
6#include <AMReX_REAL.H>
7
8#ifdef AMREX_USE_SIMD
9// TODO make SIMD provider configurable: VIR (C++17 TS2) or C++26 (later)
10# include <vir/simd.h> // includes SIMD TS2 header <experimental/simd>
11# if __cplusplus >= 202002L
12# include <vir/simd_cvt.h>
13# endif
14#endif
15
16#include <cstdint>
17#include <type_traits>
18
19
20namespace amrex::simd
21{
22 // TODO make SIMD provider configurable: VIR (C++17 TS2) or C++26 (later)
23 // for https://en.cppreference.com/w/cpp/experimental/simd/simd_cast.html
24 namespace stdx {
25#ifdef AMREX_USE_SIMD
26 using namespace vir::stdx;
27# if __cplusplus >= 202002L
28 using vir::cvt;
29# endif
30#else
31 // fallback implementations for functions that are commonly used in portable code paths
32
34 bool any_of (bool const v) { return v; }
35#endif
36 }
37
38 // TODO: move to AMReX_REAL.H?
39
40#ifdef AMREX_USE_SIMD
41 // TODO: not sure why std::experimental::simd_abi::native<T> does not work, so we use this long version
42 constexpr auto native_simd_size_real = stdx::native_simd<amrex::Real>::size();
43 constexpr auto native_simd_size_particlereal = stdx::native_simd<amrex::ParticleReal>::size();
44
45 // Note: to make use of not only vector registers but also ILP, user might want to use * 2 or more of the native size
46 // for selected compute kernels.
47 // TODO Check if a default with * 2 or similar is sensible.
48 template<int SIMD_WIDTH = native_simd_size_real>
49 using SIMDReal = stdx::fixed_size_simd<amrex::Real, SIMD_WIDTH>;
50
51 template<int SIMD_WIDTH = native_simd_size_particlereal>
52 using SIMDParticleReal = stdx::fixed_size_simd<amrex::ParticleReal, SIMD_WIDTH>;
53
54 // Type that has the same amount of IdCpu SIMD elements as the SIMDParticleReal type
55 template<typename T_ParticleReal = SIMDParticleReal<>>
56 using SIMDIdCpu = stdx::rebind_simd_t<std::uint64_t, T_ParticleReal>;
57#else
58 constexpr auto native_simd_size_real = 1;
60
61 template<int SIMD_WIDTH = native_simd_size_real>
62 using SIMDReal = amrex::Real;
63
64 template<int SIMD_WIDTH = native_simd_size_particlereal>
65 using SIMDParticleReal = amrex::ParticleReal;
66
67 // Type that has the same amount of IdCpu SIMD elements as the SIMDParticleReal type
68 template<typename T_ParticleReal = SIMDParticleReal<>>
69 using SIMDIdCpu = std::uint64_t;
70#endif
71
72 namespace detail {
74 }
75
102 template<int SIMD_WIDTH = native_simd_size_real>
103 struct
105 {
107 static constexpr int simd_width = SIMD_WIDTH;
108 };
109
114 template<typename T>
115 constexpr bool is_vectorized = std::is_base_of_v<detail::InternalVectorized, T>;
116
137 template<typename R, typename... Args>
138 constexpr bool is_nth_arg_non_const (R(*)(Args...), int n)
139 {
140 constexpr bool val_arr[sizeof...(Args)] {!std::is_const_v<std::remove_reference_t<Args>>...};
141 return val_arr[n];
142 }
143 // same for functors (const/non-const ::operator() members)
144 template<typename C, typename R, typename... Args>
145 constexpr bool is_nth_arg_non_const (R(C::*)(Args...), int n)
146 {
147 constexpr bool val_arr[sizeof...(Args)] {!std::is_const_v<std::remove_reference_t<Args>>...};
148 return val_arr[n];
149 }
150 template<typename C, typename R, typename... Args>
151 constexpr bool is_nth_arg_non_const (R(C::*)(Args...) const, int n)
152 {
153 constexpr bool val_arr[sizeof...(Args)] {!std::is_const_v<std::remove_reference_t<Args>>...};
154 return val_arr[n];
155 }
156
157} // namespace amrex::simd
158
159#endif
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
AMREX_GPU_HOST_DEVICE bool any_of(bool const v)
Definition AMReX_SIMD.H:34
Definition AMReX_SIMD.H:21
std::uint64_t SIMDIdCpu
Definition AMReX_SIMD.H:69
constexpr auto native_simd_size_real
Definition AMReX_SIMD.H:58
constexpr bool is_vectorized
Definition AMReX_SIMD.H:115
constexpr bool is_nth_arg_non_const(R(*)(Args...), int n)
Definition AMReX_SIMD.H:138
amrex::ParticleReal SIMDParticleReal
Definition AMReX_SIMD.H:65
constexpr auto native_simd_size_particlereal
Definition AMReX_SIMD.H:59
amrex::Real SIMDReal
Definition AMReX_SIMD.H:62
Definition AMReX_FabArrayCommI.H:1000
Definition AMReX_SIMD.H:105
Definition AMReX_SIMD.H:73