summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2024-05-29 21:16:06 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2024-05-29 21:16:06 +0200
commit60d0f8da2b754d1deb0dbb59f6e6783ba4c692c4 (patch)
treec0d49736f035220640ed01cfb210d37e7bb254cb
parent7b6e0ca99f8521e034452f0d0243a7f3e33843a9 (diff)
Reworked id_map and trying to fix sycl launch
-rw-r--r--modules/codec/c++/id_map.hpp (renamed from modules/core/c++/id_map.hpp)14
-rw-r--r--modules/codec/tests/codec.cpp1
-rw-r--r--modules/core/tests/core.cpp27
-rw-r--r--modules/io_codec/c++/rpc.hpp42
-rw-r--r--modules/remote-sycl/c++/remote.hpp51
5 files changed, 87 insertions, 48 deletions
diff --git a/modules/core/c++/id_map.hpp b/modules/codec/c++/id_map.hpp
index 1df2178..bb31846 100644
--- a/modules/core/c++/id_map.hpp
+++ b/modules/codec/c++/id_map.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "id.hpp"
-#include "error.hpp"
+#include <forstio/id.hpp>
+#include <forstio/error.hpp>
#include <deque>
@@ -13,13 +13,13 @@ namespace saw {
* Insert - O(1)
* Erase - O(n) ? Dunno
*/
-template<typename T>
+template<typename T, typename Encoding>
class id_map final {
private:
/**
* Container which stores the primary data
*/
- std::vector<T> data_;
+ std::vector<data<T,Encoding>> data_;
/**
* Container which tracks free'd/fragmented elements within the
* main container
@@ -65,7 +65,7 @@ public:
* Inserts an element into the container and returns either an id on success
* or an error on failure.
*/
- error_or<id<T>> insert(T val) noexcept {
+ error_or<id<T>> insert(data<T,Encoding> val) noexcept {
/// @todo Fix size_t and id base type
if(free_ids_.empty()){
try {
@@ -88,7 +88,7 @@ public:
}
/**
- * Erase a value at this id.
+ * Erase a value at this id. If this id isn't in the map, then it returns an error.
*/
error_or<void> erase(const id<T>& val) noexcept {
/**
@@ -145,7 +145,7 @@ public:
* Returns an error on failure and returns
* a value pointer on success.
*/
- error_or<T*> find(const id<T>& val){
+ error_or<data<T,Encoding>*> find(const id<T>& val){
if(val.get_value() >= data_.size()){
return make_error<err::not_found>("ID is too large");
}
diff --git a/modules/codec/tests/codec.cpp b/modules/codec/tests/codec.cpp
index b67d70d..e8a2fb3 100644
--- a/modules/codec/tests/codec.cpp
+++ b/modules/codec/tests/codec.cpp
@@ -1,5 +1,6 @@
#include <forstio/test/suite.hpp>
#include "../c++/data.hpp"
+#include "../c++/id_map.hpp"
#include "../c++/simple.hpp"
#include "../c++/interface.hpp"
diff --git a/modules/core/tests/core.cpp b/modules/core/tests/core.cpp
index 48a25ea..b1ce741 100644
--- a/modules/core/tests/core.cpp
+++ b/modules/core/tests/core.cpp
@@ -1,6 +1,5 @@
#include "../c++/test/suite.hpp"
#include "../c++/id.hpp"
-#include "../c++/id_map.hpp"
#include "../c++/string_literal.hpp"
namespace {
@@ -38,30 +37,4 @@ SAW_TEST("String Literal Append"){
SAW_EXPECT(c == "foobar", "CT String sum is not \"foobar\"");
}
-
-SAW_TEST("ID Map Insert"){
- using namespace saw;
-
- struct foo {};
-
- id_map<foo> map;
- {
- auto eoid = map.insert(foo{});
- SAW_EXPECT(eoid.is_value(), "First insert failed");
-
- auto& id = eoid.get_value();
-
- auto eoid_2 = map.insert(foo{});
- SAW_EXPECT(eoid_2.is_value(), "Second Insert failed");
- auto& id_2 = eoid_2.get_value();
-
- SAW_EXPECT(id != id_2, "Shouldn't be equal");
-
- auto eov = map.erase(id);
- SAW_EXPECT(eov.is_value(), "Erase failed");
-
- auto eov_2 = map.erase(id);
- SAW_EXPECT(eov_2.is_error(), "This is a double free");
- }
-}
}
diff --git a/modules/io_codec/c++/rpc.hpp b/modules/io_codec/c++/rpc.hpp
index 66b7c41..04293cd 100644
--- a/modules/io_codec/c++/rpc.hpp
+++ b/modules/io_codec/c++/rpc.hpp
@@ -11,27 +11,63 @@
namespace saw {
/**
- *
+ * This class acts as a helper for rpc calls and representing data on the remote.
*/
template<typename T, typename Encoding>
class data_or_id {
private:
+ /**
+ * Variant representing the either id or data class.
+ */
std::variant<id<T>, data<T,Encoding>> doi_;
public:
+ /**
+ * Constructor for instantiating.
+ */
data_or_id(const id<T>& val):
doi_{val}
{}
+ /**
+ * Constructor for instantiating.
+ */
data_or_id(data<T,Encoding> val):
doi_{std::move(val)}
{}
+ /**
+ * Check if this class holds an id.
+ */
bool is_id() const {
- return false;
+ return std::holds_alternative<id<T>>(doi_);
}
+ /**
+ * Check if this class holds data.
+ */
bool is_data() const {
- return false;
+ return std::holds_alternative<data<T,Encoding>>(doi_);
+ }
+
+ /**
+ * Returns the id.
+ */
+ id<T> get_id() const {
+ return std::get<id<T>>(doi_);
+ }
+
+ /**
+ * Return a data reference.
+ */
+ data<T,Encoding>& get_data(){
+ return std::get<data<T,Encoding>>(doi_);
+ }
+
+ /**
+ * Return a data reference.
+ */
+ const data<T,Encoding>& get_data() const {
+ return std::get<data<T,Encoding>>(doi_);
}
};
diff --git a/modules/remote-sycl/c++/remote.hpp b/modules/remote-sycl/c++/remote.hpp
index d4b114a..003dd0e 100644
--- a/modules/remote-sycl/c++/remote.hpp
+++ b/modules/remote-sycl/c++/remote.hpp
@@ -2,7 +2,7 @@
#include <forstio/io_codec/rpc.hpp>
#include <forstio/codec/data.hpp>
-#include <forstio/id_map.hpp>
+#include <forstio/codec/id_map.hpp>
#include <CL/sycl.hpp>
@@ -21,12 +21,12 @@ template<typename T, typename Encoding>
class remote_data<T, Encoding, rmt::Sycl> {
private:
id<T> id_;
- id_map<T>* map_;
+ id_map<T,Encoding>* map_;
public:
/**
* Main constructor
*/
- remote_data(const id<T>& id, id_map<data<T, Encoding>>& map):
+ remote_data(const id<T>& id, id_map<T, Encoding>& map):
id_{id},
map_{&map}
{}
@@ -55,7 +55,7 @@ struct rpc_id_map_helper {
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;
+ std::tuple<id_map<typename Members::ValueType::ResponseT, Encoding>...> maps;
};
}
/**
@@ -78,7 +78,7 @@ private:
interface<Iface, Encoding, InterfaceCtxT> cl_interface_;
/**
- *
+ * Basic storage for response data.
*/
impl::rpc_id_map_helper<Iface, Encoding> storage_;
public:
@@ -90,11 +90,11 @@ public:
template<typename IdT>
remote_data<IdT, Encoding, rmt::Sycl> request_data(id<IdT> dat){
- return {dat, std::get<id_map<data<IdT, Encoding>>>(storage_.maps)};
+ return {dat, std::get<id_map<IdT, Encoding>>(storage_.maps)};
}
/**
- * rpc call
+ * Rpc call
*/
template<string_literal Name>
error_or<
@@ -103,15 +103,44 @@ public:
>
> call(data_or_id<typename schema_member_type<Name, Iface>::type::RequestT, Encoding> input){
- auto eod = cl_interface_.template call<Name>(std::move(input), &cmd_queue_);
+ /**
+ * 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>* > {
+ 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 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();
+ }
+ }();
+ if(eoinp.is_error()){
+ return std::move(eoinp.get_error());
+ }
+ auto& inp = *(eoinp.get_value());
+
+ auto eod = cl_interface_.template call<Name>(std::move(inp), &cmd_queue_);
if(eod.is_error()){
return std::move(eod.get_error());
}
- // using ResponseTMap = id_map<data<>>
-
- return id<typename schema_member_type<Name, Iface>::type::ResponseT>{};
+ /**
+ * 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 eoid = inner_map.insert(std::move(val));
+ if(eoid.is_error()){
+ return std::move(eoid.get_error());
+ }
+ return eoid.get_value();
}
};