Skip to content

Commit 1cfd02e

Browse files
[SYCL] Move more in-tree tests to the test-suite (intel/llvm-test-suite#1279)
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 3a7f918 commit 1cfd02e

File tree

3 files changed

+210
-0
lines changed

3 files changed

+210
-0
lines changed

SYCL/Basic/exceptions-SYCL-2020.cpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
6+
#include <sycl/sycl.hpp>
7+
8+
using namespace sycl;
9+
10+
int main() {
11+
// Test new constructors, initially each with empty string messages.
12+
std::string emptyStr;
13+
const char *emptyCharPtr = "";
14+
15+
// Going to set the error code values to each of the enum (0-12).
16+
exception ex1(make_error_code(errc::runtime), emptyStr); // errc::runtime == 1
17+
exception ex2(make_error_code(errc::kernel), emptyCharPtr);
18+
exception ex3(make_error_code(errc::accessor));
19+
exception ex4(static_cast<int>(errc::nd_range), sycl_category(), emptyStr);
20+
exception ex5(static_cast<int>(errc::event), sycl_category(), emptyCharPtr);
21+
exception ex6(static_cast<int>(errc::kernel_argument), sycl_category());
22+
23+
queue Q;
24+
context ctx = Q.get_context();
25+
exception ex7(ctx, make_error_code(errc::build), emptyStr);
26+
exception ex8(ctx, make_error_code(errc::invalid), emptyCharPtr);
27+
exception ex9(ctx, make_error_code(errc::memory_allocation));
28+
exception ex10(ctx, static_cast<int>(errc::platform), sycl_category(),
29+
emptyStr);
30+
exception ex11(ctx, static_cast<int>(errc::profiling), sycl_category(),
31+
emptyCharPtr);
32+
exception ex12(ctx, static_cast<int>(errc::feature_not_supported),
33+
sycl_category());
34+
35+
std::vector<exception> v{ex1, ex2, ex3, ex4, ex5, ex6,
36+
ex7, ex8, ex9, ex10, ex11, ex12};
37+
for (int i = 0; i < 12; i++) {
38+
exception ex = v[i];
39+
assert(ex.code().value() == i + 1 &&
40+
"unexpected error_code.value() retrieved");
41+
assert(ex.category() == sycl_category() && "expected SYCL error category");
42+
if (i < 6) {
43+
assert(!ex.has_context() &&
44+
"none of the first six exceptions should have a context");
45+
} else {
46+
assert(ex.has_context() && ex.get_context() == ctx &&
47+
"the second six exceptions should have a context equal to ctx");
48+
}
49+
assert(strlen(ex.what()) == 0 &&
50+
"all these exceptions were initialized with empty strings. We "
51+
"should not have anything in the 'what' message");
52+
}
53+
54+
// Now test constructor with a real string value, including one containing
55+
// null string terminator
56+
std::string testString("this is a test");
57+
exception ex_string1(make_error_code(errc::kernel_not_supported), testString);
58+
assert(testString.compare(ex_string1.what()) == 0);
59+
testString[0] = '\0';
60+
exception ex_early_terminated(make_error_code(errc::kernel_not_supported),
61+
testString);
62+
assert(ex_early_terminated.code().value() ==
63+
static_cast<int>(errc::kernel_not_supported));
64+
char testCharPtr[] = "this is also a test";
65+
exception ex_string2(make_error_code(errc::backend_mismatch), testCharPtr);
66+
assert(strcmp(ex_string2.what(), testCharPtr) == 0);
67+
68+
// Test sycl_category.
69+
assert(std::string("sycl").compare(sycl_category().name()) == 0 &&
70+
"sycl_category name should be 'sycl'");
71+
72+
// Test make_error_code.
73+
std::error_code ec = make_error_code(errc::feature_not_supported);
74+
assert(ec.value() == static_cast<int>(errc::feature_not_supported));
75+
assert(std::string("sycl").compare(ec.category().name()) == 0 &&
76+
"error code category name should be 'sycl'");
77+
78+
// Test enum
79+
static_assert(std::is_error_code_enum<sycl::errc>::value,
80+
"errc enum should identify as error code");
81+
static_assert(!std::is_error_condition_enum<sycl::errc>::value,
82+
"errc enum should not identify as error condition");
83+
84+
// Test errc_for and backends. Should compile without complaint.
85+
constexpr int EC = 1;
86+
sycl::backend_traits<sycl::backend::opencl>::errc someOpenCLErrCode{EC};
87+
sycl::errc_for<sycl::backend::opencl> anotherOpenCLErrCode{EC};
88+
assert(someOpenCLErrCode == anotherOpenCLErrCode);
89+
sycl::backend_traits<sycl::backend::ext_oneapi_level_zero>::errc
90+
someL0ErrCode{EC};
91+
sycl::errc_for<sycl::backend::ext_oneapi_level_zero> anotherL0ErrCode{EC};
92+
assert(someL0ErrCode == anotherL0ErrCode);
93+
sycl::backend_traits<sycl::backend::host>::errc someHOSTErrCode{EC};
94+
sycl::errc_for<sycl::backend::host> anotherHOSTErrCode{EC};
95+
assert(someHOSTErrCode == anotherHOSTErrCode);
96+
sycl::backend_traits<sycl::backend::ext_oneapi_cuda>::errc someCUDAErrCode{
97+
EC};
98+
sycl::errc_for<sycl::backend::ext_oneapi_cuda> anotherCUDAErrCode{EC};
99+
assert(someCUDAErrCode == anotherCUDAErrCode);
100+
sycl::backend_traits<sycl::backend::ext_intel_esimd_emulator>::errc
101+
someESIMDErrCode{EC};
102+
sycl::errc_for<sycl::backend::ext_intel_esimd_emulator> anotherESIMDErrCode{
103+
EC};
104+
assert(someESIMDErrCode == anotherESIMDErrCode);
105+
sycl::backend_traits<sycl::backend::ext_oneapi_hip>::errc someHIPErrCode{EC};
106+
sycl::errc_for<sycl::backend::ext_oneapi_hip> anotherHIPErrCode{EC};
107+
assert(someHIPErrCode == anotherHIPErrCode);
108+
109+
std::cout << "OK" << std::endl;
110+
return 0;
111+
}

SYCL/Basic/library_loading.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// REQUIRES: linux
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: env SYCL_PI_TRACE=-1 %t.out &> %t_trace.txt || true
4+
// RUN: FileCheck --input-file=%t_trace.txt %s
5+
6+
// Checks pi traces on library loading
7+
#include <sycl/sycl.hpp>
8+
9+
using namespace sycl;
10+
11+
int main() {
12+
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_cuda.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_cuda.so)}}
13+
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_hip.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_hip.so)}}
14+
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_esimd_emulator.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_esimd_emulator.so)}}
15+
queue q;
16+
q.submit([&](handler &cgh) {});
17+
}

