diff --git a/SYCL/Plugin/interop-level-zero-interop-task-mem.cpp b/SYCL/Plugin/interop-level-zero-interop-task-mem.cpp index f1dcc27424..5459740296 100644 --- a/SYCL/Plugin/interop-level-zero-interop-task-mem.cpp +++ b/SYCL/Plugin/interop-level-zero-interop-task-mem.cpp @@ -2,45 +2,54 @@ // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %level_zero_options %s -o %t.out // RUN: env SYCL_BE=PI_LEVEL_ZERO %GPU_RUN_PLACEHOLDER %t.out -// Test fails on Level Zero on Linux -// UNSUPPORTED: level_zero && linux +// Test for Level Zero interop_task. -// Test for Level Zero interop_task +// Level-Zero +#include +// SYCL #include -// clang-format off -#include #include -// clang-format on - -class my_selector : public cl::sycl::device_selector { -public: - int operator()(const cl::sycl::device &dev) const override { - return (dev.get_platform().get_backend() == cl::sycl::backend::level_zero) - ? 1 - : 0; - } -}; + +using namespace sycl; + +constexpr size_t SIZE = 16; int main() { - sycl::queue sycl_queue = sycl::queue(my_selector()); - - ze_context_handle_t ze_context = - sycl_queue.get_context().get_native(); - std::cout << "zeContextGetStatus = " << zeContextGetStatus(ze_context) - << std::endl; - - auto buf = cl::sycl::buffer(1024); - sycl_queue.submit([&](cl::sycl::handler &cgh) { - auto acc = buf.get_access(cgh); - cgh.interop_task([&](const cl::sycl::interop_handler &ih) { - void *device_ptr = ih.get_mem(acc); - ze_memory_allocation_properties_t memAllocProperties{}; - zeMemGetAllocProperties(ze_context, device_ptr, &memAllocProperties, - nullptr); - std::cout << "Memory type = " << memAllocProperties.type << std::endl; - }); - }); + queue queue{}; + + try { + buffer buffer(SIZE); + image<2> image(image_channel_order::rgba, image_channel_type::fp32, + {SIZE, SIZE}); + + ze_context_handle_t ze_context = + queue.get_context().get_native(); + + queue + .submit([&](handler &cgh) { + auto buffer_acc = buffer.get_access(cgh); + auto image_acc = image.get_access(cgh); + cgh.interop_task([=](const interop_handler &ih) { + void *device_ptr = ih.get_mem(buffer_acc); + ze_memory_allocation_properties_t memAllocProperties{}; + ze_result_t res = zeMemGetAllocProperties( + ze_context, device_ptr, &memAllocProperties, nullptr); + assert(res == ZE_RESULT_SUCCESS); + + ze_image_handle_t ze_image = + ih.get_mem(image_acc); + assert(ze_image != nullptr); + }); + }) + .wait(); + } catch (exception const &e) { + std::cout << "SYCL exception caught: " << e.what() << std::endl; + return e.get_cl_code(); + } catch (const char *msg) { + std::cout << "Exception caught: " << msg << std::endl; + return 1; + } return 0; } diff --git a/SYCL/Plugin/interop-opencl-interop-task-mem.cpp b/SYCL/Plugin/interop-opencl-interop-task-mem.cpp new file mode 100644 index 0000000000..78390ac575 --- /dev/null +++ b/SYCL/Plugin/interop-opencl-interop-task-mem.cpp @@ -0,0 +1,52 @@ +// REQUIRES: opencl, opencl_icd + +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib +// RUN: %GPU_RUN_PLACEHOLDER %t.out + +// Test for OpenCL interop_task. + +#include +#include +#include + +using namespace sycl; + +constexpr size_t SIZE = 16; + +int main() { + queue queue{}; + + try { + buffer buffer(SIZE); + image<2> image(image_channel_order::rgba, image_channel_type::fp32, + {SIZE, SIZE}); + + queue + .submit([&](handler &cgh) { + auto buffer_acc = buffer.get_access(cgh); + auto image_acc = image.get_access(cgh); + cgh.interop_task([=](const interop_handler &ih) { + cl_mem buffer_mem = ih.get_mem(buffer_acc); + size_t size = 0; + clGetMemObjectInfo(buffer_mem, CL_MEM_SIZE, sizeof(size), + (void *)&size, nullptr); + assert(size == SIZE); + + cl_mem mem = ih.get_mem(image_acc); + size_t width = 0; + clGetImageInfo(mem, CL_IMAGE_WIDTH, sizeof(width), (void *)&width, + nullptr); + assert(width == SIZE); + }); + }) + .wait(); + } catch (exception const &e) { + std::cout << "SYCL exception caught: " << e.what() << std::endl; + return e.get_cl_code(); + } catch (const char *msg) { + std::cout << "Exception caught: " << msg << std::endl; + return 1; + } + + return 0; +}