Skip to content

Commit 1504a07

Browse files
authored
[SYCL] Move device tests from intel/llvm (intel#81)
* add device tests from intel/llvm * disable tests which use clang command line format when clang-cl is used * increase individual test timeout to 600 sec
1 parent def3d48 commit 1504a07

File tree

4 files changed

+214
-1
lines changed

4 files changed

+214
-1
lines changed

SYCL/Basic/diagnostics/handler.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %BE_RUN_PLACEHOLDER %t.out | FileCheck %s
3+
//==------------------- handler.cpp ----------------------------------------==//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include <CL/sycl.hpp>
11+
#include <cassert>
12+
13+
using namespace cl;
14+
15+
int main() {
16+
17+
sycl::queue Queue([](sycl::exception_list ExceptionList) {
18+
if (ExceptionList.size() != 1) {
19+
std::cerr << "Should be one exception in exception list" << std::endl;
20+
std::abort();
21+
}
22+
std::rethrow_exception(*ExceptionList.begin());
23+
});
24+
25+
try {
26+
Queue.submit([&](sycl::handler &CGH) {
27+
CGH.single_task<class Dummy1>([]() {});
28+
CGH.single_task<class Dummy2>([]() {});
29+
});
30+
Queue.throw_asynchronous();
31+
assert(!"Expected exception not caught");
32+
} catch (sycl::exception &ExpectedException) {
33+
// CHECK: Attempt to set multiple actions for the command group
34+
std::cout << ExpectedException.what() << std::endl;
35+
}
36+
}
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: %GPU_RUN_PLACEHOLDER %t.out
3+
// XFAIL: opencl
4+
// REQUIRES: level_zero
5+
//==------- non-uniform-wk-gp-test.cpp -------==//
6+
// This is a diagnostic test which verifies that
7+
// for loops with non-uniform work groups size
8+
// errors are handled correctly.
9+
//==------------------------------------------==//
10+
11+
#include <CL/sycl.hpp>
12+
#include <iostream>
13+
14+
using namespace cl::sycl;
15+
16+
int test() {
17+
try {
18+
queue q = queue();
19+
auto device = q.get_device();
20+
auto deviceName = device.get_info<cl::sycl::info::device::name>();
21+
std::cout << " Device Name: " << deviceName << std::endl;
22+
23+
const int N = 1;
24+
q.submit([&](handler &cgh) {
25+
cl::sycl::stream kernelout(108 * 64 + 128, 64, cgh);
26+
cgh.parallel_for<class test_kernel>(
27+
nd_range<3>(range<3>{1, 1, N}, range<3>{1, 1, 16}),
28+
[=](nd_item<3> itm) {
29+
kernelout << "Coordinates: " << itm.get_global_id()
30+
<< cl::sycl::endl;
31+
});
32+
});
33+
34+
} catch (sycl::runtime_error &E) {
35+
if (std::string(E.what()).find(
36+
"Specified local size doesn't match the required work-group size "
37+
"specified in the program source") != std::string::npos) {
38+
std::cout << E.what() << std::endl;
39+
std::cout << "Test passed: caught the expected error." << std::endl;
40+
return 0;
41+
} else {
42+
std::cout << E.what() << std::endl;
43+
std::cout << "Test failed: received error is incorrect." << std::endl;
44+
return 1;
45+
}
46+
}
47+
48+
std::cout << "Test passed: results are correct." << std::endl;
49+
return 0;
50+
}
51+
52+
int main() {
53+
54+
int pltCount = 0, ret;
55+
for (const auto &plt : platform::get_platforms()) {
56+
if (!plt.has(aspect::host)) {
57+
std::cout << "Platform #" << pltCount++ << ":" << std::endl;
58+
if (plt.get_backend() == backend::level_zero) {
59+
std::cout << "Backend: Level Zero" << std::endl;
60+
ret = test();
61+
}
62+
}
63+
std::cout << std::endl;
64+
}
65+
return 0;
66+
}

SYCL/Basic/image/image.cpp

+111
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: %HOST_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
6+
//==------------------- image.cpp - SYCL image basic test -----------------==//
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 <CL/sycl.hpp>
15+
16+
#include <iostream>
17+
#include <vector>
18+
19+
#include "../../helpers.hpp"
20+
21+
using namespace cl;
22+
23+
int main() {
24+
const sycl::image_channel_order ChanOrder = sycl::image_channel_order::rgba;
25+
const sycl::image_channel_type ChanType = sycl::image_channel_type::fp32;
26+
27+
constexpr auto SYCLRead = sycl::access::mode::read;
28+
constexpr auto SYCLWrite = sycl::access::mode::write;
29+
30+
const sycl::range<2> Img1Size(4, 4);
31+
const sycl::range<2> Img2Size(4, 4);
32+
33+
std::vector<sycl::float4> Img1HostData(Img1Size.size(), {1, 2, 3, 4});
34+
std::vector<sycl::float4> Img2HostData(Img2Size.size(), {0, 0, 0, 0});
35+
36+
{
37+
sycl::image<2> Img1(Img1HostData.data(), ChanOrder, ChanType, Img1Size);
38+
sycl::image<2> Img2(Img2HostData.data(), ChanOrder, ChanType, Img2Size);
39+
TestQueue Q{sycl::default_selector()};
40+
Q.submit([&](sycl::handler &CGH) {
41+
auto Img1Acc = Img1.get_access<sycl::float4, SYCLRead>(CGH);
42+
auto Img2Acc = Img2.get_access<sycl::float4, SYCLWrite>(CGH);
43+
44+
CGH.parallel_for<class ImgCopy>(Img1Size, [=](sycl::item<2> Item) {
45+
sycl::float4 Data = Img1Acc.read(sycl::int2{Item[0], Item[1]});
46+
Img2Acc.write(sycl::int2{Item[0], Item[1]}, Data);
47+
});
48+
});
49+
}
50+
51+
for (int X = 0; X < Img2Size[0]; ++X)
52+
for (int Y = 0; Y < Img2Size[1]; ++Y) {
53+
sycl::float4 Vec1 = Img1HostData[X * Img1Size[1] + Y];
54+
sycl::float4 Vec2 = Img2HostData[X * Img2Size[1] + Y];
55+
56+
if (sycl::any(sycl::isnotequal(Vec1, Vec2))) {
57+
std::cerr << "Failed" << std::endl;
58+
std::cerr << "Element [ " << X << ", " << Y << " ]" << std::endl;
59+
std::cerr << "Expected: " << printableVec(Vec1) << std::endl;
60+
std::cerr << " Got : " << printableVec(Vec2) << std::endl;
61+
return 1;
62+
}
63+
}
64+
65+
{
66+
const sycl::range<1> ImgPitch(4 * 4 * 4 * 2);
67+
sycl::image<2> Img(ChanOrder, ChanType, Img1Size, ImgPitch);
68+
TestQueue Q{sycl::default_selector()};
69+
Q.submit([&](sycl::handler &CGH) {
70+
auto ImgAcc = Img.get_access<sycl::float4, SYCLRead>(CGH);
71+
CGH.single_task<class EmptyKernel>([=]() { ImgAcc.get_range(); });
72+
});
73+
}
74+
75+
{
76+
const sycl::range<1> ImgPitch(4 * 4 * 4 * 2);
77+
sycl::image<2> Img(Img1HostData.data(), ChanOrder, ChanType, Img1Size,
78+
ImgPitch);
79+
TestQueue Q{sycl::default_selector()};
80+
Q.submit([&](sycl::handler &CGH) {
81+
auto ImgAcc = Img.get_access<sycl::float4, SYCLRead>(CGH);
82+
CGH.single_task<class ConstTestPitch>([=] { ImgAcc.get_range(); });
83+
});
84+
}
85+
86+
// image with write accessor to it in kernel
87+
{
88+
int NX = 32;
89+
int NY = 32;
90+
91+
sycl::image<2> Img(sycl::image_channel_order::rgba,
92+
sycl::image_channel_type::fp32, sycl::range<2>(NX, NY));
93+
94+
sycl::queue Q;
95+
Q.submit([&](sycl::handler &CGH) {
96+
auto ImgAcc =
97+
Img.get_access<sycl::float4, sycl::access::mode::write>(CGH);
98+
99+
sycl::nd_range<2> Rng(sycl::range<2>(NX, NY), sycl::range<2>(16, 16));
100+
101+
CGH.parallel_for<class sample>(Rng, [=](sycl::nd_item<2> Item) {
102+
sycl::id<2> Idx = Item.get_global_id();
103+
sycl::float4 C(0.5f, 0.5f, 0.2f, 1.0f);
104+
ImgAcc.write(sycl::int2(Idx[0], Idx[1]), C);
105+
});
106+
}).wait_and_throw();
107+
}
108+
109+
std::cout << "Success" << std::endl;
110+
return 0;
111+
}

SYCL/lit.cfg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,6 @@
262262
# Set timeout for test 1 min
263263
try:
264264
import psutil
265-
lit_config.maxIndividualTestTime = 60
265+
lit_config.maxIndividualTestTime = 600
266266
except ImportError:
267267
pass

0 commit comments

Comments
 (0)