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

Commit ff1fc58

Browse files
authored
[SYCL] Add ESIMD regression test for big const initializer list. (#91)
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent eea4405 commit ff1fc58

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//==---------- big_const_initializer.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+
// TODO enable on Windows
9+
// REQUIRES: linux && gpu
10+
// UNSUPPORTED: cuda
11+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
12+
// RUN: %ESIMD_RUN_PLACEHOLDER %t.out
13+
14+
// This test checks that ESIMD program with big constant initializer list can
15+
// compile and run correctly.
16+
17+
#include "esimd_test_utils.hpp"
18+
19+
#include <CL/sycl.hpp>
20+
#include <CL/sycl/INTEL/esimd.hpp>
21+
22+
#include <iostream>
23+
24+
#define SIMD_WIDTH 16
25+
26+
#define N_SAMPLES (SIMD_WIDTH * 100)
27+
#define N_PRINT 20
28+
29+
#define VAL1 0x9E3779B9
30+
#define VAL2 0xBB67AE85
31+
32+
inline void foo(sycl::INTEL::gpu::simd<std::uint32_t, 16> &k) {
33+
sycl::INTEL::gpu::simd<std::uint32_t, 16> k_add = {
34+
VAL1, VAL2, VAL1, VAL2, VAL1, VAL2, VAL1, VAL2,
35+
VAL1, VAL2, VAL1, VAL2, VAL1, VAL2, VAL1, VAL2};
36+
k += k_add;
37+
}
38+
39+
int main(int argc, char **argv) {
40+
size_t nsamples = N_SAMPLES;
41+
sycl::queue queue(esimd_test::ESIMDSelector{},
42+
esimd_test::createExceptionHandler());
43+
44+
std::cout << "Running on "
45+
<< queue.get_device().get_info<sycl::info::device::name>()
46+
<< std::endl;
47+
std::cout << "Driver version "
48+
<< queue.get_device().get_info<sycl::info::device::driver_version>()
49+
<< std::endl;
50+
51+
sycl::buffer<std::uint32_t, 1> r(sycl::range<1>{nsamples});
52+
53+
try {
54+
queue.submit([&](sycl::handler &cgh) {
55+
auto r_acc = r.template get_access<sycl::access::mode::write>(cgh);
56+
cgh.parallel_for<class Test>(
57+
sycl::range<1>{nsamples / SIMD_WIDTH},
58+
[=](sycl::item<1> item) SYCL_ESIMD_KERNEL {
59+
size_t id = item.get_id(0);
60+
sycl::INTEL::gpu::simd<std::uint32_t, 16> key{
61+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
62+
foo(key);
63+
sycl::INTEL::gpu::block_store(
64+
r_acc, id * SIMD_WIDTH * sizeof(std::uint32_t), key);
65+
});
66+
});
67+
} catch (const sycl::exception &e) {
68+
std::cout << "*** EXCEPTION caught: " << e.what() << "\n";
69+
return 1;
70+
}
71+
auto acc = r.template get_access<sycl::access::mode::read>();
72+
for (int i = 0; i < N_PRINT; i++) {
73+
std::cout << acc[i] << " ";
74+
}
75+
std::cout << std::endl;
76+
77+
int err_cnt = 0;
78+
79+
for (unsigned i = 0; i < nsamples; ++i) {
80+
uint32_t gold = i % 2 == 0 ? VAL1 + 1 : VAL2 + 1;
81+
uint32_t test = acc[i];
82+
if (test != gold) {
83+
if (++err_cnt < 10) {
84+
std::cout << "failed at index " << i << ", " << test << " != " << gold
85+
<< " (expected)"
86+
<< "\n";
87+
}
88+
}
89+
}
90+
if (err_cnt > 0) {
91+
std::cout << " pass rate: "
92+
<< ((float)(nsamples - err_cnt) / (float)nsamples) * 100.0f
93+
<< "% (" << (nsamples - err_cnt) << "/" << nsamples << ")\n";
94+
}
95+
96+
std::cout << (err_cnt > 0 ? "FAILED\n" : "Passed\n");
97+
return err_cnt > 0 ? 1 : 0;
98+
}

0 commit comments

Comments
 (0)