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

Commit 4f9c63a

Browse files
committed
Test half type conversion under ESIMD emulator
1 parent 58ceaa1 commit 4f9c63a

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+
// 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 <CL/sycl.hpp>
15+
#include <stdlib.h>
16+
#include <sycl/ext/intel/esimd.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 <typename Ty> struct test_id;
26+
template <int N>
27+
using int_type_t = std::conditional_t<
28+
N == 1, int8_t,
29+
std::conditional_t<
30+
N == 2, int16_t,
31+
std::conditional_t<N == 4, int32_t,
32+
std::conditional_t<N == 8, int64_t, void>>>>;
33+
34+
template <class Ty> bool test(queue q, int inc) {
35+
Ty *data = new Ty[1];
36+
37+
data[0] = (Ty)0;
38+
Ty VAL = (Ty)inc;
39+
40+
try {
41+
buffer<Ty, 1> buf(data, range<1>(1));
42+
q.submit([&](handler &cgh) {
43+
std::cout << "Running on "
44+
<< q.get_device().get_info<::sycl::info::device::name>()
45+
<< "\n";
46+
auto acc = buf.template get_access<access::mode::read_write>(cgh);
47+
cgh.single_task<test_id<Ty>>([=]() SYCL_ESIMD_KERNEL {
48+
simd<uint32_t, 1> offsets(0);
49+
simd<Ty, 1> vec = gather<Ty, 1>(acc, offsets);
50+
vec[0] += (Ty)inc;
51+
scalar_store<Ty>(acc, 0, vec[0]);
52+
});
53+
});
54+
} catch (::sycl::exception const &e) {
55+
std::cout << "SYCL exception caught: " << e.what() << '\n';
56+
delete[] data;
57+
return false;
58+
}
59+
60+
using Tint = int_type_t<sizeof(Ty)>;
61+
Tint ResBits = *(Tint *)&data[0];
62+
Tint GoldBits = *(Tint *)&VAL;
63+
64+
std::cout << "Comparison of representation '" << inc << "' of Type "
65+
<< typeid(Ty).name() << std::endl;
66+
std::cout << "Bits(data[0]) = 0x" << std::hex << ResBits << " / "
67+
<< "Bits(GOLD) = 0x" << GoldBits << std::dec << std::endl;
68+
69+
if (VAL == data[0]) {
70+
std::cout << "Pass";
71+
} else {
72+
std::cout << "Fail";
73+
}
74+
75+
return ((Ty)inc == data[0]);
76+
}
77+
78+
int main(int argc, char *argv[]) {
79+
bool passed = true;
80+
queue q;
81+
82+
std::cout << "\n===================" << std::endl;
83+
passed &= test<short>(q, 1);
84+
std::cout << "\n===================" << std::endl;
85+
passed &= test<half>(q, 1);
86+
std::cout << "\n===================" << std::endl;
87+
passed &= test<float>(q, 1);
88+
std::cout << "\n===================" << std::endl;
89+
90+
if (passed) {
91+
std::cout << "Pass!!" << std::endl;
92+
} else {
93+
std::cout << "Fail!!" << std::endl;
94+
}
95+
96+
return passed ? 0 : -1;
97+
}

0 commit comments

Comments
 (0)