From 1e19723f84667b6c889635da7e49522ff1034082 Mon Sep 17 00:00:00 2001 From: Steffen Larsen Date: Mon, 20 Sep 2021 14:40:13 +0300 Subject: [PATCH] [SYCL] Adds regression test for buffer allocation for failed SYCL streams SYCL streams that throws an exception during construction would still create buffers and accessors. This adds a test to ensure that no device memory is allocated for streams if they fail during construction. Signed-off-by: Steffen Larsen --- SYCL/Regression/stream_exception_no_alloc.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 SYCL/Regression/stream_exception_no_alloc.cpp diff --git a/SYCL/Regression/stream_exception_no_alloc.cpp b/SYCL/Regression/stream_exception_no_alloc.cpp new file mode 100644 index 0000000000..550f6bf0a0 --- /dev/null +++ b/SYCL/Regression/stream_exception_no_alloc.cpp @@ -0,0 +1,30 @@ +// RUN: %clangxx -fsycl %s -o %t.out +// RUN: env SYCL_PI_TRACE=2 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER +// RUN: env SYCL_PI_TRACE=2 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER +// RUN: env SYCL_PI_TRACE=2 %ACC_RUN_PLACEHOLDER %t.out 2>&1 %ACC_CHECK_PLACEHOLDER + +// NOTE: This test checks that sycl::stream does not allocate memory if it fails +// during construction. + +#include + +#include + +int main() { + sycl::queue q; + q.submit([&](sycl::handler &cgh) { + try { + // Try to create stream with invalid workItemBufferSize parameter. + sycl::stream invalidStream{256, std::numeric_limits::max(), cgh}; + assert(false && "No exception was thrown."); + } catch (const sycl::invalid_parameter_error &) { + // Expected exception + } catch (...) { + assert(false && "Unexpected exception was thrown."); + } + + cgh.single_task([=]() {}); + }); +} + +// CHECK-NOT:---> piMemBufferCreate