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

Commit 5bf349c

Browse files
[ESIMD] Add E2E test for simd::replicate_w bug (#373)
1 parent d38f306 commit 5bf349c

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//==--------------- replicate_bug.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
10+
// RUN: %clangxx -fsycl %s -o %t.out
11+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
12+
//
13+
// This is a regression test for a bug in simd::replicate_w interface:
14+
// call v.replicate_w<VL, 1>(1) should broadcast second element of v VL times.
15+
16+
#include "../esimd_test_utils.hpp"
17+
18+
#include <CL/sycl.hpp>
19+
#include <CL/sycl/INTEL/esimd.hpp>
20+
#include <iostream>
21+
22+
using namespace cl::sycl;
23+
constexpr int VL = 8;
24+
25+
template <int Width> bool test(queue q, const std::vector<int> &gold) {
26+
std::cout << "Testing Width=" << Width << " ...\n";
27+
auto dev = q.get_device();
28+
auto ctxt = q.get_context();
29+
int *A =
30+
static_cast<int *>(malloc_shared(VL * Width * sizeof(int), dev, ctxt));
31+
int *B =
32+
static_cast<int *>(malloc_shared(VL * Width * sizeof(int), dev, ctxt));
33+
34+
for (int i = 0; i < VL * Width; ++i) {
35+
A[i] = i;
36+
B[i] = -i;
37+
}
38+
39+
try {
40+
range<1> glob_range{1};
41+
auto e = q.submit([&](handler &cgh) {
42+
cgh.parallel_for(glob_range, [=](id<1> i) SYCL_ESIMD_KERNEL {
43+
using namespace sycl::ext::intel::experimental::esimd;
44+
simd<int, VL> va;
45+
va.copy_from(A);
46+
// FIXME: it should be similar to replicate_vs_w_hs<VL, 0, 1, 1>(1);
47+
simd<int, VL *Width> vb = va.replicate_w<VL, Width>(1);
48+
vb.copy_to(B);
49+
});
50+
});
51+
e.wait();
52+
} catch (cl::sycl::exception const &e) {
53+
std::cout << "SYCL exception caught: " << e.what() << '\n';
54+
free(A, ctxt);
55+
free(B, ctxt);
56+
return e.get_cl_code();
57+
}
58+
59+
int err_cnt = 0;
60+
for (unsigned i = 0; i < VL * Width; ++i) {
61+
if (B[i] != gold[i]) {
62+
err_cnt++;
63+
std::cout << "failed at index " << i << ": " << B[i] << " != " << gold[i]
64+
<< " (gold)\n";
65+
}
66+
}
67+
68+
if (err_cnt > 0) {
69+
std::cout << " pass rate: "
70+
<< ((float)(VL * Width - err_cnt) / (float)VL * Width) * 100.0f
71+
<< "% (" << (VL * Width - err_cnt) << "/" << VL << ")\n";
72+
}
73+
74+
free(A, ctxt);
75+
free(B, ctxt);
76+
77+
std::cout << (err_cnt > 0 ? " FAILED\n" : " Passed\n");
78+
return err_cnt > 0 ? false : true;
79+
}
80+
81+
int main(void) {
82+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
83+
auto dev = q.get_device();
84+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
85+
86+
bool passed = true;
87+
// FIXME: remove #else once fix is available
88+
#ifdef CORRECT_BEHAVIOR
89+
passed &= test<1>(q, {1, 1, 1, 1, 1, 1, 1, 1});
90+
passed &= test<2>(q, {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2});
91+
#else
92+
passed &= test<1>(q, {1, 2, 3, 4, 5, 6, 7, 0});
93+
passed &= test<2>(q, {1, 2, 3, 4, 5, 6, 7, 0, 2, 3, 4, 5, 6, 7, 0, 0});
94+
#endif
95+
96+
return passed ? 0 : 1;
97+
}

0 commit comments

Comments
 (0)