Skip to content

Commit aa76104

Browse files
committed
Tests reconstruction
Signed-off-by: Aleksander Fadeev <[email protected]>
1 parent b8f770b commit aa76104

File tree

6 files changed

+112
-317
lines changed

6 files changed

+112
-317
lines changed

sycl/test/basic_tests/vec_convert.cpp

Lines changed: 0 additions & 153 deletions
This file was deleted.

sycl/test/basic_tests/vec_convert.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <CL/sycl.hpp>
2+
3+
#include <cassert>
4+
5+
using namespace cl::sycl;
6+
7+
template <typename T, typename convertT, int roundingMode> class kernel_name;
8+
9+
template <int N> struct helper;
10+
11+
template <> struct helper<0> {
12+
template <typename T, int NumElements>
13+
static void compare(const vec<T, NumElements> &x,
14+
const vec<T, NumElements> &y) {
15+
const T xs = x.template swizzle<0>();
16+
const T ys = y.template swizzle<0>();
17+
assert(xs == ys);
18+
}
19+
};
20+
21+
template <int N> struct helper {
22+
template <typename T, int NumElements>
23+
static void compare(const vec<T, NumElements> &x,
24+
const vec<T, NumElements> &y) {
25+
const T xs = x.template swizzle<N>();
26+
const T ys = y.template swizzle<N>();
27+
helper<N - 1>::compare(x, y);
28+
assert(xs == ys);
29+
}
30+
};
31+
32+
template <typename T, typename convertT, int NumElements,
33+
rounding_mode roundingMode>
34+
void test(const vec<T, NumElements> &ToConvert,
35+
const vec<convertT, NumElements> &Expected) {
36+
vec<convertT, NumElements> Converted{0};
37+
{
38+
buffer<vec<convertT, NumElements>, 1> Buffer{&Converted, range<1>{1}};
39+
queue Queue;
40+
Queue.submit([&](handler &CGH) {
41+
accessor<vec<convertT, NumElements>, 1, access::mode::write> Accessor(
42+
Buffer, CGH);
43+
CGH.single_task<class kernel_name<T, convertT, static_cast<int>(roundingMode)>>([=]() {
44+
Accessor[0] = ToConvert.template convert<convertT, roundingMode>();
45+
});
46+
});
47+
}
48+
helper<NumElements - 1>::compare(Converted, Expected);
49+
}

sycl/test/basic_tests/vec_convert_f_to_f.cpp

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include <CL/sycl.hpp>
15-
16-
#include <cassert>
17-
18-
using namespace cl::sycl;
19-
20-
template <typename T, typename convertT, int roundingMode>
21-
class kernel_name;
22-
23-
template <int N>
24-
struct helper;
25-
26-
template <>
27-
struct helper<0> {
28-
template <typename T, int NumElements>
29-
static void compare(const vec<T, NumElements> &x,
30-
const vec<T, NumElements> &y) {
31-
const T xs = x.template swizzle<0>();
32-
const T ys = y.template swizzle<0>();
33-
assert(xs == ys);
34-
}
35-
};
36-
37-
template <int N>
38-
struct helper {
39-
template <typename T, int NumElements>
40-
static void compare(const vec<T, NumElements> &x,
41-
const vec<T, NumElements> &y) {
42-
const T xs = x.template swizzle<N>();
43-
const T ys = y.template swizzle<N>();
44-
helper<N - 1>::compare(x, y);
45-
assert(xs == ys);
46-
}
47-
};
48-
49-
template <typename T, typename convertT, int NumElements,
50-
rounding_mode roundingMode>
51-
void test(const vec<T, NumElements> &ToConvert,
52-
const vec<convertT, NumElements> &Expected) {
53-
vec<convertT, NumElements> Converted{0};
54-
{
55-
buffer<vec<convertT, NumElements>, 1> Buffer{&Converted, range<1>{1}};
56-
queue Queue;
57-
Queue.submit([&](handler &CGH) {
58-
accessor<vec<convertT, NumElements>, 1, access::mode::write> Accessor(
59-
Buffer, CGH);
60-
CGH.single_task<class kernel_name<T, convertT, static_cast<int>(roundingMode)>>([=]() {
61-
Accessor[0] = ToConvert.template convert<convertT, roundingMode>();
62-
});
63-
});
64-
}
65-
helper<NumElements - 1>::compare(Converted, Expected);
66-
}
14+
#include "vec_convert.hpp"
6715

