oneapi::mkl::rng::load_state¶
Loads the state of the random number engine from the provided memory buffer or file, then creates new engine object.
Description¶
The oneapi::mkl::rng::load_state
function allows you to create a new random number engine object from the binary state of another engine, which was written in a memory buffer or file. You can use different sycl::queue
objects for the new engine.
API¶
Syntax¶
Load from Memory Interface
template<typename Engine>
Engine load_state (const sycl::queue& queue,
const std::uint8_t* mem);
Load from File Interface
template<typename Engine>
Engine load_state (const sycl::queue& queue,
const std::string& filename);
Include Files¶
oneapi/mkl/rng.hpp
Input Parameters¶
Load from Memory Interface
Name |
Type |
Description |
---|---|---|
queue |
|
|
mem |
|
Memory, where engine's state was stored. |
Load from File Interface
Name |
Type |
Description |
---|---|---|
queue |
|
|
filename |
|
Name of the file where engine's state was written. |
Output Parameters¶
Type |
Description |
---|---|
Engine |
New random number engine object, which would be created from the given |
- The following code illustrates how to store the engine's state to the
engine_state.dat
file and load it back:
Code for Save/Load state functionality¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Creating GPU engine
oneapi::mkl::rng::default_engine engine(gpu_queue);
// Saving state of engine in the file
oneapi::mkl::rng::save_state(engine, "engine_state.dat");
// Generating random numbers from the GPU engine
oneapi::mkl::rng::generate(oneapi::mkl::rng::uniform{}, engine, n, r1);
// Loading state for the CPU queue
auto engine_2 = oneapi::mkl::rng::load_state<oneapi::mkl::rng::default_engine>(cpu_queue, "engine_state.dat");
// Generating random numbers from the CPU engine
oneapi::mkl::rng::generate(oneapi::mkl::rng::uniform{}, engine_2, n, r2);
|