From 25e05907f0292310eaae27a032db0ee274413874 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 2 Jul 2024 19:46:02 +0200 Subject: Preparing benchmark work --- modules/remote-sycl/tests/mixed_precision.cpp | 212 ++++++++++++++++++++++++++ modules/remote-sycl/tests/sycl_basics.cpp | 9 -- 2 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 modules/remote-sycl/tests/mixed_precision.cpp (limited to 'modules/remote-sycl/tests') diff --git a/modules/remote-sycl/tests/mixed_precision.cpp b/modules/remote-sycl/tests/mixed_precision.cpp new file mode 100644 index 0000000..4a62569 --- /dev/null +++ b/modules/remote-sycl/tests/mixed_precision.cpp @@ -0,0 +1,212 @@ +#include + +#include "../c++/remote.hpp" + +#include + +namespace { +namespace schema { +using namespace saw::schema; + +using TestMixedArray = Array< + MixedPrecision +>; + +using MixedFoo = Interface< + Member, "foo"> +>; + +using TestDoubleArray = Array< + Float64 +>; + +using DoubleFoo = Interface< + Member, "foo"> +>; + +using TestFloatArray = Array< + Float32 +>; + +using FloatFoo = Interface< + Member, "foo"> +>; +} + +constexpr uint64_t test_size = 1024ul; + +SAW_TEST("SYCL Mixed Test"){ + using namespace saw; + + std::random_device r; + std::default_random_engine e1{r()}; + std::uniform_real_distribution<> dis{-1.0,1.0}; + + data host_data; + host_data = {test_size}; + for(uint64_t i = 0; i < test_size; ++i){ + host_data.at(i) = static_cast(dis(e1)); + } + + saw::event_loop loop; + saw::wait_scope wait{loop}; + + remote rmt; + + own> rmt_addr{}; + + rmt.resolve_address().then([&](auto addr){ + rmt_addr = std::move(addr); + }).detach(); + + wait.poll(); + SAW_EXPECT(rmt_addr, "Remote address hasn't been filled"); + + data device_data{host_data}; + + cl::sycl::event ev; + + interface cl_iface { +[&](data& in, cl::sycl::queue* cmd) -> error_or { + + ev = cmd->submit([&](cl::sycl::handler& h){ + + auto acc_buff = in.template access(h); + + h.parallel_for(cl::sycl::range<1>(test_size), [=] (cl::sycl::id<1> it){ + acc_buff[0u].at(it[0u]) = acc_buff[0u].at(it[0u]) * data{2.0}; + }); + }); + return saw::void_t{}; + } + }; + auto& device = rmt_addr->get_device(); + + cl_iface.template call <"foo">(device_data, &(device.get_handle())); + device.get_handle().wait(); + + { + auto end = ev.get_profiling_info(); + auto start = ev.get_profiling_info(); + + std::cout<<"Elapsed kernel time: "<< (end-start) / 1.0e9 << " seconds"< dis{-1.0,1.0}; + + data host_data; + host_data = {test_size}; + for(uint64_t i = 0; i < test_size; ++i){ + host_data.at(i) = static_cast(dis(e1)); + } + + saw::event_loop loop; + saw::wait_scope wait{loop}; + + remote rmt; + + own> rmt_addr{}; + + rmt.resolve_address().then([&](auto addr){ + rmt_addr = std::move(addr); + }).detach(); + + wait.poll(); + SAW_EXPECT(rmt_addr, "Remote address hasn't been filled"); + + data device_data{host_data}; + + cl::sycl::event ev; + + interface cl_iface { +[&](data& in, cl::sycl::queue* cmd) -> error_or { + + ev = cmd->submit([&](cl::sycl::handler& h){ + + auto acc_buff = in.template access(h); + + h.parallel_for(cl::sycl::range<1>(test_size), [=] (cl::sycl::id<1> it){ + acc_buff[0u].at(it[0u]) = acc_buff[0u].at(it[0u]) * data{2.0}; + }); + }); + return saw::void_t{}; + } + }; + auto& device = rmt_addr->get_device(); + + cl_iface.template call <"foo">(device_data, &(device.get_handle())); + device.get_handle().wait(); + + { + auto end = ev.get_profiling_info(); + auto start = ev.get_profiling_info(); + + std::cout<<"Elapsed kernel time: "<< (end-start) / 1.0e9 << " seconds"< dis{-1.0,1.0}; + + data host_data; + host_data = {test_size}; + for(uint64_t i = 0; i < test_size; ++i){ + host_data.at(i) = static_cast(dis(e1)); + } + + saw::event_loop loop; + saw::wait_scope wait{loop}; + + remote rmt; + + own> rmt_addr{}; + + rmt.resolve_address().then([&](auto addr){ + rmt_addr = std::move(addr); + }).detach(); + + wait.poll(); + SAW_EXPECT(rmt_addr, "Remote address hasn't been filled"); + + data device_data{host_data}; + + cl::sycl::event ev; + + interface cl_iface { +[&](data& in, cl::sycl::queue* cmd) -> error_or { + + ev = cmd->submit([&](cl::sycl::handler& h){ + + auto acc_buff = in.template access(h); + + h.parallel_for(cl::sycl::range<1>(test_size), [=] (cl::sycl::id<1> it){ + acc_buff[0u].at(it[0u]) = acc_buff[0u].at(it[0u]) * data{2.0}; + }); + }); + return saw::void_t{}; + } + }; + auto& device = rmt_addr->get_device(); + + cl_iface.template call <"foo">(device_data, &(device.get_handle())); + device.get_handle().wait(); + + { + auto end = ev.get_profiling_info(); + auto start = ev.get_profiling_info(); + + std::cout<<"Elapsed kernel time: "<< (end-start) / 1.0e9 << " seconds"<, "foo"> >; - -using Calculator = Interface< - Member< - Function, Int64>, "add" - > -, Member< - Function, Int64>, "multiply" - > ->; } SAW_TEST("SYCL Test Setup"){ using namespace saw; -- cgit v1.2.3