diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-05-17 18:14:41 +0200 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-05-17 18:14:41 +0200 |
commit | 7479b39379bcf79dfa73a61643538832c2571c49 (patch) | |
tree | 115666ec7696d12df2a9449e18f1fc5d4cf76cb8 /modules | |
parent | 059dc4308ac731d2b3c324166d87b8d527b9d217 (diff) |
Trying to get rpc interaction with iface working
Diffstat (limited to 'modules')
-rw-r--r-- | modules/codec/c++/interface.hpp | 8 | ||||
-rw-r--r-- | modules/core/c++/id_map.hpp | 16 | ||||
-rw-r--r-- | modules/io_codec/c++/rpc.hpp | 43 | ||||
-rw-r--r-- | 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<typename Iface, typename Encode> -class i_interface { -public: - virtual ~i_interface() = default; - - -}; - template<typename T, typename Encode, typename Context = void_t > 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<T*> find(const id<T>& val){ + if(val.get_value() >= data_.size()){ + return make_error<err::not_found>("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<err::not_found>("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 <forstio/codec/interface.hpp> +#include <variant> + namespace saw { /** + * + */ +template<typename T, typename Encoding> +class data_or_id { +private: + std::variant<id<T>, data<T,Encoding>> doi_; +public: + data_or_id(const id<T>& val): + doi_{val} + {} + + data_or_id(data<T,Encoding> val): + doi_{std::move(val)} + {} + + bool is_id() const { + return false; + } + + bool is_data() const { + return false; + } +}; + +/** * Representing data on the remote */ -template<typename T, typename Remote> +template<typename T, typename Encoding, typename Remote> class remote_data { private: id<T> id_; @@ -23,24 +50,24 @@ public: /** * Wait until data arrives */ - error_or<data<T>> wait(wait_scope& wait); + error_or<data<T, Encoding>> wait(wait_scope& wait); /** * Asynchronously wait for a result */ - conveyor<data<T>> on_receive(); + conveyor<data<T, Encoding>> on_receive(); }; /** * Client RPC reference structure */ -template<typename Iface, typename Encode, typename Remote> +template<typename Iface, typename Encoding, typename Remote> class rpc_client { /** * request the data from the remote */ template<typename IdT> - remote_data<IdT, Remote> request_data(id<IdT> data); + remote_data<IdT, Encoding, Remote> request_data(id<IdT> data); /** @todo * Determine type based on Name @@ -58,12 +85,12 @@ class rpc_client { /** * Implementation of a remote server on the backend */ -template<typename Iface, typename Encode, typename Remote> +template<typename Iface, typename Encoding, typename Remote> class rpc_server { private: - interface<Iface, Encode> iface_; + interface<Iface, Encoding> iface_; public: - rpc_server(interface<Iface, Encode> iface): + rpc_server(interface<Iface, Encoding> 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 <forstio/io_codec/rpc.hpp> +#include <forstio/codec/data.hpp> +#include <forstio/id_map.hpp> #include <CL/sycl.hpp> @@ -12,12 +14,91 @@ struct Sycl {}; template<> class remote<rmt::Sycl>; -template<typename Iface, typename Encode> -class rpc_server<Iface, Encode, rmt::Sycl> { +/** + * Remote data class for the Sycl backend. + */ +template<typename T, typename Encoding> +class remote_data<T, Encoding, rmt::Sycl> { private: + id<T> id_; + id_map<T>* map_; +public: + /** + * Main constructor + */ + remote_data(const id<T>& id, id_map<data<T, Encoding>>& map): + id_{id}, + map_{&map} + {} + + /** + * Request data asynchronously + */ + conveyor<data<T,Encoding>> on_receive(); /// Stopped here +}; +namespace impl { + +template<typename Iface, typename Encoding> +struct rpc_id_map_helper { + static_assert(always_false<Iface, Encoding>, "Only support Interface schema types."); +}; + +template<typename... Members, typename Encoding> +struct rpc_id_map_helper<schema::Interface<Members...>, Encoding> { + std::tuple<id_map<data<typename Members::ValueType::ResponseT, Encoding>>...> maps; +}; +} +/** + * Rpc Server class for the Sycl backend. + */ +template<typename Iface, typename Encoding> +class rpc_server<Iface, Encoding, rmt::Sycl> { +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<Iface, Encoding, IfaceCtx> cl_interface_; + + /** + * + */ + impl::rpc_id_map_helper<Iface, Encoding> storage_; public: + rpc_server(interface<Iface, Encoding, IfaceCtx> cl_iface): + cmd_queue_{}, + cl_interface_{std::move(cl_iface)}, + storage_{} + {} + template<typename IdT> + remote_data<IdT, Encoding, rmt::Sycl> request_data(id<IdT> dat){ + return {data, std::get<id_map<data<IdT, Encoding>>>(storage_.maps)}; + } + + /** + * rpc call + */ + template<string_literal Name> + error_or< + id< + typename schema_member_type<Name, Iface>::type::ValueType::ResponseT + > + > call(data_or_id<typename schema_member_type<Name, Iface>::type::ValueType::RequestT, Encoding> input){ + + auto eod = cmd_queue_.template call<Name>(std::move(input), &cmd_queue_); + + if(eod.is_error()){ + return std::move(eod.get_error()); + } + + return id<typename schema_member_type<Name, Iface>::type::ValueType::ResponseT>{}; + } }; @@ -59,7 +140,7 @@ public: */ template<typename Iface, typename Encoding> conveyor<rpc_server<Iface, Encoding, rmt::Sycl>> listen(const remote_address<rmt::Sycl>&){ - + return {}; } }; |