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

Commit 6906a71

Browse files
committed
[SYCL] Move device tests from intel/llvm
1 parent ce23b34 commit 6906a71

File tree

144 files changed

+17707
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+17707
-4
lines changed

SYCL/Basic/access_to_subset.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: %HOST_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
//==---------- access_to_subset.cpp --- access to subset of buffer test ----==//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
#include <CL/sycl.hpp>
15+
16+
using namespace cl::sycl;
17+
using acc_w =
18+
accessor<int, 2, access::mode::write, access::target::global_buffer>;
19+
20+
int main() {
21+
22+
const int M = 6;
23+
const int N = 7;
24+
int result[M][N] = {0};
25+
bool failed = false;
26+
{
27+
auto origRange = range<2>(M, N);
28+
buffer<int, 2> Buffer(origRange);
29+
Buffer.set_final_data((int *)result);
30+
auto offset = id<2>(1, 1);
31+
auto subRange = range<2>(M - 2, N - 2);
32+
queue myQueue;
33+
myQueue.submit([&](handler &cgh) {
34+
acc_w B(Buffer, cgh);
35+
cgh.parallel_for<class bufferByRange2_init>(
36+
origRange, [=](id<2> index) { B[index] = 0; });
37+
});
38+
myQueue.submit([&](handler &cgh) {
39+
acc_w B(Buffer, cgh, subRange, offset);
40+
cgh.parallel_for<class bufferByRange2>(
41+
subRange, [=](id<2> index) { B[index] = 1; });
42+
});
43+
}
44+
45+
// Check that we filled correct subset of buffer:
46+
// 0000000 0000000
47+
// 0000000 0111110
48+
// 0000000 --> 0111110
49+
// 0000000 0111110
50+
// 0000000 0111110
51+
// 0000000 0000000
52+
53+
for (size_t i = 0; i < M; ++i) {
54+
for (size_t j = 0; j < N; ++j) {
55+
size_t expected =
56+
((i == 0) || (i == M - 1) || (j == 0) || (j == N - 1)) ? 0 : 1;
57+
if (result[i][j] != expected) {
58+
std::cout << "line: " << __LINE__ << " result[" << i << "][" << j
59+
<< "] is " << result[i][j] << " expected " << expected
60+
<< std::endl;
61+
failed = true;
62+
}
63+
}
64+
}
65+
return failed;
66+
}

