Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:30

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2020-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/random/detail/CuHipRngStateInit.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/Types.hh"
0013 #include "corecel/data/Collection.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     //// METHODS ////
0028 
0029     //! True if assigned
0030     explicit CELER_FUNCTION operator bool() const { return !seeds.empty(); }
0031 
0032     //! State size
0033     CELER_FUNCTION size_type size() const { return seeds.size(); }
0034 
0035     //! Assign from another set of data
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 // Initialize the RNG state on host/device
0047 void rng_state_init(DeviceCRef<CuHipRngParamsData> const& params,
0048                     DeviceRef<CuHipRngStateData> const& state,
0049                     DeviceCRef<CuHipRngInitData> const& seeds);
0050 
0051 void rng_state_init(HostCRef<CuHipRngParamsData> const& params,
0052                     HostRef<CuHipRngStateData> const& state,
0053                     HostCRef<CuHipRngInitData> const& seeds);
0054 
0055 #if !CELER_USE_DEVICE
0056 //---------------------------------------------------------------------------//
0057 /*!
0058  * Initialize the RNG states on device from seeds randomly generated on host.
0059  */
0060 inline void rng_state_init(DeviceCRef<CuHipRngParamsData> const&,
0061                            DeviceRef<CuHipRngStateData> const&,
0062                            DeviceCRef<CuHipRngInitData> const&)
0063 {
0064     CELER_ASSERT_UNREACHABLE();
0065 }
0066 #endif
0067 
0068 //---------------------------------------------------------------------------//
0069 }  // namespace detail
0070 }  // namespace celeritas