diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-06-26 12:30:30 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-06-26 12:30:30 +0200 |
commit | eda37df9c399b23dc5bdb668730101a87f4770ce (patch) | |
tree | 1c8272cf2e724617f144aed8a9cd185408f02ef3 /modules/remote-sycl/tests/data.cpp | |
parent | 729307460e77f62a532ee9841dcaed9c47f46419 (diff) |
Attempting to fix async errors
Diffstat (limited to 'modules/remote-sycl/tests/data.cpp')
-rw-r--r-- | modules/remote-sycl/tests/data.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/modules/remote-sycl/tests/data.cpp b/modules/remote-sycl/tests/data.cpp new file mode 100644 index 0000000..a2bb506 --- /dev/null +++ b/modules/remote-sycl/tests/data.cpp @@ -0,0 +1,79 @@ +#include <forstio/test/suite.hpp> + +#include "../c++/remote.hpp" + +namespace { +namespace schema { +using namespace saw::schema; + +using TestStruct = Struct< + Member<UInt64, "foo">, + Member<Int32, "bra">, + Member<Array<Float64>, "baz"> +>; +} + +SAW_TEST("SYCL Data Management"){ + using namespace saw; + + data<schema::TestStruct> host_data; + host_data.template get<"foo">() = 321u; + host_data.template get<"bra">() = 123; + auto& baz = host_data.template get<"baz">(); + baz = {1024}; + for(uint64_t i = 0; i < baz.size(); ++i){ + baz.at(i) = static_cast<double>(i*3); + } + + saw::event_loop loop; + saw::wait_scope wait{loop}; + + remote<rmt::Sycl> rmt; + + own<remote_address<rmt::Sycl>> 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"); + + auto device = rmt.connect_device(*rmt_addr); + + auto data_srv = data_server<tmpl_group<schema::TestStruct>, encode::Native, rmt::Sycl>{device}; + + auto data_cl = data_client<tmpl_group<schema::TestStruct>, encode::Native, rmt::Sycl>{data_srv}; + + auto eov = data_cl.send(host_data); + SAW_EXPECT(eov.is_value(), "Couldn't send data to SYCL"); + + auto& val = eov.get_value(); + + bool ran = false; + bool error_ran = false; + + auto conv = data_cl.receive(val).then([&](auto dat){ + auto& foo = dat.template get<"foo">(); + auto& bra = dat.template get<"bra">(); + auto& baz = dat.template get<"baz">(); + SAW_EXPECT(foo == host_data.template get<"foo">(), "Data sent back wasn't equal"); + SAW_EXPECT(bra == host_data.template get<"bra">(), "Data sent back wasn't equal"); + + for(uint64_t i = 0u; i < baz.size(); ++i){ + SAW_EXPECT(baz.at(i) == host_data.template get<"baz">().at(i), "Data sent back wasn't equal"); + } + ran = true; + }, [&](auto err){ + error_ran = true; + return std::move(err); + }); + + auto eob = conv.take(); + SAW_EXPECT(eob.is_value(), "conv value doesn't exist"); + auto& bval = eob.get_value(); + + SAW_EXPECT(!error_ran, "conveyor ran, but we got an error"); + SAW_EXPECT(ran, "conveyor didn't run"); +} +} |