Skip to content

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

@al42and

Description

@al42and

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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions