forked from intel/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.hpp
More file actions
73 lines (62 loc) · 2.11 KB
/
helpers.hpp
File metadata and controls
73 lines (62 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//==------------------- helpers.hpp - test helpers ------------------------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <iostream>
#include <sycl/sycl.hpp>
template <class VecT, int EndIdx = VecT::get_count(), int StartIdx = 0>
class VecPrinter {
public:
VecPrinter(const VecT &Vec) : MVec(Vec) {}
void print(std::ostream &Out) const {
std::cout << "[ ";
printHelper<StartIdx>(Out, MVec);
std::cout << " ]";
}
static void print(const VecT &Elem1) {
std::cout << "[ ";
printHelper<StartIdx>(std::cout, Elem1);
std::cout << " ]";
}
private:
template <int Idx>
static void printHelper(std::ostream &Out, const VecT &Elem1) {
std::cout << (typename VecT::element_type)(Elem1.template swizzle<Idx>());
if (Idx + 1 != EndIdx)
std::cout << ", ";
printHelper<Idx + 1>(Out, Elem1);
}
template <>
static void printHelper<EndIdx>(std::ostream &Out, const VecT &Elem1) {}
VecT MVec;
};
template <class VecT, int EndIdx = VecT::get_count(), int StartIdx = 0>
VecPrinter<VecT, EndIdx, StartIdx> printableVec(const VecT &Vec) {
return VecPrinter<VecT, EndIdx, StartIdx>(Vec);
}
template <class VecT, int EndIdx, int StartIdx>
std::ostream &operator<<(std::ostream &Out,
const VecPrinter<VecT, EndIdx, StartIdx> &VecP) {
VecP.print(Out);
return Out;
}
void exceptionHandlerHelper(sycl::exception_list ExceptionList) {
for (std::exception_ptr ExceptionPtr : ExceptionList) {
try {
std::rethrow_exception(ExceptionPtr);
} catch (sycl::exception &E) {
std::cerr << E.what() << std::endl;
}
}
abort();
}
class TestQueue : public sycl::queue {
public:
TestQueue(const sycl::detail::DSelectorInvocableType &DevSelector,
const sycl::property_list &PropList = {})
: sycl::queue(DevSelector, exceptionHandlerHelper, PropList) {}
~TestQueue() { wait_and_throw(); }
};