From 7479b39379bcf79dfa73a61643538832c2571c49 Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Fri, 17 May 2024 18:14:41 +0200 Subject: Trying to get rpc interaction with iface working --- modules/codec/c++/interface.hpp | 8 ---- modules/core/c++/id_map.hpp | 16 +++++++ modules/io_codec/c++/rpc.hpp | 43 +++++++++++++++---- modules/remote-sycl/c++/remote.hpp | 87 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 135 insertions(+), 19 deletions(-) diff --git a/modules/codec/c++/interface.hpp b/modules/codec/c++/interface.hpp index d6d02a3..8c6808b 100644 --- a/modules/codec/c++/interface.hpp +++ b/modules/codec/c++/interface.hpp @@ -43,14 +43,6 @@ public: } }; -template -class i_interface { -public: - virtual ~i_interface() = default; - - -}; - template class interface; diff --git a/modules/core/c++/id_map.hpp b/modules/core/c++/id_map.hpp index 6172840..e1c1b3f 100644 --- a/modules/core/c++/id_map.hpp +++ b/modules/core/c++/id_map.hpp @@ -139,5 +139,21 @@ public: ); return void_t{}; } + + error_or find(const id& val){ + if(val.get_value() >= data_.size()){ + return make_error("ID is too large"); + } + + /** + * This can be removed technically if we are not in a debug state? + */ + auto find_id = std::find(free_ids_.begin(), free_ids_.end(), val); + if(find_id != free_ids_.end()){ + return make_error("ID value has already been freed"); + } + + return &data_.at(val.get_value()); + } }; } diff --git a/modules/io_codec/c++/rpc.hpp b/modules/io_codec/c++/rpc.hpp index 547eea3..66b7c41 100644 --- a/modules/io_codec/c++/rpc.hpp +++ b/modules/io_codec/c++/rpc.hpp @@ -6,12 +6,39 @@ #include +#include + namespace saw { +/** + * + */ +template +class data_or_id { +private: + std::variant, data> doi_; +public: + data_or_id(const id& val): + doi_{val} + {} + + data_or_id(data val): + doi_{std::move(val)} + {} + + bool is_id() const { + return false; + } + + bool is_data() const { + return false; + } +}; + /** * Representing data on the remote */ -template +template class remote_data { private: id id_; @@ -23,24 +50,24 @@ public: /** * Wait until data arrives */ - error_or> wait(wait_scope& wait); + error_or> wait(wait_scope& wait); /** * Asynchronously wait for a result */ - conveyor> on_receive(); + conveyor> on_receive(); }; /** * Client RPC reference structure */ -template +template class rpc_client { /** * request the data from the remote */ template - remote_data request_data(id data); + remote_data request_data(id data); /** @todo * Determine type based on Name @@ -58,12 +85,12 @@ class rpc_client { /** * Implementation of a remote server on the backend */ -template +template class rpc_server { private: - interface iface_; + interface iface_; public: - rpc_server(interface iface): + rpc_server(interface iface): iface_{std::move(iface)} {} }; diff --git a/modules/remote-sycl/c++/remote.hpp b/modules/remote-sycl/c++/remote.hpp index 0d10ba7..70c8032 100644 --- a/modules/remote-sycl/c++/remote.hpp +++ b/modules/remote-sycl/c++/remote.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include @@ -12,12 +14,91 @@ struct Sycl {}; template<> class remote; -template -class rpc_server { +/** + * Remote data class for the Sycl backend. + */ +template +class remote_data { private: + id id_; + id_map* map_; +public: + /** + * Main constructor + */ + remote_data(const id& id, id_map>& map): + id_{id}, + map_{&map} + {} + + /** + * Request data asynchronously + */ + conveyor> on_receive(); /// Stopped here +}; +namespace impl { + +template +struct rpc_id_map_helper { + static_assert(always_false, "Only support Interface schema types."); +}; + +template +struct rpc_id_map_helper, Encoding> { + std::tuple>...> maps; +}; +} +/** + * Rpc Server class for the Sycl backend. + */ +template +class rpc_server { +private: + using IfaceCtx = cl::sycl::queue*; + /** + * Command queue for the sycl backend + */ cl::sycl::queue cmd_queue_; + + /** + * The interface including the relevant context class. + */ + interface cl_interface_; + + /** + * + */ + impl::rpc_id_map_helper storage_; public: + rpc_server(interface cl_iface): + cmd_queue_{}, + cl_interface_{std::move(cl_iface)}, + storage_{} + {} + template + remote_data request_data(id dat){ + return {data, std::get>>(storage_.maps)}; + } + + /** + * rpc call + */ + template + error_or< + id< + typename schema_member_type::type::ValueType::ResponseT + > + > call(data_or_id::type::ValueType::RequestT, Encoding> input){ + + auto eod = cmd_queue_.template call(std::move(input), &cmd_queue_); + + if(eod.is_error()){ + return std::move(eod.get_error()); + } + + return id::type::ValueType::ResponseT>{}; + } }; @@ -59,7 +140,7 @@ public: */ template conveyor> listen(const remote_address&){ - + return {}; } }; -- cgit v1.2.3