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/core/c++/id.hpp | 4 ++ modules/io/examples/echo_client.cpp | 21 +++++++--- modules/remote-sycl/.nix/derivation.nix | 22 +++++++++- modules/remote-sycl/SConstruct | 9 ++++ modules/remote-sycl/c++/SConscript | 24 +++++------ modules/remote-sycl/c++/remote.hpp | 32 +++++++++++---- modules/remote-sycl/examples/SConscript | 31 ++++++++++++++ modules/remote-sycl/examples/sycl_basic.cpp | 47 +++++++++++++++++++++ modules/remote-sycl/tests/calculator.cpp | 64 ++++++++++++++++++++++++++++- 9 files changed, 225 insertions(+), 29 deletions(-) create mode 100644 modules/remote-sycl/examples/SConscript create mode 100644 modules/remote-sycl/examples/sycl_basic.cpp (limited to 'modules') diff --git a/modules/core/c++/id.hpp b/modules/core/c++/id.hpp index d836648..32fa95f 100644 --- a/modules/core/c++/id.hpp +++ b/modules/core/c++/id.hpp @@ -1,5 +1,9 @@ #pragma once +#include + +#include "common.hpp" + namespace saw { /** * ID class which is tied to it's representing class diff --git a/modules/io/examples/echo_client.cpp b/modules/io/examples/echo_client.cpp index 4b95158..e827ce0 100644 --- a/modules/io/examples/echo_client.cpp +++ b/modules/io/examples/echo_client.cpp @@ -5,6 +5,8 @@ #include "echo.hpp" +std::string message_content = "Hey there! Sending this message"; + int main(){ /** * Create EventLoop @@ -38,26 +40,33 @@ int main(){ net_addr = std::move(addr); network.connect(*net_addr).then([&](auto rmt_srv){ async_rmt = saw::heap(std::move(rmt_srv)); - async_rmt->write("foo", 3); + async_rmt->write(&message_content[0], message_content.size()); - async_rmt->read(&read_data[0], 3, read_data.size()-1); + async_rmt->read(&read_data[0], message_content.size(), read_data.size()-1); async_rmt->read_done().then([&](size_t b){ - std::cout<<"Received bytes:\n"<(read_data[i]); } - std::cout<on_read_disconnected().then([&](){ keep_running = false; + std::cout<<"Disconnected"<> on_receive(); /// Stopped here }; + +template +class data, encode::Native> { +private: + cl::sycl::buffer::type, D> device_data_; + + static_assert(D==1u, "For now we only support 1D Arrays"); +public: +}; + namespace impl { template @@ -53,8 +63,10 @@ struct rpc_id_map_helper, Encoding> { */ template class rpc_server { +public: + using InterfaceCtxT = cl::sycl::queue*; + using InterfaceT = interface; private: - using IfaceCtx = cl::sycl::queue*; /** * Command queue for the sycl backend */ @@ -63,14 +75,14 @@ private: /** * The interface including the relevant context class. */ - interface cl_interface_; + interface cl_interface_; /** * */ impl::rpc_id_map_helper storage_; public: - rpc_server(interface cl_iface): + rpc_server(interface cl_iface): cmd_queue_{}, cl_interface_{std::move(cl_iface)}, storage_{} @@ -87,9 +99,9 @@ public: template error_or< id< - typename schema_member_type::type::ValueType::ResponseT + typename schema_member_type::type::ResponseT > - > call(data_or_id::type::ValueType::RequestT, Encoding> input){ + > call(data_or_id::type::RequestT, Encoding> input){ auto eod = cl_interface_.template call(std::move(input), &cmd_queue_); @@ -97,7 +109,9 @@ public: return std::move(eod.get_error()); } - return id::type::ValueType::ResponseT>{}; + // using ResponseTMap = id_map> + + return id::type::ResponseT>{}; } }; @@ -139,8 +153,10 @@ public: * Spin up a rpc server */ template - conveyor> listen(const remote_address&){ - return {}; + rpc_server listen(const remote_address&, typename rpc_server::InterfaceT iface){ + using RpcServerT = rpc_server; + using InterfaceT = typename RpcServerT::InterfaceT; + return {std::move(iface)}; } }; diff --git a/modules/remote-sycl/examples/SConscript b/modules/remote-sycl/examples/SConscript new file mode 100644 index 0000000..7fa9429 --- /dev/null +++ b/modules/remote-sycl/examples/SConscript @@ -0,0 +1,31 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +examples_env = env.Clone(); + +examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp")) + +env.sources += examples_env.sources; +env.headers += examples_env.headers; + +objects_static = [] +examples_env.sycl_basic = examples_env.Program('#bin/sycl_basic', ['sycl_basic.cpp', env.library_static]); + +# Set Alias +env.examples = [examples_env.sycl_basic]; +env.Alias('examples', env.examples); + +if env["build_examples"]: + env.targets += ['examples']; + env.Install('$prefix/bin/', env.examples); +#endif diff --git a/modules/remote-sycl/examples/sycl_basic.cpp b/modules/remote-sycl/examples/sycl_basic.cpp new file mode 100644 index 0000000..a180d23 --- /dev/null +++ b/modules/remote-sycl/examples/sycl_basic.cpp @@ -0,0 +1,47 @@ +#include "../c++/remote.hpp" + +namespace schema { +using namespace saw::schema; + +using BasicInterface = Interface< + Member, "increment"> +>; +} + +int main(){ + saw::remote remote_ctx; + + saw::own> rmt_addr{}; + + saw::event_loop loop; + saw::wait_scope wait{loop}; + + remote_ctx.resolve_address().then([&](auto addr){ + rmt_addr = std::move(addr); + }).detach(); + + wait.poll(); + + if(!rmt_addr){ + return -1; + } + + saw::interface, cl::sycl::queue*> iface{ + [](saw::data in, cl::sycl::queue* q) -> saw::data { + return {in.get() + 1u}; + } + }; + auto rpc_server = remote_ctx.template listen>(*rmt_addr, std::move(iface)); + + { + auto eov = rpc_server.template call<"increment">({1u}); + if(eov.is_error()){ + return -2; + } + auto& val = eov.get_value(); + std::cout<<"Value: "<, 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