From 97ec4b9edfa88302878b523baf09674503d19fab Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 22 May 2024 17:22:18 +0200 Subject: Progress in fixing remote-sycl and ammended minor parts in echo_client --- modules/remote-sycl/tests/calculator.cpp | 64 +++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) (limited to 'modules/remote-sycl/tests/calculator.cpp') diff --git a/modules/remote-sycl/tests/calculator.cpp b/modules/remote-sycl/tests/calculator.cpp index 9ee1583..730838d 100644 --- a/modules/remote-sycl/tests/calculator.cpp +++ b/modules/remote-sycl/tests/calculator.cpp @@ -2,6 +2,68 @@ #include "../c++/remote.hpp" -SAW_TEST("OpenCl Calculator"){ +namespace { +namespace schema { +using namespace saw::schema; +using Calculator = Interface< + Member< + Function, Int64>, "add" + > +, Member< + Function, Int64>, "multiply" + > +>; +} + +SAW_TEST("Sycl Interface Calculator"){ + using namespace saw; + + cl::sycl::queue cmd_queue; + + interface, cl::sycl::queue*> cl_iface { +[](data> in, cl::sycl::queue* cmd) -> data { + std::array h_xy{in.get<0>().get(), in.get<1>().get()}; + int64_t res{}; + cl::sycl::buffer d_xy { h_xy.data(), h_xy.size() }; + cl::sycl::buffer d_z { &res, 1u }; + cmd->submit([&](cl::sycl::handler& h){ + auto a_xy = d_xy.get_access(h); + auto a_z = d_z.get_access(h); + + h.parallel_for(cl::sycl::range<1>(1u), [=] (cl::sycl::id<1> it){ + a_z[0] = a_xy[0] + a_xy[1]; + }); + }); + cmd->wait(); + return data{res}; + }, + [](data> in, cl::sycl::queue* cmd) -> data { + return data{in.get<0>().get() * in.get<1>().get()}; + } + }; + + int64_t x = 1; + int64_t y = -2; + int64_t sum = x + y; + int64_t mult = x * y; + + + data> input; + input.template get<0>().set(x); + input.template get<1>().set(y); + + { + auto eov = cl_iface.template call<"add">(input, &cmd_queue); + SAW_EXPECT(eov.is_value(), "Returned error on add"); + + SAW_EXPECT(eov.get_value().get() == sum, "Addition was incorrect"); + } + { + auto eov = cl_iface.template call<"multiply">(input, &cmd_queue); + SAW_EXPECT(eov.is_value(), "Returned error on add"); + + SAW_EXPECT(eov.get_value().get() == mult, "Addition was incorrect"); + } +} } -- cgit v1.2.3