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