SYCL/Basic/property_list.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
6+
// This test performs basic check of the SYCL property_list class.
7+
8+
#include <iostream>
9+
#include <sycl/sycl.hpp>
10+
11+
namespace sycl_property = sycl::property;
12+
13+
int main() {
14+
bool Failed = false;
15+
16+
{
17+
sycl::property_list Empty{};
18+
if (Empty.has_property<sycl_property::buffer::use_host_ptr>()) {
19+
std::cerr << "Error: empty property list has property." << std::endl;
20+
Failed = true;
21+
}
22+
}
23+
24+
{
25+
sycl::context SYCLContext;
26+
sycl_property::buffer::context_bound ContextBound(SYCLContext);
27+
28+
sycl::property_list SeveralProps{sycl_property::image::use_host_ptr(),
29+
sycl_property::buffer::use_host_ptr(),
30+
sycl_property::image::use_host_ptr(),
31+
ContextBound};
32+
33+
if (!SeveralProps.has_property<sycl_property::buffer::use_host_ptr>()) {
34+
std::cerr << "Error: property list has no property while should have."
35+
<< std::endl;
36+
Failed = true;
37+
}
38+
39+
if (!SeveralProps.has_property<sycl_property::image::use_host_ptr>()) {
40+
std::cerr << "Error: property list has no property while should have."
41+
<< std::endl;
42+
Failed = true;
43+
}
44+
45+
try {
46+
sycl_property::buffer::context_bound ContextBoundRet =
47+
SeveralProps.get_property<sycl_property::buffer::context_bound>();
48+
if (SYCLContext != ContextBoundRet.get_context()) {
49+
std::cerr << "Error: returned SYCL context is not the same that was "
50+
"passed to c'tor earlier."
51+
<< std::endl;
52+
Failed = true;
53+
}
54+
55+
} catch (sycl::invalid_object_error &Error) {
56+
Error.what();
57+
std::cerr << "Error: exception was thrown in get_property method."
58+
<< std::endl;
59+
Failed = true;
60+
}
61+
}
62+
63+
{
64+
sycl::property_list MemChannelProp{sycl_property::buffer::mem_channel(2)};
65+
if (!MemChannelProp.has_property<sycl_property::buffer::mem_channel>()) {
66+
std::cerr << "Error: property list has no property while should have."
67+
<< std::endl;
68+
Failed = true;
69+
}
70+
auto Prop =
71+
MemChannelProp.get_property<sycl_property::buffer::mem_channel>();
72+
if (Prop.get_channel() != 2) {
73+
std::cerr << "Error: mem_channel property is not equal to 2."
74+
<< std::endl;
75+
Failed = true;
76+
}
77+
}
78+
79+
std::cerr << "Test status : " << (Failed ? "FAILED" : "PASSED") << std::endl;
80+
81+
return Failed;
82+
}

0 commit comments

Comments
 (0)