Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Adds regression test for buffer allocation for failed SYCL streams #467

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions SYCL/Regression/stream_exception_no_alloc.cpp
Original file line number Diff line number Diff line change
@@ -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 <CL/sycl.hpp>

#include <limits>

int main() {
sycl::queue q;
q.submit([&](sycl::handler &cgh) {
try {
// Try to create stream with invalid workItemBufferSize parameter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test in intel/llvm sycl/unittests instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering it, but it was simpler to have single_task try and manifest the memory.

One way to do it in the unittests would be to check that StreamBufferPool remains empty, but since it it private to the scheduler I would need to use the mock scheduler. Do you reckon that would work?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have the same code + PIImages mocks + redefine call of piMemBufferCreate to a function which sets global flag if it is called. Then is "main" check that the flag is not set. Will it work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right, that works. I have moved this to a unittest in intel/llvm#4594 and will close this.

sycl::stream invalidStream{256, std::numeric_limits<size_t>::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