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

Commit 6bb47ee

Browse files
authored
[SYCL][ESIMD] Add regression test for SVM gather/scatter API (#566)
Signed-off-by: Sergey Dmitriev <[email protected]>
1 parent 63cb748 commit 6bb47ee

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

SYCL/ESIMD/api/svm_gather_scatter.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//==---- svm_gather_scatter.cpp - DPC++ ESIMD svm gather/scatter 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 %s -o %t.out
11+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
12+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
13+
14+
// Regression test for SVM gather/scatter API.
15+
16+
#include "../esimd_test_utils.hpp"
17+
18+
#include <CL/sycl.hpp>
19+
#include <CL/sycl/builtins_esimd.hpp>
20+
#include <algorithm>
21+
#include <array>
22+
#include <iostream>
23+
24+
#include <sycl/ext/intel/experimental/esimd.hpp>
25+
26+
using namespace cl::sycl;
27+
using namespace sycl::ext::intel::experimental;
28+
using namespace sycl::ext::intel::experimental::esimd;
29+
30+
template <typename T, int N> bool test(queue &Q) {
31+
std::cout << " Running " << typeid(T).name() << " test, N=" << N << "...\n";
32+
33+
struct Deleter {
34+
queue Q;
35+
void operator()(T *Ptr) {
36+
if (Ptr) {
37+
sycl::free(Ptr, Q);
38+
}
39+
}
40+
};
41+
42+
std::unique_ptr<T, Deleter> Ptr1(sycl::malloc_shared<T>(N, Q), Deleter{Q});
43+
std::unique_ptr<T, Deleter> Ptr2(sycl::malloc_shared<T>(N, Q), Deleter{Q});
44+
45+
T *Src = Ptr1.get();
46+
T *Dst = Ptr2.get();
47+
48+
for (int I = 0; I < N; ++I) {
49+
Src[I] = I + 1;
50+
Dst[I] = 0;
51+
}
52+
53+
try {
54+
Q.submit([&](handler &CGH) {
55+
CGH.parallel_for(sycl::range<1>{1}, [=](id<1>) SYCL_ESIMD_KERNEL {
56+
simd<uint32_t, N> Offsets(0u, sizeof(T));
57+
scatter<T, N>(Dst, Offsets, gather<T, N>(Src, Offsets));
58+
});
59+
}).wait();
60+
} catch (cl::sycl::exception const &E) {
61+
std::cout << "ERROR. SYCL exception caught: " << E.what() << std::endl;
62+
return false;
63+
}
64+
65+
unsigned NumErrs = 0;
66+
for (int I = 0; I < N; ++I)
67+
if (Dst[I] != Src[I])
68+
if (++NumErrs <= 10)
69+
std::cout << "failed at " << I << ": " << Dst[I]
70+
<< " (Dst) != " << Src[I] << " (Src)\n";
71+
72+
std::cout << (NumErrs == 0 ? " Passed\n" : " FAILED\n");
73+
return NumErrs == 0;
74+
}
75+
76+
int main(void) {
77+
queue Q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
78+
auto Dev = Q.get_device();
79+
std::cout << "Running on " << Dev.get_info<info::device::name>() << "\n";
80+
81+
bool Pass = true;
82+
83+
Pass &= test<int8_t, 8>(Q);
84+
Pass &= test<int8_t, 16>(Q);
85+
Pass &= test<int8_t, 32>(Q);
86+
87+
Pass &= test<int16_t, 8>(Q);
88+
Pass &= test<int16_t, 16>(Q);
89+
Pass &= test<int16_t, 32>(Q);
90+
91+
Pass &= test<int32_t, 8>(Q);
92+
Pass &= test<int32_t, 16>(Q);
93+
Pass &= test<int32_t, 32>(Q);
94+
95+
std::cout << (Pass ? "Test Passed\n" : "Test FAILED\n");
96+
return Pass ? 0 : 1;
97+
}

0 commit comments

Comments
 (0)