File indexing completed on 2025-09-14 08:50:58
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <random>
0010
0011 #include "corecel/Config.hh"
0012 #include "corecel/DeviceRuntimeApi.hh"
0013
0014 #include "corecel/Assert.hh"
0015 #include "corecel/Macros.hh"
0016 #include "corecel/Types.hh"
0017 #include "corecel/data/Collection.hh"
0018 #include "corecel/sys/Device.hh"
0019
0020
0021
0022
0023
0024
0025
0026 #if CELERITAS_USE_CUDA
0027
0028 # define QUALIFIERS static __forceinline__ __host__ __device__
0029 # include <curand_kernel.h>
0030
0031 # define CELER_RNG_PREFIX(TOK) cu##TOK
0032 #elif CELERITAS_USE_HIP
0033 # if (HIP_VERSION_MAJOR > 5 \
0034 || (HIP_VERSION_MAJOR == 5 && HIP_VERSION_MINOR >= 3))
0035
0036
0037 # define QUALIFIERS __forceinline__ __host__ __device__
0038 # else
0039
0040 # define FQUALIFIERS __forceinline__ __host__ __device__
0041 # endif
0042 # pragma clang diagnostic push
0043
0044 # pragma clang diagnostic ignored "-W#warnings"
0045
0046 # pragma clang diagnostic ignored "-Wunused-result"
0047 # include <hiprand/hiprand_kernel.h>
0048 # pragma clang diagnostic pop
0049 # define CELER_RNG_PREFIX(TOK) hip##TOK
0050 #else
0051
0052 # include "detail/MockRand.hh"
0053
0054 # define CELER_RNG_PREFIX(TOK) mock##TOK
0055 #endif
0056
0057 namespace celeritas
0058 {
0059
0060 #if !CELER_USE_DEVICE
0061 using mockrandState_t = detail::MockRandState;
0062 #endif
0063
0064
0065 using CuHipRngThreadState = CELER_RNG_PREFIX(randState_t);
0066
0067
0068
0069
0070
0071 template<Ownership W, MemSpace M>
0072 struct CuHipRngParamsData
0073 {
0074
0075
0076 unsigned int seed = 12345;
0077
0078
0079
0080
0081 explicit CELER_FUNCTION operator bool() const { return true; }
0082
0083
0084 template<Ownership W2, MemSpace M2>
0085 CuHipRngParamsData& operator=(CuHipRngParamsData<W2, M2> const& other)
0086 {
0087 seed = other.seed;
0088 return *this;
0089 }
0090 };
0091
0092
0093
0094
0095
0096 struct CuHipRngInitializer
0097 {
0098 ull_int seed{0};
0099 ull_int subsequence{0};
0100 ull_int offset{0};
0101 };
0102
0103
0104
0105
0106
0107 template<Ownership W, MemSpace M>
0108 struct CuHipRngStateData
0109 {
0110
0111
0112 template<class T>
0113 using StateItems = StateCollection<T, W, M>;
0114
0115
0116
0117 StateItems<CuHipRngThreadState> rng;
0118
0119
0120
0121
0122 explicit CELER_FUNCTION operator bool() const { return !rng.empty(); }
0123
0124
0125 CELER_FUNCTION size_type size() const { return rng.size(); }
0126
0127
0128 template<Ownership W2, MemSpace M2>
0129 CuHipRngStateData& operator=(CuHipRngStateData<W2, M2>& other)
0130 {
0131 CELER_EXPECT(other);
0132 rng = other.rng;
0133 return *this;
0134 }
0135 };
0136
0137
0138
0139
0140
0141 template<MemSpace M>
0142 void resize(CuHipRngStateData<Ownership::value, M>* state,
0143 HostCRef<CuHipRngParamsData> const& params,
0144 StreamId stream,
0145 size_type size);
0146
0147 }