|
| 1 | +//==------------------- DeleteCmdException.cpp ----------------------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +// REQUIRES: level_zero |
| 10 | + |
| 11 | +// UNSUPPORTED: windows |
| 12 | +// UNSUPPORTED-TRACKER: CMPLRLLVM-44705 |
| 13 | + |
| 14 | +// RUN: %{build} -o %t.out |
| 15 | +// RUN: %{l0_leak_check} %{run} %t.out |
| 16 | + |
| 17 | +#include <sycl/detail/core.hpp> |
| 18 | + |
| 19 | +void test_exception(sycl::queue &q, sycl::buffer<int, 1> &buf, |
| 20 | + size_t workGroupSize) { |
| 21 | + |
| 22 | + try { |
| 23 | + // Illegal nd_range |
| 24 | + auto illegal_range = sycl::nd_range<1>{sycl::range<1>{workGroupSize * 2}, |
| 25 | + sycl::range<1>{workGroupSize + 32}}; |
| 26 | + |
| 27 | + // Will throw when submitted |
| 28 | + q.submit([&](sycl::handler &cgh) { |
| 29 | + auto acc = buf.get_access<sycl::access::mode::read_write>(cgh); |
| 30 | + cgh.parallel_for(illegal_range, [=](sycl::nd_item<1> nd_item) { |
| 31 | + acc[nd_item.get_global_linear_id()] = 42; // will not be reached |
| 32 | + }); |
| 33 | + }).wait_and_throw(); |
| 34 | + } catch (const sycl::exception &e) { |
| 35 | + std::cout << "exception caught: " << e.code() << ":\t"; |
| 36 | + std::cout << e.what() << std::endl; |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +int main() { |
| 41 | + sycl::queue q; |
| 42 | + sycl::device dev = q.get_device(); |
| 43 | + int maxWorkGroupSize = |
| 44 | + dev.get_info<sycl::info::device::max_work_group_size>(); |
| 45 | + |
| 46 | + constexpr size_t NumWorkItems = |
| 47 | + 2048; // this value is arbitrary since kernel is never run. |
| 48 | + std::vector<int> source(NumWorkItems, 0); |
| 49 | + { |
| 50 | + // Buffers with their own memory will have their memory release deferred, |
| 51 | + // while buffers backstopped by host memory will release when the buffer is |
| 52 | + // destroyed. This means there are two different paths we need to check to |
| 53 | + // ensure we are not leaking resources when encountering exceptions. |
| 54 | + |
| 55 | + // buffer with own memory |
| 56 | + sycl::buffer<int, 1> buf{sycl::range<1>{NumWorkItems}}; |
| 57 | + |
| 58 | + // buffer backstopped by host memory |
| 59 | + sycl::buffer<int, 1> buf2{source.data(), sycl::range<1>{NumWorkItems}}; |
| 60 | + |
| 61 | + test_exception(q, buf, maxWorkGroupSize); |
| 62 | + |
| 63 | + test_exception(q, buf2, maxWorkGroupSize); |
| 64 | + } |
| 65 | + |
| 66 | + return 0; |
| 67 | +} |
0 commit comments