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

Commit 95dc2fa

Browse files
[ESIMD] Added regression test for postfix simd_view::operator-- (#281)
1 parent 4ef8af2 commit 95dc2fa

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//==------------- operator_decrement.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+
// This is a test for a bug found simd_view::operator--
9+
//
10+
// REQUIRES: gpu
11+
// UNSUPPORTED: cuda
12+
// RUN: %clangxx -fsycl -I%S/.. %s -o %t.out
13+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
14+
15+
#include "esimd_test_utils.hpp"
16+
17+
#include <CL/sycl.hpp>
18+
#include <CL/sycl/INTEL/esimd.hpp>
19+
#include <iostream>
20+
21+
using namespace cl::sycl;
22+
23+
int main(void) {
24+
constexpr unsigned Size = 1024;
25+
constexpr unsigned VL = 16;
26+
27+
float *A = new float[Size];
28+
29+
for (unsigned i = 0; i < Size; ++i) {
30+
A[i] = i + 1;
31+
}
32+
33+
try {
34+
buffer<float, 1> bufa(A, range<1>(Size));
35+
36+
// We need that many workgroups
37+
cl::sycl::range<1> GlobalRange{Size / VL};
38+
39+
// We need that many threads in each group
40+
cl::sycl::range<1> LocalRange{1};
41+
42+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
43+
44+
auto dev = q.get_device();
45+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
46+
47+
auto e = q.submit([&](handler &cgh) {
48+
auto PA = bufa.get_access<access::mode::read_write>(cgh);
49+
cgh.parallel_for<class Test>(
50+
GlobalRange * LocalRange, [=](id<1> i) SYCL_ESIMD_KERNEL {
51+
using namespace sycl::ext::intel::experimental::esimd;
52+
unsigned int offset = i * VL * sizeof(float);
53+
simd<float, VL> va;
54+
va.copy_from(PA, offset);
55+
auto va_view = va.select<VL, 1>(0);
56+
va_view--;
57+
va.copy_to(PA, offset);
58+
});
59+
});
60+
e.wait();
61+
} catch (cl::sycl::exception const &e) {
62+
std::cout << "SYCL exception caught: " << e.what() << '\n';
63+
64+
delete[] A;
65+
return e.get_cl_code();
66+
}
67+
68+
int err_cnt = 0;
69+
70+
for (unsigned i = 0; i < Size; ++i) {
71+
if (A[i] != i) {
72+
if (++err_cnt < 10) {
73+
std::cout << "failed at index " << i << ", " << A[i] << " != " << i
74+
<< "\n";
75+
}
76+
}
77+
}
78+
if (err_cnt > 0) {
79+
std::cout << " pass rate: "
80+
<< ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% ("
81+
<< (Size - err_cnt) << "/" << Size << ")\n";
82+
}
83+
84+
delete[] A;
85+
86+
std::cout << (err_cnt > 0 ? "FAILED\n" : "Passed\n");
87+
return err_cnt > 0 ? 1 : 0;
88+
}

0 commit comments

Comments
 (0)