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

Commit 05821f0

Browse files
authored
[ESIMD] Add regression test for USM 32-element scatter. (#526)
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent edcb434 commit 05821f0

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//==---------- usm_gather_scatter_32.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
9+
// UNSUPPORTED: cuda || hip
10+
// RUN: %clangxx -fsycl -I%S/.. %s -o %t.out
11+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
12+
13+
// Regression test for checking USM-based gather/scatter with 32 elements.
14+
15+
#include "../esimd_test_utils.hpp"
16+
17+
#include <CL/sycl.hpp>
18+
#include <sycl/ext/intel/experimental/esimd.hpp>
19+
20+
#include <iostream>
21+
22+
using namespace cl::sycl;
23+
using namespace sycl::ext::intel::experimental::esimd;
24+
25+
using DataT = std::uint8_t;
26+
27+
int main(void) {
28+
constexpr unsigned Size = 1024;
29+
constexpr unsigned VL = 32;
30+
31+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
32+
33+
auto dev = q.get_device();
34+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
35+
36+
DataT *A = malloc_shared<DataT>(Size, q);
37+
DataT *C = malloc_shared<DataT>(Size, q);
38+
39+
for (unsigned i = 0; i < Size; ++i) {
40+
A[i] = i;
41+
}
42+
43+
auto e = q.submit([&](handler &cgh) {
44+
cgh.parallel_for<class Test>({Size / VL},
45+
[=](item<1> ndi) SYCL_ESIMD_KERNEL {
46+
int i = ndi.get_id(0);
47+
simd<DataT, VL> va;
48+
va.copy_from(A + i * VL);
49+
50+
simd<uint32_t, VL> offsets(0, 1);
51+
scatter<DataT, VL>(C + i * VL, va, offsets);
52+
});
53+
});
54+
e.wait();
55+
56+
std::cout << "Elements should be equal to indices after scatter operation\n";
57+
std::cout << "C[16] C[17] C[18] C[19]:\n";
58+
std::cout << +C[16] << " " << +C[17] << " " << +C[18] << " " << +C[19]
59+
<< "\n";
60+
int err_cnt = 0;
61+
62+
for (int i = 0; i < Size; i++) {
63+
if ((C[i] != (DataT)i) && (++err_cnt < VL)) {
64+
std::cerr << "### ERROR at " << i << ": " << C[i] << " != " << (int)i
65+
<< "(gold)\n";
66+
}
67+
}
68+
sycl::free(A, q);
69+
sycl::free(C, q);
70+
71+
if (err_cnt == 0) {
72+
std::cout << "OK\n";
73+
return 0;
74+
} else {
75+
std::cout << "FAIL\n";
76+
return 1;
77+
}
78+
}

0 commit comments

Comments
 (0)