Skip to content

Commit 4a54111

Browse files
authored
Fix tests after move of Scheduler out of Basic (intel#38)
1 parent c9eb12f commit 4a54111

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

SYCL/helpers.hpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//==------------------- helpers.hpp - test helpers ------------------------==//
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+
9+
#include <CL/sycl.hpp>
10+
11+
12+
using namespace cl;
13+
14+
template <class VecT, int EndIdx = VecT::get_count(), int StartIdx = 0>
15+
class VecPrinter {
16+
public:
17+
VecPrinter(const VecT &Vec) : MVec(Vec) {}
18+
19+
void print(std::ostream &Out) const {
20+
std::cout << "[ ";
21+
printHelper<StartIdx>(Out, MVec);
22+
std::cout << " ]";
23+
}
24+
25+
static void print(const VecT &Elem1) {
26+
std::cout << "[ ";
27+
printHelper<StartIdx>(std::cout, Elem1);
28+
std::cout << " ]";
29+
}
30+
31+
private:
32+
template <int Idx>
33+
static void printHelper(std::ostream &Out, const VecT &Elem1) {
34+
std::cout << (typename VecT::element_type)(Elem1.template swizzle<Idx>());
35+
if (Idx + 1 != EndIdx)
36+
std::cout << ", ";
37+
printHelper<Idx + 1>(Out, Elem1);
38+
}
39+
template <>
40+
static void printHelper<EndIdx>(std::ostream &Out, const VecT &Elem1) {}
41+
42+
VecT MVec;
43+
};
44+
45+
template <class VecT, int EndIdx = VecT::get_count(), int StartIdx = 0>
46+
VecPrinter<VecT, EndIdx, StartIdx> printableVec(const VecT &Vec) {
47+
return VecPrinter<VecT, EndIdx, StartIdx>(Vec);
48+
}
49+
50+
template <class VecT, int EndIdx, int StartIdx>
51+
std::ostream &operator<<(std::ostream &Out,
52+
const VecPrinter<VecT, EndIdx, StartIdx> &VecP) {
53+
VecP.print(Out);
54+
return Out;
55+
}
56+
57+
class TestQueue : public sycl::queue {
58+
public:
59+
TestQueue(const sycl::device_selector &DevSelector,
60+
const sycl::property_list &PropList = {})
61+
: sycl::queue(DevSelector,
62+
[](sycl::exception_list ExceptionList) {
63+
for (sycl::exception_ptr_class ExceptionPtr :
64+
ExceptionList) {
65+
try {
66+
std::rethrow_exception(ExceptionPtr);
67+
} catch (sycl::exception &E) {
68+
std::cerr << E.what() << std::endl;
69+
}
70+
}
71+
abort();
72+
},
73+
PropList) {}
74+
75+
~TestQueue() { wait_and_throw(); }
76+
};

0 commit comments

Comments
 (0)