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

Commit bd52f31

Browse files
[SYCL] Migrate remaining device-dependent in-tree LIT tests (#1195)
With the removal of the host device a selection of in-tree LIT tests can potentially fail as they rely on a device being available on the system. intel/llvm#6683 removes these tests, but since most are still valid this commit migrates these to the test-suite. Signed-off-by: Larsen, Steffen <steffen.larsen@intel.com>
1 parent 9ca4851 commit bd52f31

File tree

9 files changed

+763
-0
lines changed

9 files changed

+763
-0
lines changed

SYCL/Basic/built-ins.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER
5+
6+
// CUDA does not support printf.
7+
// UNSUPPORTED: cuda
8+
//
9+
// Hits an assertion with AMD:
10+
// XFAIL: hip_amd
11+
12+
#include <sycl/sycl.hpp>
13+
14+
#include <cassert>
15+
16+
namespace s = sycl;
17+
18+
// According to OpenCL C spec, the format string must be in constant address
19+
// space
20+
#ifdef __SYCL_DEVICE_ONLY__
21+
#define CONSTANT __attribute__((opencl_constant))
22+
#else
23+
#define CONSTANT
24+
#endif
25+
26+
static const CONSTANT char format[] = "Hello, World! %d %f\n";
27+
28+
int main() {
29+
s::queue q{};
30+
31+
// Test printf
32+
q.submit([&](s::handler &CGH) {
33+
CGH.single_task<class printf>([=]() {
34+
s::ext::oneapi::experimental::printf(format, 123, 1.23);
35+
// CHECK: {{(Hello, World! 123 1.23)?}}
36+
});
37+
}).wait();
38+
39+
s::ext::oneapi::experimental::printf(format, 321, 3.21);
40+
// CHECK: {{(Hello, World! 123 1.23)?}}
41+
42+
// Test common
43+
{
44+
s::buffer<s::cl_float, 1> BufMin(s::range<1>(1));
45+
s::buffer<s::cl_float2, 1> BufMax(s::range<1>(1));
46+
q.submit([&](s::handler &cgh) {
47+
auto AccMin = BufMin.get_access<s::access::mode::write>(cgh);
48+
auto AccMax = BufMax.get_access<s::access::mode::write>(cgh);
49+
cgh.single_task<class common>([=]() {
50+
AccMax[0] = s::max(s::cl_float2{0.5f, 2.5}, s::cl_float2{2.3f, 2.3});
51+
AccMin[0] = s::min(s::cl_float{0.5f}, s::cl_float{2.3f});
52+
});
53+
});
54+
55+
auto AccMin = BufMin.template get_access<s::access::mode::read>();
56+
auto AccMax = BufMax.template get_access<s::access::mode::read>();
57+
58+
assert(AccMin[0] == 0.5);
59+
assert(AccMax[0].x() == 2.3f && AccMax[0].y() == 2.5f);
60+
assert(s::min(0.5f, 2.3f) == 0.5);
61+
auto Res = s::max(s::int4{5, 2, 1, 5}, s::int4{3, 3, 4, 2});
62+
assert(Res.x() == 5 && Res.y() == 3 && Res.z() == 4 && Res.w() == 5);
63+
}
64+
65+
return 0;
66+
}

SYCL/Basic/context.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 context class.
7+
8+
#include <iostream>
9+
#include <sycl/sycl.hpp>
10+
11+
using namespace sycl;
12+
13+
int main() {
14+
try {
15+
context c;
16+
} catch (device_error e) {
17+
std::cout << "Failed to create device for context" << std::endl;
18+
}
19+
20+
auto devices = device::get_devices();
21+
device &deviceA = devices[0];
22+
device &deviceB = (devices.size() > 1 ? devices[1] : devices[0]);
23+
{
24+
std::cout << "move constructor" << std::endl;
25+
context Context(deviceA);
26+
size_t hash = std::hash<context>()(Context);
27+
context MovedContext(std::move(Context));
28+
assert(hash == std::hash<context>()(MovedContext));
29+
}
30+
{
31+
std::cout << "move assignment operator" << std::endl;
32+
context Context(deviceA);
33+
size_t hash = std::hash<context>()(Context);
34+
context WillMovedContext(deviceB);
35+
WillMovedContext = std::move(Context);
36+
assert(hash == std::hash<context>()(WillMovedContext));
37+
}
38+
{
39+
std::cout << "copy constructor" << std::endl;
40+
context Context(deviceA);
41+
size_t hash = std::hash<context>()(Context);
42+
context ContextCopy(Context);
43+
assert(hash == std::hash<context>()(Context));
44+
assert(hash == std::hash<context>()(ContextCopy));
45+
assert(Context == ContextCopy);
46+
}
47+
{
48+
std::cout << "copy assignment operator" << std::endl;
49+
context Context(deviceA);
50+
size_t hash = std::hash<context>()(Context);
51+
context WillContextCopy(deviceB);
52+
WillContextCopy = Context;
53+
assert(hash == std::hash<context>()(Context));
54+
assert(hash == std::hash<context>()(WillContextCopy));
55+
assert(Context == WillContextCopy);
56+
}
57+
{
58+
auto AsyncHandler = [](const sycl::exception_list &EL) {};
59+
sycl::context Context1(sycl::property_list{});
60+
sycl::context Context2(AsyncHandler, sycl::property_list{});
61+
sycl::context Context3(deviceA, sycl::property_list{});
62+
sycl::context Context4(deviceA, AsyncHandler, sycl::property_list{});
63+
sycl::context Context5(deviceA.get_platform(), sycl::property_list{});
64+
sycl::context Context6(deviceA.get_platform(), AsyncHandler,
65+
sycl::property_list{});
66+
sycl::context Context7(std::vector<sycl::device>{deviceA},
67+
sycl::property_list{});
68+
sycl::context Context8(
69+
std::vector<sycl::device>{deviceA}, AsyncHandler,
70+
sycl::property_list{
71+
sycl::ext::oneapi::cuda::property::context::use_primary_context{}});
72+
73+
if (!Context8.has_property<sycl::ext::oneapi::cuda::property::context::
74+
use_primary_context>()) {
75+
std::cerr << "Line " << __LINE__ << ": Property was not found"
76+
<< std::endl;
77+
return 1;
78+
}
79+
80+
auto Prop = Context8.get_property<
81+
sycl::ext::oneapi::cuda::property::context::use_primary_context>();
82+
}
83+
}

SYCL/Basic/device.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 device class.
7+
8+
#include <cassert>
9+
#include <iostream>
10+
#include <sycl/sycl.hpp>
11+
#include <utility>
12+
13+
using namespace sycl;
14+
15+
std::string get_type(const device &dev) {
16+
if (dev.is_gpu()) {
17+
return "OpenCL.GPU";
18+
} else if (dev.is_accelerator()) {
19+
return "OpenCL.ACC";
20+
} else {
21+
return "OpenCL.CPU";
22+
}
23+
}
24+
25+
int main() {
26+
device d;
27+
std::cout << "Default device type: " << get_type(d) << std::endl;
28+
29+
int i = 1;
30+
std::cout << "Get all devices in the system" << std::endl;
31+
for (const auto &dev : device::get_devices()) {
32+
std::cout << "Device " << i++ << " is available: " << get_type(dev)
33+
<< std::endl;
34+
}
35+
i = 1;
36+
std::cout << "Get host devices in the system" << std::endl;
37+
for (const auto &dev : device::get_devices(info::device_type::host)) {
38+
std::cout << "Device " << i++ << " is available: " << get_type(dev)
39+
<< std::endl;
40+
}
41+
i = 1;
42+
std::cout << "Get OpenCL.CPU devices in the system" << std::endl;
43+
for (const auto &dev : device::get_devices(info::device_type::cpu)) {
44+
std::cout << "Device " << i++ << " is available: " << get_type(dev)
45+
<< std::endl;
46+
}
47+
i = 1;
48+
std::cout << "Get OpenCL.GPU devices in the system" << std::endl;
49+
for (const auto &dev : device::get_devices(info::device_type::gpu)) {
50+
std::cout << "Device " << i++ << " is available: " << get_type(dev)
51+
<< std::endl;
52+
}
53+
i = 1;
54+
std::cout << "Get OpenCL.ACC devices in the system" << std::endl;
55+
for (const auto &dev : device::get_devices(info::device_type::accelerator)) {
56+
std::cout << "Device " << i++ << " is available: " << get_type(dev)
57+
<< std::endl;
58+
}
59+
60+
auto devices = device::get_devices();
61+
device &deviceA = devices[0];
62+
device &deviceB = (devices.size() > 1 ? devices[1] : devices[0]);
63+
{
64+
std::cout << "move constructor" << std::endl;
65+
device Device(deviceA);
66+
size_t hash = std::hash<device>()(Device);
67+
device MovedDevice(std::move(Device));
68+
assert(hash == std::hash<device>()(MovedDevice));
69+
}
70+
{
71+
std::cout << "move assignment operator" << std::endl;
72+
device Device(deviceA);
73+
size_t hash = std::hash<device>()(Device);
74+
device WillMovedDevice(deviceB);
75+
WillMovedDevice = std::move(Device);
76+
assert(hash == std::hash<device>()(WillMovedDevice));
77+
}
78+
{
79+
std::cout << "copy constructor" << std::endl;
80+
device Device(deviceA);
81+
size_t hash = std::hash<device>()(Device);
82+
device DeviceCopy(Device);
83+
assert(hash == std::hash<device>()(Device));
84+
assert(hash == std::hash<device>()(DeviceCopy));
85+
assert(Device == DeviceCopy);
86+
}
87+
{
88+
std::cout << "copy assignment operator" << std::endl;
89+
device Device(deviceA);
90+
size_t hash = std::hash<device>()(Device);
91+
device WillDeviceCopy(deviceB);
92+
WillDeviceCopy = Device;
93+
assert(hash == std::hash<device>()(Device));
94+
assert(hash == std::hash<device>()(WillDeviceCopy));
95+
assert(Device == WillDeviceCopy);
96+
}
97+
}

SYCL/Basic/event_async_exception.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
//==---- event_async_exception.cpp - Test for event async exceptions -------==//
7+
//
8+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9+
// See https://llvm.org/LICENSE.txt for license information.
10+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include <sycl/sycl.hpp>
15+
16+
// This test checks that if there is a submit failure, the asynchronous
17+
// exception is associated with the returned event.
18+
19+
using namespace sycl;
20+
21+
class KernelName;
22+
23+
int main() {
24+
auto asyncHandler = [](exception_list el) {
25+
for (auto &e : el) {
26+
std::rethrow_exception(e);
27+
}
28+
};
29+
30+
queue q(asyncHandler);
31+
32+
try {
33+
// Check that submitting a CG with no kernel or memory operation doesn't
34+
// produce an async exception
35+
event e = q.submit([&](handler &cgh) {});
36+
37+
e.wait_and_throw();
38+
return 0;
39+
} catch (runtime_error e) {
40+
return 1;
41+
}
42+
}

0 commit comments

Comments
 (0)