summaryrefslogtreecommitdiff
path: root/modules/remote-sycl/c++
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-06-12 17:15:34 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-06-12 17:15:34 +0200
commite2a7609028346c3b776a424c9be848e49d3a0e2e (patch)
treeed4d8adf8b82a6442514da467406c6bc3d3fc312 /modules/remote-sycl/c++
parente4e49a117702945066e3e279fa0f005200400cb7 (diff)
Working on reference types in std::function deduction
Diffstat (limited to 'modules/remote-sycl/c++')
-rw-r--r--modules/remote-sycl/c++/remote.hpp79
1 files changed, 46 insertions, 33 deletions
diff --git a/modules/remote-sycl/c++/remote.hpp b/modules/remote-sycl/c++/remote.hpp
index d956314..a2b5a87 100644
--- a/modules/remote-sycl/c++/remote.hpp
+++ b/modules/remote-sycl/c++/remote.hpp
@@ -17,16 +17,16 @@ class remote<rmt::Sycl>;
/**
* Remote data class for the Sycl backend.
*/
-template<typename T, typename Encoding>
-class remote_data<T, Encoding, rmt::Sycl> {
+template<typename T, typename Encoding, typename Storage>
+class remote_data<T, Encoding, Storage, rmt::Sycl> {
private:
id<T> id_;
- id_map<T,Encoding>* map_;
+ id_map<T,Encoding,rmt::Sycl>* map_;
public:
/**
* Main constructor
*/
- remote_data(const id<T>& id, id_map<T, Encoding>& map):
+ remote_data(const id<T>& id, id_map<T, Encoding, rmt::Sycl>& map):
id_{id},
map_{&map}
{}
@@ -34,14 +34,14 @@ public:
/**
* Request data asynchronously
*/
- conveyor<data<T,Encoding>> on_receive(); /// Stopped here
+ conveyor<data<T,Encoding,Storage>> on_receive(); /// Stopped here
};
/**
*
*/
template<typename T, uint64_t N>
-class data<schema::Primitive<T,N>, encode::Native<rmt::Sycl>> {
+class data<schema::Primitive<T,N>, encode::Native, rmt::Sycl> {
public:
using Schema = schema::Primitive<T,N>;
using NativeType = typename native_data_type<Schema>::type;
@@ -64,7 +64,7 @@ public:
};
template<typename T, uint64_t D>
-class data<schema::Array<T,D>, encode::Native<rmt::Sycl>> {
+class data<schema::Array<T,D>, encode::Native, rmt::Sycl> {
public:
using Schema = schema::Array<T,D>;
private:
@@ -86,8 +86,8 @@ public:
}
}
- template<typename Encoding>
- data(const data<Schema, Encoding>& from, cl::sycl::queue& q__):
+ template<typename Encoding, typename Storage>
+ data(const data<Schema, Encoding, Storage>& from, cl::sycl::queue& q__):
total_length_{from.size()},
device_data_{cl::sycl::malloc_device<typename native_data_type<T>::type>(from.size(), q__)},
queue_{&q__}
@@ -105,28 +105,32 @@ public:
}
}
- data<T,encode::Native<rmt::Sycl>>& at(uint64_t i){
+ // data<T,encode::Native,rmt::Sycl>& at(uint64_t i){
+ typename native_data_type<T>::type& at(uint64_t i){
return device_data_[i];
}
+
+ uint64_t size() const {
+ return total_length_;
+ }
};
namespace impl {
-
-template<typename Iface, typename Encoding>
+template<typename Iface, typename Encoding, typename Storage>
struct rpc_id_map_helper {
- static_assert(always_false<Iface, Encoding>, "Only support Interface schema types.");
+ static_assert(always_false<Iface, Encoding,Storage>, "Only supports Interface schema types.");
};
-template<typename... Members, typename Encoding>
-struct rpc_id_map_helper<schema::Interface<Members...>, Encoding> {
- std::tuple<id_map<typename Members::ValueType::ResponseT, Encoding>...> maps;
+template<typename... Members, typename Encoding, typename Storage>
+struct rpc_id_map_helper<schema::Interface<Members...>, Encoding, Storage> {
+ std::tuple<id_map<typename Members::ValueType::ResponseT, Encoding, Storage>...> maps;
};
}
/**
* Rpc Client class for the Sycl backend.
*/
-template<typename Iface, typename Encoding>
-class rpc_client<Iface, Encoding, rmt::Sycl> {
+template<typename Iface, typename Encoding, typename Storage>
+class rpc_client<Iface, Encoding, Storage, rmt::Sycl> {
public:
private:
/**
@@ -141,12 +145,13 @@ public:
/**
* Rpc call
*/
- template<string_literal Name, typename ClientEncoding>
+ template<string_literal Name>
error_or<
id<
typename schema_member_type<Name, Iface>::type::ResponseT
>
- > call(data_or_id<typename schema_member_type<Name, Iface>::type::RequestT, ClientEncoding> input){
+ > call(data_or_id<typename schema_member_type<Name, Iface>::type::RequestT, Encoding, Storage> input){
+ (void) input;
return make_error<err::not_implemented>("RpcClient side is not implemented");
}
@@ -159,7 +164,7 @@ template<typename Iface, typename Encoding>
class rpc_server<Iface, Encoding, rmt::Sycl> {
public:
using InterfaceCtxT = cl::sycl::queue*;
- using InterfaceT = interface<Iface, Encoding, InterfaceCtxT>;
+ using InterfaceT = interface<Iface, Encoding, rmt::Sycl, InterfaceCtxT>;
private:
/**
* Command queue for the sycl backend
@@ -169,22 +174,23 @@ private:
/**
* The interface including the relevant context class.
*/
- interface<Iface, Encoding, InterfaceCtxT> cl_interface_;
+ interface<Iface, Encoding, rmt::Sycl, InterfaceCtxT> cl_interface_;
/**
* Basic storage for response data.
*/
- impl::rpc_id_map_helper<Iface, Encoding> storage_;
+ impl::rpc_id_map_helper<Iface, Encoding, rmt::Sycl> storage_;
public:
- rpc_server(interface<Iface, Encoding, InterfaceCtxT> cl_iface):
+ rpc_server(interface<Iface, Encoding, rmt::Sycl, InterfaceCtxT> 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 {dat, std::get<id_map<IdT, Encoding>>(storage_.maps)};
+ template<typename IdT, typename Storage>
+ remote_data<IdT, Encoding, Storage, rmt::Sycl> request_data(id<IdT> dat){
+ /// @TODO Fix so I can receive data
+ return {dat, std::get<id_map<IdT, Encoding,rmt::Sycl>>(storage_.maps)};
}
/**
@@ -195,23 +201,30 @@ public:
id<
typename schema_member_type<Name, Iface>::type::ResponseT
>
- > call(data_or_id<typename schema_member_type<Name, Iface>::type::RequestT, ClientAllocation> input){
+ > call(data_or_id<typename schema_member_type<Name, Iface>::type::RequestT, Encoding, ClientAllocation> input){
+ using FuncT = typename schema_member_type<Name, Iface>::type;
/**
+ * Object needed if and only if the provided data type is not an id
+ */
+ own<data<typename FuncT::RequestT, Encoding, rmt::Sycl>> 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.
*/
- auto eoinp = [&,this]() -> error_or<data<typename schema_member_type<Name, Iface>::type::RequestT, Encoding>* > {
+ auto eoinp = [&,this]() -> error_or<data<typename FuncT::RequestT, Encoding, rmt::Sycl>* > {
if(input.is_id()){
// storage_.maps
- auto& inner_map = std::get<id_map<typename schema_member_type<Name, Iface>::type::RequestT, Encoding >> (storage_.maps);
+ auto& inner_map = std::get<id_map<typename FuncT::RequestT, Encoding, rmt::Sycl>> (storage_.maps);
auto eov = inner_map.find(input.get_id());
if(eov.is_error()){
return std::move(eov.get_error());
}
return eov.get_value();
} else {
- return &input.get_data();
+ auto& client_data = input.get_data();
+ dev_tmp_inp = heap<data<typename FuncT::RequestT, Encoding, rmt::Sycl>>(client_data, cmd_queue_);
+ return dev_tmp_inp.get();
}
}();
if(eoinp.is_error()){
@@ -219,7 +232,7 @@ public:
}
auto& inp = *(eoinp.get_value());
- auto eod = cl_interface_.template call<Name>(std::move(inp), &cmd_queue_);
+ auto eod = cl_interface_.template call<Name>(inp, &cmd_queue_);
if(eod.is_error()){
return std::move(eod.get_error());
@@ -229,7 +242,7 @@ public:
* Store returned data in rpc storage
*/
auto& val = eod.get_value();
- auto& inner_map = std::get<id_map<typename schema_member_type<Name, Iface>::type::RequestT, Encoding >> (storage_.maps);
+ auto& inner_map = std::get<id_map<typename schema_member_type<Name, Iface>::type::RequestT, Encoding,rmt::Sycl>> (storage_.maps);
auto eoid = inner_map.insert(std::move(val));
if(eoid.is_error()){
return std::move(eoid.get_error());