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

Commit 4219664

Browse files
authored
[SYCL] Moved tests introduced in intel/llvm#3255 (#181)
* [SYCL] Moved tests introduced in intel/llvm#3255 * [SYCL] Fix issues found in CI - fix target tripple used by default to spir64-unknown-unknown-sycldevice; - remove obsolet LIT parameters (target_triple, host_triple); - enable tests for CPU and ACC devices.
1 parent 3530fb2 commit 4219664

File tree

4 files changed

+141
-3
lines changed

4 files changed

+141
-3
lines changed

SYCL/SubGroup/sub_group_as.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// Sub-groups are not suported on Host
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
#include <CL/sycl.hpp>
8+
#include <cassert>
9+
#include <cstdint>
10+
#include <cstdio>
11+
#include <cstdlib>
12+
13+
int main(int argc, char *argv[]) {
14+
cl::sycl::queue queue;
15+
printf("Device Name = %s\n",
16+
queue.get_device().get_info<cl::sycl::info::device::name>().c_str());
17+
18+
// Initialize some host memory
19+
constexpr int N = 64;
20+
int host_mem[N];
21+
for (int i = 0; i < N; ++i) {
22+
host_mem[i] = i * 100;
23+
}
24+
25+
// Use the device to transform each value
26+
{
27+
cl::sycl::buffer<int, 1> buf(host_mem, N);
28+
queue.submit([&](cl::sycl::handler &cgh) {
29+
auto global =
30+
buf.get_access<cl::sycl::access::mode::read_write,
31+
cl::sycl::access::target::global_buffer>(cgh);
32+
sycl::accessor<int, 1, sycl::access::mode::read_write,
33+
sycl::access::target::local>
34+
local(N, cgh);
35+
36+
cgh.parallel_for<class test>(
37+
cl::sycl::nd_range<1>(N, 32), [=](cl::sycl::nd_item<1> it) {
38+
cl::sycl::ONEAPI::sub_group sg = it.get_sub_group();
39+
if (!it.get_local_id(0)) {
40+
int end = it.get_global_id(0) + it.get_local_range()[0];
41+
for (int i = it.get_global_id(0); i < end; i++) {
42+
local[i] = i;
43+
}
44+
}
45+
it.barrier();
46+
47+
int i = (it.get_global_id(0) / sg.get_max_local_range()[0]) *
48+
sg.get_max_local_range()[0];
49+
// Global address space
50+
auto x = sg.load(&global[i]);
51+
52+
// Local address space
53+
auto y = sg.load(&local[i]);
54+
55+
sg.store(&global[i], x + y);
56+
});
57+
});
58+
}
59+
60+
// Print results and tidy up
61+
for (int i = 0; i < N; ++i) {
62+
if (i * 101 != host_mem[i]) {
63+
printf("Unexpected result %04d vs %04d\n", i * 101, host_mem[i]);
64+
return 1;
65+
}
66+
}
67+
printf("Success!\n");
68+
return 0;
69+
}

SYCL/SubGroup/sub_group_as_vec.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// Sub-groups are not suported on Host
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
#include <CL/sycl.hpp>
8+
#include <cassert>
9+
#include <cstdint>
10+
#include <cstdio>
11+
#include <cstdlib>
12+
13+
int main(int argc, char *argv[]) {
14+
cl::sycl::queue queue;
15+
printf("Device Name = %s\n",
16+
queue.get_device().get_info<cl::sycl::info::device::name>().c_str());
17+
18+
// Initialize some host memory
19+
constexpr int N = 64;
20+
sycl::vec<int, 2> host_mem[N];
21+
for (int i = 0; i < N; ++i) {
22+
host_mem[i].s0() = i;
23+
host_mem[i].s1() = 0;
24+
}
25+
26+
// Use the device to transform each value
27+
{
28+
cl::sycl::buffer<sycl::vec<int, 2>, 1> buf(host_mem, N);
29+
queue.submit([&](cl::sycl::handler &cgh) {
30+
auto global =
31+
buf.get_access<cl::sycl::access::mode::read_write,
32+
cl::sycl::access::target::global_buffer>(cgh);
33+
sycl::accessor<sycl::vec<int, 2>, 1, sycl::access::mode::read_write,
34+
sycl::access::target::local>
35+
local(N, cgh);
36+
cgh.parallel_for<class test>(
37+
cl::sycl::nd_range<1>(N, 32), [=](cl::sycl::nd_item<1> it) {
38+
cl::sycl::ONEAPI::sub_group sg = it.get_sub_group();
39+
if (!it.get_local_id(0)) {
40+
int end = it.get_global_id(0) + it.get_local_range()[0];
41+
for (int i = it.get_global_id(0); i < end; i++) {
42+
local[i].s0() = 0;
43+
local[i].s1() = i;
44+
}
45+
}
46+
it.barrier();
47+
48+
int i = (it.get_global_id(0) / sg.get_max_local_range()[0]) *
49+
sg.get_max_local_range()[0];
50+
// Global address space
51+
auto x = sg.load(&global[i]);
52+
53+
// Local address space
54+
auto y = sg.load(&local[i]);
55+
56+
sg.store(&global[i], x + y);
57+
});
58+
});
59+
}
60+
61+
// Print results and tidy up
62+
for (int i = 0; i < N; ++i) {
63+
if (i != host_mem[i].s0() || i != host_mem[i].s1()) {
64+
printf("Unexpected result [%02d,%02d] vs [%02d,%02d]\n", i, i,
65+
host_mem[i].s0(), host_mem[i].s1());
66+
return 1;
67+
}
68+
}
69+
printf("Success!\n");
70+
return 0;
71+
}

SYCL/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@
280280
if config.sycl_be == 'cuda':
281281
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
282282
else:
283-
config.substitutions.append( ('%sycl_triple', "spir64-unknown-linux-sycldevice" ) )
283+
config.substitutions.append( ('%sycl_triple', "spir64-unknown-unknown-sycldevice" ) )
284284

285285
if find_executable('sycl-ls'):
286286
config.available_features.add('sycl-ls')

SYCL/lit.site.cfg.py.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ config.sycl_tools_dir = config.llvm_tools_dir
1414
config.sycl_include = os.path.join(config.dpcpp_root_dir, 'include', 'sycl')
1515
config.sycl_obj_root = "@CMAKE_CURRENT_BINARY_DIR@"
1616
config.sycl_libs_dir = os.path.join(config.dpcpp_root_dir, ('bin' if platform.system() == "Windows" else 'lib'))
17-
config.target_triple = "x86_64-unknown-unknown-gnu"
18-
config.host_triple = "x86_64-unknown-unknown-gnu"
1917

2018
config.opencl_libs_dir = (os.path.dirname("@OpenCL_LIBRARY@") if "@OpenCL_LIBRARY@" else "")
2119
config.level_zero_libs_dir = "@LEVEL_ZERO_LIBS_DIR@"

0 commit comments

Comments
 (0)