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

Commit 45a96ee

Browse files
authored
[SYCL][ESIMD] Test half type conversion under ESIMD emulator (#1155)
Complementary compiler PR: intel/llvm#6592
1 parent efeffb3 commit 45a96ee

File tree

6 files changed

+96
-10
lines changed

6 files changed

+96
-10
lines changed

SYCL/ESIMD/api/bin_and_cmp_ops_heavy.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//===----------------------------------------------------------------------===//
88
// REQUIRES: gpu
99
// UNSUPPORTED: cuda || hip
10-
// TODO: esimd_emulator fails due to unimplemented 'half' type
11-
// XFAIL: esimd_emulator
1210
// RUN: %clangxx -fsycl %s -o %t.out
1311
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1412

SYCL/ESIMD/api/simd_memory_access.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//===----------------------------------------------------------------------===//
88
// REQUIRES: gpu
99
// UNSUPPORTED: cuda || hip
10-
// TODO: esimd_emulator fails due to unimplemented 'half' type
11-
// XFAIL: esimd_emulator
1210
// RUN: %clangxx -fsycl %s -o %t.out
1311
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1412
//

SYCL/ESIMD/api/simd_view_select_2d_fp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//===----------------------------------------------------------------------===//
88
// REQUIRES: gpu
99
// UNSUPPORTED: cuda || hip
10-
// TODO: esimd_emulator fails due to unimplemented 'single_task()' method
11-
// XFAIL: esimd_emulator
1210
// RUN: %clangxx -fsycl %s -fsycl-device-code-split=per_kernel -o %t.out
1311
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1412
//

SYCL/ESIMD/api/slm_gather_scatter_heavy.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//===----------------------------------------------------------------------===//
88
// REQUIRES: gpu
99
// UNSUPPORTED: cuda || hip
10-
// TODO: esimd_emulator fails due to outdated memory intrinsic
11-
// XFAIL: esimd_emulator
1210
// RUN: %clangxx -fsycl %s -o %t.out
1311
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1412
//

SYCL/ESIMD/api/unary_ops_heavy.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//===----------------------------------------------------------------------===//
88
// REQUIRES: gpu
99
// UNSUPPORTED: cuda || hip
10-
// TODO: esimd_emulator fails due to unimplemented 'half' type
11-
// XFAIL: esimd_emulator
1210
// RUN: %clangxx -fsycl %s -o %t.out
1311
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1412

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// REQUIRES: gpu
2+
// UNSUPPORTED: cuda || hip
3+
// RUN: %clangxx -fsycl %s -o %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
//==- half_conversion_test.cpp - Test for half conversion under ESIMD_EMULATOR
6+
// backend -==/
7+
//
8+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9+
// See https://llvm.org/LICENSE.txt for license information.
10+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include <stdlib.h>
15+
#include <sycl/ext/intel/esimd.hpp>
16+
#include <sycl/sycl.hpp>
17+
18+
#include <iostream>
19+
20+
using namespace ::sycl;
21+
using namespace ::sycl::ext;
22+
using namespace sycl::ext::intel;
23+
using namespace sycl::ext::intel::esimd;
24+
25+
template <int N>
26+
using int_type_t = std::conditional_t<
27+
N == 1, int8_t,
28+
std::conditional_t<
29+
N == 2, int16_t,
30+
std::conditional_t<N == 4, int32_t,
31+
std::conditional_t<N == 8, int64_t, void>>>>;
32+
33+
template <class Ty> bool test(queue q, int inc) {
34+
Ty *data = new Ty[1];
35+
36+
data[0] = (Ty)0;
37+
Ty VAL = (Ty)inc;
38+
39+
try {
40+
buffer<Ty, 1> buf(data, range<1>(1));
41+
q.submit([&](handler &cgh) {
42+
std::cout << "Running on "
43+
<< q.get_device().get_info<::sycl::info::device::name>()
44+
<< "\n";
45+
auto acc = buf.template get_access<access::mode::read_write>(cgh);
46+
cgh.single_task([=]() SYCL_ESIMD_KERNEL {
47+
simd<uint32_t, 1> offsets(0);
48+
simd<Ty, 1> vec = gather<Ty, 1>(acc, offsets);
49+
vec[0] += (Ty)inc;
50+
scalar_store<Ty>(acc, 0, vec[0]);
51+
});
52+
});
53+
} catch (::sycl::exception const &e) {
54+
std::cout << "SYCL exception caught: " << e.what() << '\n';
55+
delete[] data;
56+
return false;
57+
}
58+
59+
using Tint = int_type_t<sizeof(Ty)>;
60+
Tint ResBits = *(Tint *)&data[0];
61+
Tint GoldBits = *(Tint *)&VAL;
62+
63+
std::cout << "Comparison of representation '" << inc << "' of Type "
64+
<< typeid(Ty).name() << std::endl;
65+
std::cout << "Bits(data[0]) = 0x" << std::hex << ResBits << " / "
66+
<< "Bits(GOLD) = 0x" << GoldBits << std::dec << std::endl;
67+
68+
if (VAL == data[0]) {
69+
std::cout << "Pass";
70+
} else {
71+
std::cout << "Fail";
72+
}
73+
74+
return ((Ty)inc == data[0]);
75+
}
76+
77+
int main(int argc, char *argv[]) {
78+
bool passed = true;
79+
queue q;
80+
81+
std::cout << "\n===================" << std::endl;
82+
passed &= test<short>(q, 1);
83+
std::cout << "\n===================" << std::endl;
84+
passed &= test<half>(q, 1);
85+
std::cout << "\n===================" << std::endl;
86+
passed &= test<float>(q, 1);
87+
std::cout << "\n===================" << std::endl;
88+
89+
if (passed) {
90+
std::cout << "Pass!!" << std::endl;
91+
} else {
92+
std::cout << "Fail!!" << std::endl;
93+
}
94+
95+
return passed ? 0 : -1;
96+
}

0 commit comments

Comments
 (0)