intel / llvm

Intel staging area for llvm.org contribution. Home for Intel LLVM-based projects.
Other
1.21k stars 725 forks source link

[SYCL][OpenCL] malloc_device returns 0 when USM is not supported, should throw #9513

Open al42and opened 1 year ago

al42and commented 1 year ago

Describe the bug

sycl::device_malloc, per the spec v2020 r7, should throw when the device does not support USM:

Throws a synchronous exception with the errc::feature_not_supported error code if the syclDevice does not have aspect::usm_device_allocations.

However, when used with Mesa Rusticl backend, which does not support USM, it calmly returns 0 instead.

This seems to also affect other sycl:malloc_X functions.

To Reproduce

#include <iostream>
#include <sycl/sycl.hpp>

int main(int, char **) {
  for (const auto &device : sycl::device::get_devices()) {
    sycl::queue queue(device);
    std::cout << "Running on " << device.get_info<sycl::info::device::name>()
              << "\n";
    std::cout << "usm_device_allocations: "
              << device.has(sycl::aspect::usm_device_allocations) << std::endl;
    float *d_buf = sycl::malloc_device<float>(1, queue);
    std::cout << "malloc_device returned: " << d_buf << std::endl;
  }

  return 0;
}
$ clang++ -fsycl hello_sycl_usm.cpp -o hello_sycl_usm

# Running on AMD GPU via Mesa OpenCL, usm_device_allocations not supported:
$ ONEAPI_DEVICE_SELECTOR=opencl:2 RUSTICL_ENABLE=radeonsi ./hello_sycl_usm
Running on AMD Radeon RX 6400 (navi24, LLVM 15.0.7, DRM 3.49, 6.2.8-060208-generic)
usm_device_allocations: 0
malloc_device returned: 0

Environment (please complete the following information):

pwisniewskimobica commented 1 year ago

@al42and @AlexeySachkov Guys do you maybe know is there any device without USM to run on windows? I would like to reproduce this error on Win but every device I got uses usm

al42and commented 1 year ago

@al42and @AlexeySachkov Guys do you maybe know is there any device without USM to run on windows? I would like to reproduce this error on Win but every device I got uses usm

No :(

bader commented 1 year ago

@al42and @AlexeySachkov Guys do you maybe know is there any device without USM to run on windows? I would like to reproduce this error on Win but every device I got uses usm

@pwisniewskimobica, you can try to use unit-test infrastructure for the DPC++ runtime library. It allows you to override the results of low-level API calls, so you can mock the device with no-usm support. You can find examples here: https://github.com/intel/llvm/tree/sycl/sycl/unittests. Feel free to ping @intel/llvm-reviewers-runtime team if you have questions about using the unit-test framework.

pwisniewskimobica commented 1 year ago

@bader @al42and @AlexeySachkov I made PR for this: https://github.com/intel/llvm/pull/10348 Please take a look