Visible to Intel only — GUID: GUID-81B3CEA9-3D5F-43E6-951B-FF05AB2DD4A3
Visible to Intel only — GUID: GUID-81B3CEA9-3D5F-43E6-951B-FF05AB2DD4A3
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 |
const sycl::queue& queue |
sycl::queue object, which will be used for the newly-created engine. |
mem |
const std::uint8_t* |
Memory, where engine's state was stored. |
Load from File Interface
Name |
Type |
Description |
---|---|---|
queue |
const sycl::queue& queue |
sycl::queue object, which will be used for the newly-created engine. |
filename |
const std::string& |
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 sycl::queue and loaded engine's state. |
- 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
// 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);