Visible to Intel only — GUID: GUID-D209BEA0-CD4B-42D8-9144-FFFB214FF380
Visible to Intel only — GUID: GUID-D209BEA0-CD4B-42D8-9144-FFFB214FF380
oneapi::mkl::rng::get_state_size
Returns the size in bytes which is needed to store the state of a given random number engine.
Description
The oneapi::mkl::rng::get_state_size function allows you to know the amount of memory needed for storing the engine’s state in memory.
API
Syntax
template<typename Engine> std::int64_t get_state_size (Engine& engine);
Include Files
oneapi/mkl/rng.hpp
Input Parameters
Name |
Type |
Description |
---|---|---|
engine |
Engine& |
Random number engine object, which state size would be calculated. |
Output Parameters
Type |
Description |
---|---|
std::int64_t |
Size of the given engine’s state in bytes. |
The following code illustrates how to use the oneapi::mkl::rng::get_state_size function to store the engine’s state to memory:
Code for Save/Load state functionality
// Creating GPU engine oneapi::mkl::rng::default_engine engine(gpu_queue); // Checking how much memory is required to save auto mem_size = oneapi::mkl::rng::get_state_size(engine); // Allocating memory buffer std::uint8_t* mem_buf = new std::uint8_t[mem_size]; // Saving state of engine in the file oneapi::mkl::rng::save_state(engine, mem_buf); // 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, mem_buf); // Generating random numbers from the CPU engine oneapi::mkl::rng::generate(oneapi::mkl::rng::uniform{}, engine_2, n, r2); // Cleaning up memory buffer delete[] mem_buf;