SYCL/Basic/boolean.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// TODO: Enable compilation w/o -fno-sycl-early-optimizations option.
2+
// See https://github.com/intel/llvm/issues/2264 for more details.
3+
// XFAIL: gpu && (level_zero || opencl)
4+
5+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
6+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
7+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
8+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
9+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
10+
#include <CL/sycl.hpp>
11+
12+
#include <cassert>
13+
14+
using namespace cl::sycl;
15+
namespace s = cl::sycl;
16+
namespace d = s::detail;
17+
18+
d::Boolean<3> foo() {
19+
d::Boolean<3> b3{true, false, true};
20+
return b3;
21+
}
22+
23+
int main() {
24+
{
25+
s::cl_long4 r{0};
26+
{
27+
buffer<s::cl_long4, 1> BufR(&r, range<1>(1));
28+
queue myQueue;
29+
myQueue.submit([&](handler &cgh) {
30+
auto AccR = BufR.get_access<access::mode::write>(cgh);
31+
cgh.single_task<class b4_l4>([=]() {
32+
d::Boolean<4> b4{false, true, false, false};
33+
AccR[0] = b4;
34+
});
35+
});
36+
}
37+
s::cl_long r1 = r.s0();
38+
s::cl_long r2 = r.s1();
39+
s::cl_long r3 = r.s2();
40+
s::cl_long r4 = r.s3();
41+
42+
std::cout << "r1 " << r1 << " r2 " << r2 << " r3 " << r3 << " r4 " << r4
43+
<< std::endl;
44+
45+
assert(r1 == 0);
46+
assert(r2 == -1);
47+
assert(r3 == 0);
48+
assert(r4 == 0);
49+
}
50+
51+
{
52+
s::cl_short3 r{0};
53+
{
54+
buffer<s::cl_short3, 1> BufR(&r, range<1>(1));
55+
queue myQueue;
56+
myQueue.submit([&](handler &cgh) {
57+
auto AccR = BufR.get_access<access::mode::write>(cgh);
58+
cgh.single_task<class b3_sh3>([=]() { AccR[0] = foo(); });
59+
});
60+
}
61+
s::cl_short r1 = r.s0();
62+
s::cl_short r2 = r.s1();
63+
s::cl_short r3 = r.s2();
64+
65+
std::cout << "r1 " << r1 << " r2 " << r2 << " r3 " << r3 << std::endl;
66+
67+
assert(r1 == -1);
68+
assert(r2 == 0);
69+
assert(r3 == -1);
70+
}
71+
72+
{
73+
s::cl_int r1[6];
74+
s::cl_int r2[6];
75+
{
76+
buffer<s::cl_int, 1> BufR1(r1, range<1>(6));
77+
buffer<s::cl_int, 1> BufR2(r2, range<1>(6));
78+
queue myQueue;
79+
myQueue.submit([&](handler &cgh) {
80+
auto AccR1 = BufR1.get_access<access::mode::write>(cgh);
81+
auto AccR2 = BufR2.get_access<access::mode::write>(cgh);
82+
cgh.single_task<class size_align>([=]() {
83+
AccR1[0] = sizeof(d::Boolean<1>);
84+
AccR1[1] = sizeof(d::Boolean<2>);
85+
AccR1[2] = sizeof(d::Boolean<3>);
86+
AccR1[3] = sizeof(d::Boolean<4>);
87+
AccR1[4] = sizeof(d::Boolean<8>);
88+
AccR1[5] = sizeof(d::Boolean<16>);
89+
90+
AccR2[0] = alignof(d::Boolean<1>);
91+
AccR2[1] = alignof(d::Boolean<2>);
92+
AccR2[2] = alignof(d::Boolean<3>);
93+
AccR2[3] = alignof(d::Boolean<4>);
94+
AccR2[4] = alignof(d::Boolean<8>);
95+
AccR2[5] = alignof(d::Boolean<16>);
96+
});
97+
});
98+
}
99+
100+
for (size_t I = 0; I < 6; I++) {
101+
std::cout << " r1[" << I << "] " << r1[I];
102+
}
103+
std::cout << std::endl;
104+
105+
for (size_t I = 0; I < 6; I++) {
106+
std::cout << " r2[" << I << "] " << r2[I];
107+
}
108+
std::cout << std::endl;
109+
assert(r1[0] == sizeof(d::Boolean<1>));
110+
assert(r1[1] == sizeof(d::Boolean<2>));
111+
assert(r1[2] == sizeof(d::Boolean<3>));
112+
assert(r1[3] == sizeof(d::Boolean<4>));
113+
assert(r1[4] == sizeof(d::Boolean<8>));
114+
assert(r1[5] == sizeof(d::Boolean<16>));
115+
116+
assert(r2[0] == alignof(d::Boolean<1>));
117+
assert(r2[1] == alignof(d::Boolean<2>));
118+
assert(r2[2] == alignof(d::Boolean<3>));
119+
assert(r2[3] == alignof(d::Boolean<4>));
120+
assert(r2[4] == alignof(d::Boolean<8>));
121+
assert(r2[5] == alignof(d::Boolean<16>));
122+
}
123+
124+
{
125+
s::cl_int4 i4 = {1, -2, 0, -3};
126+
d::Boolean<4> b4(i4);
127+
i4 = b4;
128+
129+
s::cl_int r1 = i4.s0();
130+
s::cl_int r2 = i4.s1();
131+
s::cl_int r3 = i4.s2();
132+
s::cl_int r4 = i4.s3();
133+
134+
std::cout << "r1 " << r1 << " r2 " << r2 << " r3 " << r3 << " r4 " << r4
135+
<< std::endl;
136+
assert(r1 == 0);
137+
assert(r2 == -1);
138+
assert(r3 == 0);
139+
assert(r4 == -1);
140+
}
141+
142+
{
143+
s::cl_int r1 = d::Boolean<1>(s::cl_int{-1});
144+
s::cl_int r2 = d::Boolean<1>(s::cl_int{0});
145+
s::cl_int r3 = d::Boolean<1>(s::cl_int{1});
146+
std::cout << "r1 " << r1 << " r2 " << r2 << " r3 " << r3 << std::endl;
147+
assert(r1 == 1);
148+
assert(r2 == 0);
149+
assert(r3 == 1);
150+
}
151+
152+
return 0;
153+
}

0 commit comments

Comments
 (0)