Skip to content

Commit 2dbc002

Browse files
authored
Merge pull request intel#1118 from kychendev/private/kchen/esimd-embargo-wait-test
[ESIMD] Add E2E test for esimd wait API. This is a complementary test for llvm#6760.
2 parents ac171d5 + 496efc0 commit 2dbc002

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+
//==------------------- esimd_wait.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-intel-pvc
9+
// UNSUPPORTED: cuda || hip
10+
// RUN: %clangxx -fsycl %s -o %t.out
11+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
12+
13+
// Smoke test for the esimd wait API.
14+
15+
#include "../../esimd_test_utils.hpp"
16+
17+
#include <CL/sycl.hpp>
18+
#include <ext/intel/esimd.hpp>
19+
20+
#include <iostream>
21+
22+
using namespace sycl;
23+
24+
int main() {
25+
constexpr unsigned Size = 16;
26+
constexpr unsigned VL = 16;
27+
constexpr unsigned GroupSize = 1;
28+
29+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
30+
auto dev = q.get_device();
31+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
32+
33+
auto ctxt = q.get_context();
34+
auto *A =
35+
static_cast<float *>(malloc_shared(Size * sizeof(float), dev, ctxt));
36+
auto *B =
37+
static_cast<float *>(malloc_shared(Size * sizeof(float), dev, ctxt));
38+
auto *C =
39+
static_cast<float *>(malloc_shared(Size * sizeof(float), dev, ctxt));
40+
41+
for (auto i = 0; i != Size; i++) {
42+
A[i] = 1.0f;
43+
B[i] = 3.0f;
44+
}
45+
46+
// iteration space
47+
nd_range<1> Range(range<1>(Size / VL), range<1>(GroupSize));
48+
49+
auto e = q.submit([&](handler &cgh) {
50+
cgh.parallel_for<class Test>(Range, [=](nd_item<1> i) SYCL_ESIMD_KERNEL {
51+
using namespace __ESIMD_NS;
52+
using namespace __ESIMD_ENS;
53+
54+
simd<uint32_t, VL> address(0, 1);
55+
address = address * sizeof(float);
56+
simd_mask<VL> pred(0);
57+
pred[0] = 1;
58+
simd<float, VL> data =
59+
lsc_gather<float, 1, lsc_data_size::default_size, cache_hint::cached,
60+
cache_hint::cached, VL>(A, address);
61+
wait(data.bit_cast_view<uint16_t>()[0]);
62+
simd<float, VL> tmp =
63+
lsc_gather<float, 1, lsc_data_size::default_size, cache_hint::cached,
64+
cache_hint::cached, VL>(B, address);
65+
wait(tmp.bit_cast_view<uint16_t>()[0]);
66+
data.merge(tmp, pred);
67+
lsc_block_store<float, VL, lsc_data_size::default_size,
68+
cache_hint::write_back, cache_hint::write_back>(C, data);
69+
});
70+
});
71+
e.wait();
72+
73+
bool passed = true;
74+
for (auto i = 0; i != Size; i++) {
75+
std::cout << " C[" << i << "]:" << C[i] << std::endl;
76+
if ((i == 0 && C[i] != B[i]) || (i > 0 && C[i] != A[i])) {
77+
passed = false;
78+
break;
79+
}
80+
}
81+
82+
free(A, q);
83+
free(B, q);
84+
free(C, q);
85+
86+
std::cout << (passed ? "=== Test passed\n" : "=== Test FAILED\n");
87+
return passed ? 0 : 1;
88+
}

0 commit comments

Comments
 (0)