6816
int main() {
6917
// automatic
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// XFAIL: cuda
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7+
//==------------ vec_convert.cpp - SYCL vec class convert method test ------==//
8+
//
9+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10+
// See https://llvm.org/LICENSE.txt for license information.
11+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "vec_convert.hpp"
16+
17+
// TODO make the test to pass on cuda
18+
19+
int main() {
20+
// automatic
21+
test<float, int, 8, rounding_mode::automatic>(
22+
float8{+2.3f, +2.5f, +2.7f, -2.3f, -2.5f, -2.7f, 0.f, 0.f},
23+
int8{2, 2, 3, -2, -2, -3, 0, 0});
24+
test<int, float, 8, rounding_mode::automatic>(
25+
int8{2, 3, 3, -2, -3, -3, 0, 0},
26+
float8{2.f, 3.f, 3.f, -2.f, -3.f, -3.f, 0.f, 0.f});
27+
28+
// rte
29+
test<float, int, 8, rounding_mode::rte>(
30+
float8{+2.3f, +2.5f, +2.7f, -2.3f, -2.5f, -2.7f, 0.f, 0.f},
31+
int8{2, 2, 3, -2, -2, -3, 0, 0});
32+
test<int, float, 8, rounding_mode::rte>(
33+
int8{2, 3, 3, -2, -3, -3, 0, 0},
34+
float8{2.f, 3.f, 3.f, -2.f, -3.f, -3.f, 0.f, 0.f});
35+
36+
// rtz
37+
test<float, int, 8, rounding_mode::rtz>(
38+
float8{+2.3f, +2.5f, +2.7f, -2.3f, -2.5f, -2.7f, 0.f, 0.f},
39+
int8{2, 2, 2, -2, -2, -2, 0, 0});
40+
test<int, float, 8, rounding_mode::rtz>(
41+
int8{2, 3, 3, -2, -3, -3, 0, 0},
42+
float8{2.f, 3.f, 3.f, -2.f, -3.f, -3.f, 0.f, 0.f});
43+
44+
// rtp
45+
test<float, int, 8, rounding_mode::rtp>(
46+
float8{+2.3f, +2.5f, +2.7f, -2.3f, -2.5f, -2.7f, 0.f, 0.f},
47+
int8{3, 3, 3, -2, -2, -2, 0, 0});
48+
test<int, float, 8, rounding_mode::rtp>(
49+
int8{2, 3, 3, -2, -3, -3, 0, 0},
50+
float8{2.f, 3.f, 3.f, -2.f, -3.f, -3.f, 0.f, 0.f});
51+
52+
// rtn
53+
test<float, int, 8, rounding_mode::rtn>(
54+
float8{+2.3f, +2.5f, +2.7f, -2.3f, -2.5f, -2.7f, 0.f, 0.f},
55+
int8{2, 2, 2, -3, -3, -3, 0, 0});
56+
test<int, float, 8, rounding_mode::rtn>(
57+
int8{2, 3, 3, -2, -3, -3, 0, 0},
58+
float8{2.f, 3.f, 3.f, -2.f, -3.f, -3.f, 0.f, 0.f});
59+
return 0;
60+
}

sycl/test/basic_tests/vec_convert_half.cpp

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include <CL/sycl.hpp>
15-
16-
#include <cassert>
17-
18-
using namespace cl::sycl;
19-
20-
template <typename T, typename convertT, int roundingMode>
21-
class kernel_name;
22-
23-
template <int N>
24-
struct helper;
25-
26-
template <>
27-
struct helper<0> {
28-
template <typename T, int NumElements>
29-
static void compare(const vec<T, NumElements> &x,
30-
const vec<T, NumElements> &y) {
31-
const T xs = x.template swizzle<0>();
32-
const T ys = y.template swizzle<0>();
33-
assert(xs == ys);
34-
}
35-
};
36-
37-
template <int N>
38-
struct helper {
39-
template <typename T, int NumElements>
40-
static void compare(const vec<T, NumElements> &x,
41-
const vec<T, NumElements> &y) {
42-
const T xs = x.template swizzle<N>();
43-
const T ys = y.template swizzle<N>();
44-
helper<N - 1>::compare(x, y);
45-
assert(xs == ys);
46-
}
47-
};
48-
49-
template <typename T, typename convertT, int NumElements,
50-
rounding_mode roundingMode>
51-
void test(const vec<T, NumElements> &ToConvert,
52-
const vec<convertT, NumElements> &Expected) {
53-
vec<convertT, NumElements> Converted{0};
54-
{
55-
buffer<vec<convertT, NumElements>, 1> Buffer{&Converted, range<1>{1}};
56-
queue Queue;
57-
58-
cl::sycl::device D = Queue.get_device();
59-
if (!D.has_extension("cl_khr_fp16"))
60-
exit(0);
61-
62-
Queue.submit([&](handler &CGH) {
63-
accessor<vec<convertT, NumElements>, 1, access::mode::write> Accessor(
64-
Buffer, CGH);
65-
CGH.single_task<class kernel_name<T, convertT, static_cast<int>(roundingMode)>>([=]() {
66-
Accessor[0] = ToConvert.template convert<convertT, roundingMode>();
67-
});
68-
});
69-
}
70-
helper<NumElements - 1>::compare(Converted, Expected);
71-
}
14+
#include "vec_convert.hpp"
7215

7316
int main() {
7417
//automatic

0 commit comments

Comments
 (0)