|
| 1 | +// UNSUPPORTED: cuda |
| 2 | +// |
| 3 | +// RUN: %clangxx -fsycl %s -o %t.out |
| 4 | +// RUN: %RUN_ON_HOST %t.out | FileCheck %s |
| 5 | +// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER |
| 6 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER |
| 7 | +// |
| 8 | +// The test checks that the specialization constant feature works correctly with |
| 9 | +// composite types: toolchain processes them correctly and runtime can correctly |
| 10 | +// execute the program. |
| 11 | +// |
| 12 | +// CHECK: 1 : 2 |
| 13 | +// CHECK-NEXT: 3 |
| 14 | +// CHECK-NEXT: 4 : 5 |
| 15 | + |
| 16 | +#include <CL/sycl.hpp> |
| 17 | + |
| 18 | +using namespace cl::sycl; |
| 19 | + |
| 20 | +struct A { |
| 21 | + float x; |
| 22 | + float y[2]; |
| 23 | +}; |
| 24 | + |
| 25 | +struct pod_t { |
| 26 | + int f1[2]; |
| 27 | + A f2; |
| 28 | +}; |
| 29 | + |
| 30 | +class my_kernel_t { |
| 31 | +public: |
| 32 | + using sc_t = |
| 33 | + sycl::ONEAPI::experimental::spec_constant<pod_t, class my_kernel_t>; |
| 34 | + |
| 35 | + my_kernel_t(const sc_t &sc, const cl::sycl::stream &strm) |
| 36 | + : sc_(sc), strm_(strm) {} |
| 37 | + |
| 38 | + void operator()(cl::sycl::id<1> i) const { |
| 39 | + auto p = sc_.get(); |
| 40 | + strm_ << p.f1[0] << " : " << p.f1[1] << "\n"; |
| 41 | + strm_ << p.f2.x << "\n"; |
| 42 | + strm_ << p.f2.y[0] << " : " << p.f2.y[1] << "\n"; |
| 43 | + strm_ << sycl::endl; |
| 44 | + } |
| 45 | + |
| 46 | + sc_t sc_; |
| 47 | + cl::sycl::stream strm_; |
| 48 | +}; |
| 49 | + |
| 50 | +int main() { |
| 51 | + cl::sycl::queue q(default_selector{}, [](exception_list l) { |
| 52 | + for (auto ep : l) { |
| 53 | + try { |
| 54 | + std::rethrow_exception(ep); |
| 55 | + } catch (cl::sycl::exception &e0) { |
| 56 | + std::cout << e0.what(); |
| 57 | + } catch (std::exception &e1) { |
| 58 | + std::cout << e1.what(); |
| 59 | + } catch (...) { |
| 60 | + std::cout << "*** catch (...)\n"; |
| 61 | + } |
| 62 | + } |
| 63 | + }); |
| 64 | + |
| 65 | + pod_t pod; |
| 66 | + pod.f1[0] = 1; |
| 67 | + pod.f1[1] = 2; |
| 68 | + pod.f2.x = 3; |
| 69 | + pod.f2.y[0] = 4; |
| 70 | + pod.f2.y[1] = 5; |
| 71 | + |
| 72 | + cl::sycl::program p(q.get_context()); |
| 73 | + auto sc = p.set_spec_constant<my_kernel_t>(pod); |
| 74 | + p.build_with_kernel_type<my_kernel_t>(); |
| 75 | + |
| 76 | + q.submit([&](cl::sycl::handler &cgh) { |
| 77 | + cl::sycl::stream strm(1024, 256, cgh); |
| 78 | + my_kernel_t func(sc, strm); |
| 79 | + |
| 80 | + auto sycl_kernel = p.get_kernel<my_kernel_t>(); |
| 81 | + cgh.parallel_for(sycl_kernel, cl::sycl::range<1>(1), func); |
| 82 | + }); |
| 83 | + q.wait(); |
| 84 | + |
| 85 | + return 0; |
| 86 | +} |
| 87 | + |
0 commit comments