intel / intel/llvm

sycl::stream causes leak if exception is thrown during launch

Open
#15,111 0 comments 0 reactions 0 assignees View on GitHub
bug confirmed
Dominant language
LLVM
Stars
1.5k
Forks
854
Avg merge
3d 17h
Merged PRs (30d)
137

Description

### Describe the bug

The `sycl::stream` class leaks multiple backend objects if the launch it is used in throws an exception. This can be illustrated with:

```c++
#include

using namespace sycl;

int main() {
queue q = queue();

try {
const int N = 1;
q.submit([&](handler &cgh) {
sycl::stream kernelout(128, 64, cgh);
cgh.parallel_for(
nd_range<3>(range<3>{1, 1, N}, range<3>{1, 1, 16}),
[=](nd_item<3> itm) { kernelout << 1; });
}).wait();
return 1;
} catch (exception &E) {
return E.code() != errc::nd_range;
}
}
```

Compile and run:
```
$ clang++ -fsycl test.cpp -o test.out
$ UR_L0_LEAKS_DEBUG=1 ./test.out
Check balance of create/destroy calls
----------------------------------------------------------
zeContextCreate = 1 \---> zeContextDestroy = 0 ---> LEAK = 1
zeCommandQueueCreate = 0 \---> zeCommandQueueDestroy = 0
zeModuleCreate = 1 \---> zeModuleDestroy = 0 ---> LEAK = 1
zeKernelCreate = 1 \---> zeKernelDestroy = 0 ---> LEAK = 1
zeEventPoolCreate = 1 \---> zeEventPoolDestroy = 0 ---> LEAK = 1
zeCommandListCreateImmediate = 2 |
zeCommandListCreate = 0 \---> zeCommandListDestroy = 0 ---> LEAK = 2
zeEventCreate = 1 \---> zeEventDestroy = 0 ---> LEAK = 1
zeFenceCreate = 0 \---> zeFenceDestroy = 0
zeImageCreate = 0 \---> zeImageDestroy = 0
zeSamplerCreate = 0 \---> zeSamplerDestroy = 0
zeMemAllocDevice = 2 |
zeMemAllocHost = 1 |
zeMemAllocShared = 2 \---> zeMemFree = 4 ---> LEAK = 1
```

### To reproduce

1. Include a code snippet that is as short as possible
2. Specify the command which should be used to compile the program
3. Specify the command which should be used to launch the program
4. Indicate what is wrong and what was expected

### Environment

- OS: [e.g Windows/Linux]
- Target device and vendor: [e.g. Intel GPU]
- DPC++ version: [e.g. commit hash or output of `clang++ --version`]
- Dependencies version: [e.g. the output of `sycl-ls --verbose`]

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.