File indexing completed on 2026-11-03 10:19:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #pragma once
0015
0016 #include <cstddef>
0017 #include <string>
0018 #include <type_traits>
0019
0020 #include "corecel/Config.hh"
0021
0022 #include "Macros.hh"
0023
0024 namespace celeritas
0025 {
0026
0027
0028 template<class T, std::size_t N>
0029 class Array;
0030
0031
0032
0033
0034 #if CELER_USE_DEVICE || defined(__DOXYGEN__)
0035
0036 using size_type = unsigned int;
0037 #else
0038 using size_type = std::size_t;
0039 #endif
0040
0041 #if CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_DOUBLE || defined(__DOXYGEN__)
0042
0043 using real_type = double;
0044 #elif CELERITAS_REAL_TYPE == CELERITAS_REAL_TYPE_FLOAT
0045 using real_type = float;
0046 #else
0047 using real_type = void;
0048 #endif
0049
0050
0051 using ull_int = unsigned long long int;
0052
0053
0054 using Real3 = Array<real_type, 3>;
0055
0056
0057
0058
0059
0060 enum class MemSpace
0061 {
0062 host,
0063 device,
0064 mapped,
0065 size_,
0066 #if defined(CELER_DEVICE_SOURCE) || defined(__DOXYGEN__)
0067 native = device,
0068 #else
0069 native = host,
0070 #endif
0071 };
0072
0073
0074 enum class Ownership
0075 {
0076 value,
0077 reference,
0078 const_reference,
0079 };
0080
0081
0082
0083 enum class UnitSystem
0084 {
0085 none,
0086 cgs,
0087 si,
0088 clhep,
0089 size_,
0090 native = CELERITAS_UNITS,
0091 };
0092
0093
0094
0095
0096
0097
0098
0099
0100 template<template<Ownership, MemSpace> class P>
0101 using HostVal = P<Ownership::value, MemSpace::host>;
0102
0103 template<template<Ownership, MemSpace> class P>
0104 using HostCRef = P<Ownership::const_reference, MemSpace::host>;
0105
0106 template<template<Ownership, MemSpace> class S>
0107 using HostRef = S<Ownership::reference, MemSpace::host>;
0108
0109
0110 template<template<Ownership, MemSpace> class P>
0111 using DeviceCRef = P<Ownership::const_reference, MemSpace::device>;
0112
0113 template<template<Ownership, MemSpace> class S>
0114 using DeviceRef = S<Ownership::reference, MemSpace::device>;
0115
0116
0117 template<template<Ownership, MemSpace> class P>
0118 using NativeCRef = P<Ownership::const_reference, MemSpace::native>;
0119
0120 template<template<Ownership, MemSpace> class S>
0121 using NativeRef = S<Ownership::reference, MemSpace::native>;
0122
0123 template<class T, MemSpace M>
0124 class ObserverPtr;
0125
0126
0127 template<template<Ownership, MemSpace> class P, MemSpace M>
0128 using CRefPtr = ObserverPtr<P<Ownership::const_reference, M> const, M>;
0129
0130 template<template<Ownership, MemSpace> class S, MemSpace M>
0131 using RefPtr = ObserverPtr<S<Ownership::reference, M>, M>;
0132
0133
0134
0135
0136
0137
0138
0139
0140 template<MemSpace M, class HT, class DT>
0141 using MemSpaceCond_t
0142 = std::conditional_t<M == MemSpace::host,
0143 HT,
0144 std::conditional_t<M == MemSpace::device, DT, void>>;
0145
0146
0147
0148
0149
0150
0151
0152
0153 template<class T>
0154 struct IsTriviallyCopyable : std::is_trivially_copyable<T>
0155 {
0156 };
0157
0158
0159
0160
0161
0162
0163
0164
0165 template<class T>
0166 struct IsAutoLdg
0167 : std::bool_constant<std::is_arithmetic_v<T> || std::is_enum_v<T>>
0168 {
0169 static_assert(!std::is_const_v<T> && !std::is_reference_v<T>
0170 && !std::is_pointer_v<T>);
0171 };
0172
0173
0174 template<class T>
0175 struct MakeSize : std::make_unsigned_t<T>
0176 {
0177 };
0178
0179
0180
0181
0182
0183
0184
0185
0186 template<class T>
0187 constexpr inline bool is_trivially_copyable_v = IsTriviallyCopyable<T>::value;
0188
0189
0190 template<class T>
0191 constexpr inline bool is_auto_ldg_v = IsAutoLdg<T>::value;
0192
0193
0194 template<class F>
0195 constexpr inline bool is_launchable_v
0196 = (is_trivially_copyable_v<F> || CELERITAS_USE_HIP
0197 || CELER_COMPILER == CELER_COMPILER_CLANG)
0198 && !std::is_pointer_v<F> && !std::is_reference_v<F>;
0199
0200
0201 template<class T>
0202 using MakeSize_t = typename MakeSize<std::remove_cv_t<T>>::type;
0203
0204
0205
0206
0207
0208
0209
0210 char const* to_cstring(MemSpace m);
0211
0212
0213 char const* to_cstring(UnitSystem);
0214
0215
0216 UnitSystem to_unit_system(std::string const& s);
0217
0218
0219
0220
0221
0222
0223
0224 namespace literals
0225 {
0226
0227
0228 CELER_CONSTEXPR_FUNCTION real_type operator""_r(long double value)
0229 {
0230 return static_cast<real_type>(value);
0231 }
0232
0233
0234 CELER_CONSTEXPR_FUNCTION real_type operator""_r(unsigned long long int value)
0235 {
0236 return static_cast<real_type>(value);
0237 }
0238
0239
0240 CELER_CONSTEXPR_FUNCTION size_type operator""_sz(unsigned long long int value)
0241 {
0242 return static_cast<size_type>(value);
0243 }
0244
0245
0246 }
0247 }