oneMKL icon indicating copy to clipboard operation
oneMKL copied to clipboard

Missing function rng::device::generate_single

Open npolina4 opened this issue 1 year ago • 1 comments

Summary

Missing functions rng::device::generate_single and rng::host::generate_single. I can see this functions in code, but I cannot see them in library after build.

Reproducer

#include <sycl/sycl.hpp>
#include <oneapi/mkl/rng/device.hpp>

namespace mkl_dev_rng = oneapi::mkl::rng::device;

int main(void)
{
    sycl::queue q{sycl::default_selector_v};

    const auto &dev = q.get_device();
    std::cout << "Device: " << dev.get_info<sycl::info::device::name>() << std::endl;
    std::cout << "Driver_version: " << dev.get_info<sycl::info::device::driver_version>() << std::endl;

    using T = float;
    constexpr std::size_t size = 10;
    T *data = sycl::malloc_device<T>(size, q);

    using EngineT = mkl_dev_rng::mcg59<2>;

    q.submit([&](sycl::handler &cgh) {
        cgh.parallel_for<>(sycl::range<1>(size/2), [=](sycl::id<1> id) {
            size_t i = id[0];

            constexpr std::uint32_t seed = 12345u;
            EngineT engine(seed, 2*i);
            mkl_dev_rng::gaussian<T> distr(0, 1);

            data[2*i] = mkl_dev_rng::generate_single(distr, engine);
            data[2*i + 1] = mkl_dev_rng::generate_single(distr, engine);
        });
    }).wait_and_throw();

    T *host_data = new T[size];
    q.memcpy(host_data, data, size * sizeof(T)).wait();

    std::cout << "Data:\n";
    for (std::uint16_t i = 0; i < size; i++) {
        std::cout << std::to_string(host_data[i]) << ", ";
    }
    std::cout << std::endl;

    sycl::free(data, q);
    delete[] host_data;
    return 0;
} 

build out: error: no member named 'generate_single' in namespace 'oneapi::mkl::rng::device’

npolina4 avatar Apr 23 '24 16:04 npolina4

Hi @npolina4,

For device API the situation is the following: Intel oneMKL product supports this function and it is available in #include <oneapi/mkl/rng/device.hpp> from the binary distribution

However, we deliberately didn't include this function into oneMKL specification and oneMKL interfaces as it seems a bit redundant (if vec_size = 1 for engine it acts the same as just generate).

Do you have a wide usage of this function or is it enough to use regular generate for your use cases?

aelizaro avatar Apr 23 '24 17:04 aelizaro