llvm / llvm/llvm-project

[SYCL] Feature request: support device code assertions

Open
#221,297 3 comments 0 reactions 0 assignees View on GitHub
confirmed SYCL
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I am working to enable SYCL capable Clang compiler for Pytorch. As of today a lot of features are not implemented for SYCL in Clang which is understandable. Problem is that at the moment I don't have a way to abort the program once not implemented feature is encountered which gives extreme difficulty to 1) enable the supported scope, 2) clearly identify what is not supported. Can assertions, please, be supported in LLVM implementation of SYCL? The intended usage for assertions in general is clear. At the current stage of enabling Pytorch with SYCL capable Clang, my usage would be:

```c++
#include
#include

class TestKernel;

int main() {
sycl::queue q;
const size_t dataSize = 1;

q.submit([&](sycl::handler &cgh) {
cgh.parallel_for(
sycl::range<1>(dataSize),
[=](sycl::id<1> idx) {
assert(!"abort sycl kernel: feature XXX is not currently supported");
# if 0
// Existing Pytorch SYCL code
// ...
# endif
});
});
q.wait();

return 0;
}
```

With the above, currently (see https://github.com/llvm/llvm-project/issues/221283 for the patch to get unresolved external symbols debug prints):

```console
$ clang++ -fsycl test.cpp -Wl,--no-undefined -o a.clang
$ ./a.clang
./a.clang
>>>> RC=0
error : unresolved external symbol __assert_fail at offset 396 in instructions segment #0 (aka kernel : _ZTS10TestKernel)
error : unresolved external symbol __assert_fail at offset 412 in instructions segment #0 (aka kernel : _ZTS10TestKernel)

terminate called after throwing an instance of 'sycl::__V0::exception'
what(): 3 (OL_ERRC_INVALID_BINARY) zeKernelCreate failed with error 2013265944, ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED
Aborted
```

CC: @KseniyaTikhomirova, @gmlueck, @tahonermann

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provided clang++ -fsycl example and reviewing LLVM issue 221283, which is referenced for unresolved external symbol diagnostics. The work is complete when the device-side assertion is supported by the SYCL implementation instead of producing an unresolved __assert_fail symbol and invalid module error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.