File indexing completed on 2025-09-13 08:53:54
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Assert.hh"
0011 #include "corecel/OpaqueId.hh"
0012 #include "corecel/random/data/CuHipRngData.hh"
0013 #include "corecel/random/distribution/GenerateCanonical.hh"
0014 #include "corecel/sys/ThreadId.hh"
0015
0016 namespace celeritas
0017 {
0018
0019
0020
0021
0022
0023
0024
0025
0026 class CuHipRngEngine
0027 {
0028 public:
0029
0030
0031 using result_type = unsigned int;
0032 using Initializer_t = CuHipRngInitializer;
0033 using ParamsRef = NativeCRef<CuHipRngParamsData>;
0034 using StateRef = NativeRef<CuHipRngStateData>;
0035
0036
0037 public:
0038
0039 inline CELER_FUNCTION CuHipRngEngine(ParamsRef const& params,
0040 StateRef const& state,
0041 TrackSlotId tid);
0042
0043
0044 inline CELER_FUNCTION CuHipRngEngine& operator=(Initializer_t const&);
0045
0046
0047 inline CELER_FUNCTION result_type operator()();
0048
0049 private:
0050 CuHipRngThreadState* state_;
0051
0052 template<class Generator, class RealType>
0053 friend struct GenerateCanonical;
0054 };
0055
0056
0057
0058
0059
0060 template<>
0061 struct GenerateCanonical<CuHipRngEngine, float>
0062 {
0063
0064
0065 using real_type = float;
0066 using result_type = real_type;
0067
0068
0069
0070 static constexpr auto policy = GenerateCanonicalPolicy::custom;
0071
0072
0073 inline CELER_FUNCTION result_type operator()(CuHipRngEngine& rng);
0074 };
0075
0076
0077
0078
0079
0080 template<>
0081 struct GenerateCanonical<CuHipRngEngine, double>
0082 {
0083
0084
0085 using real_type = double;
0086 using result_type = real_type;
0087
0088
0089
0090 static constexpr auto policy = GenerateCanonicalPolicy::custom;
0091
0092
0093 inline CELER_FUNCTION result_type operator()(CuHipRngEngine& rng);
0094 };
0095
0096
0097
0098
0099
0100
0101
0102 CELER_FUNCTION
0103 CuHipRngEngine::CuHipRngEngine(ParamsRef const&,
0104 StateRef const& state,
0105 TrackSlotId tid)
0106 {
0107 CELER_EXPECT(tid < state.rng.size());
0108 state_ = &state.rng[tid];
0109 }
0110
0111
0112
0113
0114
0115 CELER_FUNCTION CuHipRngEngine& CuHipRngEngine::operator=(Initializer_t const& s)
0116 {
0117 CELER_RNG_PREFIX(rand_init)(s.seed, s.subsequence, s.offset, state_);
0118 return *this;
0119 }
0120
0121
0122
0123
0124
0125 CELER_FUNCTION auto CuHipRngEngine::operator()() -> result_type
0126 {
0127 return CELER_RNG_PREFIX(rand)(state_);
0128 }
0129
0130
0131
0132
0133
0134 CELER_FUNCTION float
0135 GenerateCanonical<CuHipRngEngine, float>::operator()(CuHipRngEngine& rng)
0136 {
0137 return CELER_RNG_PREFIX(rand_uniform)(rng.state_);
0138 }
0139
0140
0141
0142
0143
0144 CELER_FUNCTION double
0145 GenerateCanonical<CuHipRngEngine, double>::operator()(CuHipRngEngine& rng)
0146 {
0147 return CELER_RNG_PREFIX(rand_uniform_double)(rng.state_);
0148 }
0149
0150
0151 }