|
2 | 2 | // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %level_zero_options %s -o %t.out |
3 | 3 | // RUN: env SYCL_BE=PI_LEVEL_ZERO %GPU_RUN_PLACEHOLDER %t.out |
4 | 4 |
|
5 | | -// Test fails on Level Zero on Linux |
6 | | -// UNSUPPORTED: level_zero && linux |
| 5 | +// Test for Level Zero interop_task. |
7 | 6 |
|
8 | | -// Test for Level Zero interop_task |
| 7 | +// Level-Zero |
| 8 | +#include <level_zero/ze_api.h> |
9 | 9 |
|
| 10 | +// SYCL |
10 | 11 | #include <CL/sycl.hpp> |
11 | | -// clang-format off |
12 | | -#include <level_zero/ze_api.h> |
13 | 12 | #include <CL/sycl/backend/level_zero.hpp> |
14 | | -// clang-format on |
15 | | - |
16 | | -class my_selector : public cl::sycl::device_selector { |
17 | | -public: |
18 | | - int operator()(const cl::sycl::device &dev) const override { |
19 | | - return (dev.get_platform().get_backend() == cl::sycl::backend::level_zero) |
20 | | - ? 1 |
21 | | - : 0; |
22 | | - } |
23 | | -}; |
| 13 | + |
| 14 | +using namespace sycl; |
| 15 | + |
| 16 | +constexpr size_t SIZE = 16; |
24 | 17 |
|
25 | 18 | int main() { |
26 | | - sycl::queue sycl_queue = sycl::queue(my_selector()); |
27 | | - |
28 | | - ze_context_handle_t ze_context = |
29 | | - sycl_queue.get_context().get_native<sycl::backend::level_zero>(); |
30 | | - std::cout << "zeContextGetStatus = " << zeContextGetStatus(ze_context) |
31 | | - << std::endl; |
32 | | - |
33 | | - auto buf = cl::sycl::buffer<uint8_t, 1>(1024); |
34 | | - sycl_queue.submit([&](cl::sycl::handler &cgh) { |
35 | | - auto acc = buf.get_access<cl::sycl::access::mode::write>(cgh); |
36 | | - cgh.interop_task([&](const cl::sycl::interop_handler &ih) { |
37 | | - void *device_ptr = ih.get_mem<sycl::backend::level_zero>(acc); |
38 | | - ze_memory_allocation_properties_t memAllocProperties{}; |
39 | | - zeMemGetAllocProperties(ze_context, device_ptr, &memAllocProperties, |
40 | | - nullptr); |
41 | | - std::cout << "Memory type = " << memAllocProperties.type << std::endl; |
42 | | - }); |
43 | | - }); |
| 19 | + queue queue{}; |
| 20 | + |
| 21 | + try { |
| 22 | + buffer<uint8_t, 1> buffer(SIZE); |
| 23 | + image<2> image(image_channel_order::rgba, image_channel_type::fp32, |
| 24 | + {SIZE, SIZE}); |
| 25 | + |
| 26 | + ze_context_handle_t ze_context = |
| 27 | + queue.get_context().get_native<backend::level_zero>(); |
| 28 | + |
| 29 | + queue |
| 30 | + .submit([&](handler &cgh) { |
| 31 | + auto buffer_acc = buffer.get_access<access::mode::write>(cgh); |
| 32 | + auto image_acc = image.get_access<float4, access::mode::write>(cgh); |
| 33 | + cgh.interop_task([=](const interop_handler &ih) { |
| 34 | + void *device_ptr = ih.get_mem<backend::level_zero>(buffer_acc); |
| 35 | + ze_memory_allocation_properties_t memAllocProperties{}; |
| 36 | + ze_result_t res = zeMemGetAllocProperties( |
| 37 | + ze_context, device_ptr, &memAllocProperties, nullptr); |
| 38 | + assert(res == ZE_RESULT_SUCCESS); |
| 39 | + |
| 40 | + ze_image_handle_t ze_image = |
| 41 | + ih.get_mem<backend::level_zero>(image_acc); |
| 42 | + assert(ze_image != nullptr); |
| 43 | + }); |
| 44 | + }) |
| 45 | + .wait(); |
| 46 | + } catch (exception const &e) { |
| 47 | + std::cout << "SYCL exception caught: " << e.what() << std::endl; |
| 48 | + return e.get_cl_code(); |
| 49 | + } catch (const char *msg) { |
| 50 | + std::cout << "Exception caught: " << msg << std::endl; |
| 51 | + return 1; |
| 52 | + } |
44 | 53 |
|
45 | 54 | return 0; |
46 | 55 | } |
0 commit comments