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