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

Commit e581541

Browse files
authored
[SYCL] Tests for Level Zero linker flags (#713)
The Level Zero backend never supported linker options, but it previously ignored them silently. The backend now raises an error if a request to link kernel code specifies any linker options. Add two new tests to verify this behavior. One test exercises the deprecated program API. The other exercises the new kernel_bundle API. The test using the kernel_bundle API is currently disabled (see the comments in the test for why). Also mark two existing tests as UNSUPPORTED on Level Zero. These tests were incorrectly passing OpenCL linker flags to the Level Zero backend. This used to work when the backend silently ignored the flags, but it now raises an error.
1 parent ece3226 commit e581541

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

SYCL/DeprecatedFeatures/get-options.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// RUN: %CPU_RUN_PLACEHOLDER %t.out
44
// RUN: %GPU_RUN_PLACEHOLDER %t.out
55
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6-
// XFAIL: cuda || hip
6+
//
7+
// This test passes OpenCL specific compiler and linker swiches to the backend,
8+
// so it is unsupported on any other backend.
9+
// UNSUPPORTED: cuda || hip || level_zero
710

811
#include <CL/sycl.hpp>
912

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clangxx -fsycl -D__SYCL_INTERNAL_API %s -o %t.out
2+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
3+
// REQUIRES: level_zero
4+
//
5+
//==--- level-zero-link-flags.cpp - Error handling for link flags --==//
6+
//
7+
// The Level Zero backend does not accept any online linker options.
8+
// This test validates that an error is raised if you attempt to pass any.
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 <CL/sycl.hpp>
17+
18+
class MyKernel;
19+
20+
void test() {
21+
sycl::queue Queue;
22+
sycl::context Context = Queue.get_context();
23+
24+
sycl::program Program(Context);
25+
Program.compile_with_kernel_type<MyKernel>();
26+
27+
try {
28+
Program.link("-foo");
29+
assert(false && "Expected error linking program");
30+
} catch (const sycl::exception &e) {
31+
assert((e.code() == sycl::errc::build) && "Wrong error code");
32+
} catch (...) {
33+
assert(false && "Expected sycl::exception");
34+
}
35+
36+
Queue.submit([&](sycl::handler &CGH) { CGH.single_task<MyKernel>([=] {}); })
37+
.wait();
38+
}
39+
40+
int main() {
41+
test();
42+
43+
return 0;
44+
}

SYCL/DeprecatedFeatures/program_link.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
//
1010
// Hits an assertion on AMD with multiple GPUs available, fails trace on Nvidia.
1111
// XFAIL: hip_amd || hip_nvidia
12+
//
13+
// Unsupported on Level Zero because the test passes OpenCL specific compiler
14+
// and linker switches.
15+
// UNSUPPORTED: level_zero
1216

1317
#include <CL/sycl.hpp>
1418
#include <iostream>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clangxx -fsycl -Xsycl-target-linker=spir64 -foo %s -o %t.out
2+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
3+
// REQUIRES: level_zero
4+
//
5+
// This test is disabled because the runtime does not currently pass linker
6+
// flags from "-Xsycl-target-linker=spir64 <opts>" when the program calls
7+
// "sycl::link()". This seems like a bug. Note that the runtime does pass
8+
// those "<opts>" to the online linker in other cases when it links device
9+
// code.
10+
//
11+
// XFAIL: level_zero
12+
//
13+
//==--- level-zero-link-flags.cpp - Error handling for link flags --==//
14+
//
15+
// The Level Zero backend does not accept any online linker options.
16+
// This test validates that an error is raised if you attempt to pass any.
17+
//
18+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
19+
// See https://llvm.org/LICENSE.txt for license information.
20+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
21+
//
22+
//===--------------------------------------------------------------===//
23+
24+
#include <sycl/sycl.hpp>
25+
26+
class MyKernel;
27+
28+
void test() {
29+
sycl::queue Queue;
30+
sycl::context Context = Queue.get_context();
31+
32+
auto BundleInput =
33+
sycl::get_kernel_bundle<MyKernel, sycl::bundle_state::input>(Context);
34+
auto BundleObject = sycl::compile(BundleInput);
35+
36+
try {
37+
sycl::link(BundleObject);
38+
assert(false && "Expected error linking kernel bundle");
39+
} catch (const sycl::exception &e) {
40+
std::string Msg(e.what());
41+
assert((e.code() == sycl::errc::build) && "Wrong error code");
42+
assert(Msg.find("-foo") != std::string::npos);
43+
} catch (...) {
44+
assert(false && "Expected sycl::exception");
45+
}
46+
47+
Queue.submit([&](sycl::handler &CGH) { CGH.single_task<MyKernel>([=] {}); })
48+
.wait();
49+
}
50+
51+
int main() {
52+
test();
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)