According to this page: oneAPI for CUDA® - Codeplay Software Ltd, OneMKL is supported with NVIDIA GPU. I used a simple example provided with OneAPI (fcorr_1d_buffers.cpp) fails with the error below. It seems to happen right when the oneapi::mkl::rng::generate() function is called around L48 of the code.

Running on: NVIDIA GeForce RTX 3050 Laptop GPU
terminate called after throwing an instance of ‘sycl::_V1::runtime_error’
*** what(): Native API failed. Native API returns: -42 (PI_ERROR_INVALID_BINARY) -42 (PI_ERROR_INVALID_BINARY)***
Aborted (core dumped)

The OneAPI example code is here: oneAPI-samples/fcorr_1d_buffers.cpp at master · oneapi-src/oneAPI-samples · GitHub

From the error it sounds like you have not built the binary with the flag to use Nvidia hardware.

Are you compiling with the flags in the Get Started Guide, i.e. using the nvptx64-nvidia-cuda flag?

clang++ -fsycl -fsycl-targets=nvptx64-nvidia-cuda simple-sycl-app.cpp -o simple-sycl-app

Thanks for responding.
The short answer is: yes.

The exact line used to compile is:
clang++ -O2 -DMKL_ILP64 -fsycl -fsycl-targets=nvptx64-nvidia-cuda -qmkl=parallel -o CMakeFiles/CodePlay.dir/simple-sycl-app.cpp.o -c simple-sycl-app.cpp

The exact line used to link is:
clang++ -O2 -DMKL_ILP64 -fsycl -fsycl-targets=nvptx64-nvidia-cuda -qmkl=parallel CMakeFiles/CodePlay.dir/simple-sycl-app.cpp.o -o CodePlay

Results are same with the -O2 flag omitted. The MKL flags are needed for the MKL portions of the code. The contents of simple-sycl-app.cpp are the same as fcorr_1d_buffers.cpp (example provided in OneAPI).

Thanks for the information.

You will need to build oneMKL with the right backend to use these custom kernels including for RNG.
The project includes CMake flags to enable these, I believe the appropriate one is ENABLE_CURAND_BACKEND

Just to check, did you get the oneMKL binaries with the oneAPI base toolkit release?

Yes, they are the ones that came with oneAPI base toolkit.
Should I follow the directions here: Building the Project — oneAPI Math Kernel Library Interfaces 0.1 documentation?

As a follow up, can oneMKL be compiled with multiple backends (e.g. ENABLE_MKLCPU_BACKEND, ENABLE_CURAND_BACKEND and ENABLE_CUBLAS_BACKEND) enabled? I assume this is what I need to run common code (either on CPU or GPU, selected at runtime) on my laptop which has an intel CPU and NVIDIA GPU.

Your help is much appreciated.

Yes, take a look at the building for CUDA instructions, you’ll need to enable the backend options you need.

1 Like