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

Commit d142785

Browse files
authored
[SYCL][ESIMD] Test lsc template argument type deduction (#1257)
* Test for template argument type deduction
1 parent 68cbeba commit d142785

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//==-------- lsc_argument_type_deduction.cpp - DPC++ ESIMD on-device test --==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
// REQUIRES: gpu-intel-pvc || esimd_emulator
9+
// RUN: %clangxx -fsycl %s -o %t.out
10+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
11+
12+
// The test checks that compiler is able to corrctly deduce the template
13+
// parameter types for lsc functions.
14+
15+
#include "../esimd_test_utils.hpp"
16+
17+
#include <numeric>
18+
#include <sycl/ext/intel/esimd.hpp>
19+
#include <sycl/sycl.hpp>
20+
21+
using namespace sycl;
22+
using namespace sycl::ext::intel::esimd;
23+
using namespace sycl::ext::intel::experimental::esimd;
24+
25+
template <unsigned SIMDSize> int testAccessor(queue q) {
26+
auto size = size_t{128};
27+
28+
auto vec_0 = std::vector<int>(size);
29+
30+
std::iota(vec_0.begin(), vec_0.end(), 0);
31+
auto buf_0 = buffer{vec_0};
32+
33+
try {
34+
q.submit([&](handler &h) {
35+
auto access_0 = buf_0.template get_access<access::mode::read_write>(h);
36+
37+
h.parallel_for(
38+
range<1>{size / SIMDSize}, [=](id<1> id) SYCL_ESIMD_KERNEL {
39+
auto offset = id[0] * SIMDSize * sizeof(int);
40+
auto offsets = simd<uint32_t, SIMDSize>(id * SIMDSize * sizeof(int),
41+
sizeof(int));
42+
auto data_0 = lsc_block_load<int, SIMDSize>(access_0, offset);
43+
lsc_block_store(access_0, offset, data_0 * 2);
44+
});
45+
});
46+
q.wait();
47+
buf_0.template get_access<access::mode::read_write>();
48+
} catch (sycl::exception e) {
49+
std::cout << "SYCL exception caught: " << e.what();
50+
return 1;
51+
}
52+
53+
auto error = 0;
54+
for (auto i = 0; i != size; ++i) {
55+
if (vec_0[i] != 2 * i) {
56+
++error;
57+
std::cout << "out[" << i << "] = 0x" << std::hex << vec_0[i]
58+
<< " vs etalon = 0x" << 2 * i << std::dec << std::endl;
59+
}
60+
}
61+
std::cout << "Accessor lsc argument type deduction test ";
62+
std::cout << (error != 0 ? "FAILED" : "passed") << std::endl;
63+
return error;
64+
}
65+
66+
template <unsigned SIMDSize> int testUSM(queue q) {
67+
auto size = size_t{128};
68+
69+
auto *vec_0 = malloc_shared<int>(size, q);
70+
std::iota(vec_0, vec_0 + size, 0);
71+
72+
try {
73+
q.submit([&](handler &h) {
74+
h.parallel_for(
75+
range<1>{size / SIMDSize}, [=](id<1> id) SYCL_ESIMD_KERNEL {
76+
auto offset = id[0] * SIMDSize;
77+
auto offsets = simd<uint32_t, SIMDSize>(id * SIMDSize * sizeof(int),
78+
sizeof(int));
79+
auto data_0 = lsc_block_load<int, SIMDSize>(vec_0 + offset);
80+
lsc_block_store(vec_0 + offset, data_0 * 2);
81+
});
82+
});
83+
q.wait();
84+
} catch (sycl::exception e) {
85+
std::cout << "SYCL exception caught: " << e.what();
86+
sycl::free(vec_0, q);
87+
return 1;
88+
}
89+
90+
int error = 0;
91+
for (auto i = 0; i != size; ++i) {
92+
if (vec_0[i] != 2 * i) {
93+
++error;
94+
std::cout << "out[" << i << "] = 0x" << std::hex << vec_0[i]
95+
<< " vs etalon = 0x" << 2 * i << std::dec << std::endl;
96+
}
97+
}
98+
sycl::free(vec_0, q);
99+
std::cout << "USM lsc argument type deduction test ";
100+
std::cout << (error != 0 ? "FAILED" : "passed") << std::endl;
101+
return error;
102+
}
103+
104+
int main() {
105+
106+
queue q(esimd_test::ESIMDSelector, esimd_test::createExceptionHandler());
107+
auto device = q.get_device();
108+
std::cout << "Device name: " << device.get_info<info::device::name>()
109+
<< std::endl;
110+
111+
int error = testUSM<8>(q);
112+
error += testUSM<16>(q);
113+
error += testUSM<32>(q);
114+
115+
error += testAccessor<8>(q);
116+
error += testAccessor<16>(q);
117+
error += testAccessor<32>(q);
118+
return error;
119+
}

0 commit comments

Comments
 (0)