File indexing completed on 2025-09-14 08:50:58
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Assert.hh"
0010 #include "corecel/Macros.hh"
0011 #include "corecel/Types.hh"
0012 #include "corecel/data/Collection.hh"
0013 #include "corecel/random/engine/CuHipRngEngine.hh"
0014
0015 #include "../CuHipRngData.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021
0022 template<Ownership W, MemSpace M>
0023 struct CuHipRngInitData
0024 {
0025 StateCollection<ull_int, W, M> seeds;
0026
0027
0028
0029
0030 explicit CELER_FUNCTION operator bool() const { return !seeds.empty(); }
0031
0032
0033 CELER_FUNCTION size_type size() const { return seeds.size(); }
0034
0035
0036 template<Ownership W2, MemSpace M2>
0037 CuHipRngInitData& operator=(CuHipRngInitData<W2, M2> const& other)
0038 {
0039 CELER_EXPECT(other);
0040 seeds = other.seeds;
0041 return *this;
0042 }
0043 };
0044
0045
0046
0047
0048
0049 struct RngSeedExecutor
0050 {
0051 NativeCRef<CuHipRngParamsData> const params;
0052 NativeRef<CuHipRngStateData> const state;
0053 NativeCRef<CuHipRngInitData> const seeds;
0054
0055
0056 inline CELER_FUNCTION void operator()(TrackSlotId tid) const
0057 {
0058 CELER_EXPECT(tid < state.size());
0059 CuHipRngInitializer init;
0060 init.seed = seeds.seeds[tid];
0061 CuHipRngEngine rng{params, state, tid};
0062 rng = init;
0063 }
0064
0065
0066 CELER_FORCEINLINE_FUNCTION void operator()(ThreadId tid) const
0067 {
0068 return (*this)(TrackSlotId{tid.unchecked_get()});
0069 }
0070 };
0071
0072
0073
0074 void rng_state_init(DeviceCRef<CuHipRngParamsData> const& params,
0075 DeviceRef<CuHipRngStateData> const& state,
0076 DeviceCRef<CuHipRngInitData> const& seeds,
0077 StreamId stream);
0078
0079 void rng_state_init(HostCRef<CuHipRngParamsData> const& params,
0080 HostRef<CuHipRngStateData> const& state,
0081 HostCRef<CuHipRngInitData> const& seeds,
0082 StreamId);
0083
0084 #if !CELER_USE_DEVICE
0085
0086
0087
0088
0089 inline void rng_state_init(DeviceCRef<CuHipRngParamsData> const&,
0090 DeviceRef<CuHipRngStateData> const&,
0091 DeviceCRef<CuHipRngInitData> const&,
0092 StreamId)
0093 {
0094 CELER_ASSERT_UNREACHABLE();
0095 }
0096 #endif
0097
0098
0099 }
0100 }