From 729307460e77f62a532ee9841dcaed9c47f46419 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Wed, 26 Jun 2024 09:39:34 +0200 Subject: Added better structure for the data server --- modules/remote-sycl/c++/remote.hpp | 138 +++++++++++-------------------------- 1 file changed, 41 insertions(+), 97 deletions(-) (limited to 'modules/remote-sycl/c++/remote.hpp') diff --git a/modules/remote-sycl/c++/remote.hpp b/modules/remote-sycl/c++/remote.hpp index 2d0eaea..1ae3103 100644 --- a/modules/remote-sycl/c++/remote.hpp +++ b/modules/remote-sycl/c++/remote.hpp @@ -2,28 +2,10 @@ #include "common.hpp" #include "data.hpp" +#include "device.hpp" +#include "transfer.hpp" namespace saw { - -template -class data { -private: - cl::sycl::buffer> data_; -public: - data(data& data__): - data_{&data__, 1u} - {} - - auto& get_handle() { - return data_; - } - - template - auto access(cl::sycl::handler& h){ - return data_.template get_access(h); - } -}; - /** * Remote data class for the Sycl backend. */ @@ -78,35 +60,22 @@ public: /** * Meant to be a helper object which holds the allocated data on the sycl side */ -template -class device_data; +//template +//class device_data; /** * This class helps in regards to the ownership on the server side - */ template class device_data { private: - /** - * The actual data - */ data* device_data_; - /** - * The sycl queue object - */ cl::sycl::queue* queue_; public: - /** - * Main constructor - */ device_data(data& device_data__, cl::sycl::queue& queue__): device_data_{&device_data__}, queue_{&queue__} {} - /** - * Destructor specifically designed to deallocate on the device. - */ ~device_data(){ if(device_data_){ cl::sycl::free(device_data_,queue_); @@ -117,64 +86,33 @@ public: SAW_FORBID_COPY(device_data); SAW_FORBID_MOVE(device_data); }; - -namespace impl { -template -struct device_id_map { - std::vector> data; -}; - -template -struct rpc_id_map_helper { - static_assert(always_false, "Only supports Interface schema types."); -}; - -template -struct rpc_id_map_helper, Encoding, Storage> { - std::tuple...> maps; -}; -} + */ } // Maybe a helper impl tmpl file? namespace saw { -/** - * Represents a remote Sycl device. - */ -template<> -class device final { -private: - cl::sycl::queue cmd_queue_; -public: - device() = default; - SAW_FORBID_COPY(device); - SAW_FORBID_MOVE(device); +namespace impl { +template +struct rpc_func_type_helper; - /** - * Copy data to device - */ - template - error_or> copy_to_device(const data& host_data){ - return data::copy_to_device(host_data, *this); - } - - /** - * Copy data to host - */ - template - error_or> copy_to_host(const data& device_data){ - return device_data.copy_to_host(); - } - - /** - * Get a reference to the handle - */ - cl::sycl::queue& get_handle(){ - return cmd_queue_; - } +template +struct rpc_func_type_helper>{ + using type = tmpl_group; +}; + +template +struct rpc_iface_type_helper { + using type = tmpl_group<>; +}; + +template +struct rpc_iface_type_helper,schema::Member...>> { + using inner_type = typename rpc_func_type_helper::type; + using type = typename tmpl_concat...>>::type>::type; }; +} /** * Rpc Client class for the Sycl backend. @@ -188,12 +126,18 @@ private: */ rpc_server* srv_; + /** + * TransferClient created from the internal RPC data server + */ + data_client::type, Encoding, rmt::Sycl> data_client_; + /** * Generated some sort of id for the request. */ public: rpc_client(rpc_server& srv): - srv_{&srv} + srv_{&srv}, + data_client_{srv_->data_server} {} /** @@ -219,6 +163,7 @@ class rpc_server { public: using InterfaceCtxT = cl::sycl::queue*; using InterfaceT = interface; + private: /** * Device instance enabling the use of the remote device. @@ -226,14 +171,15 @@ private: device* device_; /** - * The interface including the relevant context class. + * Data server storing the relevant data */ - interface cl_interface_; + data_server::type, Encoding, rmt::Sycl> data_server_; /** - * Basic storage for response data. + * The interface including the relevant context class. */ - impl::rpc_id_map_helper storage_; + interface cl_interface_; + public: /** @@ -241,8 +187,8 @@ public: */ rpc_server(device& dev__, InterfaceT cl_iface): device_{&dev__}, - cl_interface_{std::move(cl_iface)}, - storage_{} + data_server_{}, + cl_interface_{std::move(cl_iface)} {} /** @@ -276,7 +222,7 @@ public: /** * Object needed if and only if the provided data type is not an id */ - own> dev_tmp_inp = nullptr; + own> dev_tmp_inp = nullptr; /** * First check if it's data or an id. * If it's an id, check if it's registered within the storage and retrieve it. @@ -284,8 +230,7 @@ public: auto eoinp = [&,this]() -> error_or* > { if(input.is_id()){ // storage_.maps - auto& inner_map = std::get> (storage_.maps); - auto eov = inner_map.find(input.get_id()); + auto eov = data_server_.template find(input.get_id()); if(eov.is_error()){ return std::move(eov.get_error()); } @@ -319,8 +264,7 @@ public: /** * Store returned data in rpc storage */ - auto& inner_map = std::get::type::RequestT, Encoding,rmt::Sycl>> (storage_.maps); - auto eoid = inner_map.insert_as(std::move(val), rpc_id); + auto eoid = data_server_.template insert::type::RequestT>(std::move(val), rpc_id); if(eoid.is_error()){ return std::move(eoid.get_error()); } -- cgit v1.2.3