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

Commit 3de4a77

Browse files
authored
[SYCL] Test error handling undefined device symbol (#712)
Add a test for the case when a kernel references an undefined symbol. We expect an exception at kernel submission time with a message telling the name of the undefined symbol.
1 parent 6bc57b4 commit 3de4a77

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// XFAIL: cuda || hip
2+
// UNSUPPORTED: host
3+
// RUN: %clangxx -fsycl %s -o %t.out
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7+
//
8+
//==--- undefined-symbol.cpp - Error handling for undefined device symbol --==//
9+
//
10+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11+
// See https://llvm.org/LICENSE.txt for license information.
12+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13+
//
14+
//===--------------------------------------------------------------===//
15+
16+
#include <sycl/sycl.hpp>
17+
SYCL_EXTERNAL
18+
void symbol_that_does_not_exist();
19+
20+
void test() {
21+
sycl::queue Queue;
22+
23+
auto Kernel = []() {
24+
#ifdef __SYCL_DEVICE_ONLY__
25+
// This is not guaranteed by the SYCL specification, but DPC++ currently
26+
// does not diagnose an error at compilation/link time if a kernel
27+
// references an undefined symbol from within code that is protected by
28+
// __SYCL_DEVICE_ONLY__. As a result, this error is delayed and diagnosed
29+
// at runtime when the kernel is submitted to a device.
30+
//
31+
// This test is "unsupported" on the host device because the kernel does
32+
// not actually contain an undefined reference in that case.
33+
symbol_that_does_not_exist();
34+
#endif // __SYCL_DEVICE_ONLY__
35+
};
36+
37+
try {
38+
Queue.submit(
39+
[&](sycl::handler &CGH) { CGH.single_task<class SingleTask>(Kernel); });
40+
assert(false && "Expected error submitting kernel");
41+
} catch (const sycl::exception &e) {
42+
assert((e.code() == sycl::errc::build) && "Wrong error code");
43+
44+
// Error message should mention name of undefined symbol.
45+
std::string Msg(e.what());
46+
assert(Msg.find("symbol_that_does_not_exist") != std::string::npos);
47+
} catch (...) {
48+
assert(false && "Expected sycl::exception");
49+
}
50+
}
51+
52+
int main() {
53+
test();
54+
55+
return 0;
56+
}

0 commit comments

Comments
 (0)