diff --git a/SYCL/helpers.hpp b/SYCL/helpers.hpp new file mode 100644 index 0000000000000..e5ca8f768faed --- /dev/null +++ b/SYCL/helpers.hpp @@ -0,0 +1,76 @@ +//==------------------- 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 + + +using namespace cl; + +template +class VecPrinter { +public: + VecPrinter(const VecT &Vec) : MVec(Vec) {} + + void print(std::ostream &Out) const { + std::cout << "[ "; + printHelper(Out, MVec); + std::cout << " ]"; + } + + static void print(const VecT &Elem1) { + std::cout << "[ "; + printHelper(std::cout, Elem1); + std::cout << " ]"; + } + +private: + template + static void printHelper(std::ostream &Out, const VecT &Elem1) { + std::cout << (typename VecT::element_type)(Elem1.template swizzle()); + if (Idx + 1 != EndIdx) + std::cout << ", "; + printHelper(Out, Elem1); + } + template <> + static void printHelper(std::ostream &Out, const VecT &Elem1) {} + + VecT MVec; +}; + +template +VecPrinter printableVec(const VecT &Vec) { + return VecPrinter(Vec); +} + +template +std::ostream &operator<<(std::ostream &Out, + const VecPrinter &VecP) { + VecP.print(Out); + return Out; +} + +class TestQueue : public sycl::queue { +public: + TestQueue(const sycl::device_selector &DevSelector, + const sycl::property_list &PropList = {}) + : sycl::queue(DevSelector, + [](sycl::exception_list ExceptionList) { + for (sycl::exception_ptr_class ExceptionPtr : + ExceptionList) { + try { + std::rethrow_exception(ExceptionPtr); + } catch (sycl::exception &E) { + std::cerr << E.what() << std::endl; + } + } + abort(); + }, + PropList) {} + + ~TestQueue() { wait_and_throw(); } +};