summaryrefslogtreecommitdiff
path: root/modules/remote-sycl/c++/transfer.hpp
blob: 6849caa24b487df32e25c2b3dadbf29c089a6a65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once

#include "common.hpp"
#include "data.hpp"
#include <forstio/error.hpp>

namespace saw {
template<typename Schema, typename Encoding>
class data_server<Schema, Encoding, rmt::Sycl> {
private:
	/**
	 * Device context class
	 */
	device<rmt::Sycl>* device_;

	/**
	 * Store for the data the server manages.
	 */
	std::unordered_map<uint64_t, data<Schema, Encoding, rmt::Sycl>> values_;
public:
	/**
	 * Main constructor
	 */
	data_server(device<rmt::Sycl>& device__):
		device_{&device__}
	{}

	/**
	 * Receive data which we will store.
	 */
	error_or<void> send(const data<Schema, Encoding, storage::Default>& dat, id<Schema> store_id){
		auto eoval = device_->copy_to_device(dat);
		if(eoval.is_error()){
			auto& err = eoval.get_error();
			return std::move(err);
		}
		return make_error<err::not_implemented>();
	}

	error_or<data<Schema, Encoding, storage::Default>> receive(id<Schema> store_id){
		return make_error<err::not_implemented>();
	}
};

template<typename Schema, typename Encoding>
class data_client<Schema, Encoding, rmt::Sycl> {
private:
	/**
	 * Corresponding server for this client
	 */
	data_server<Schema, Encoding, rmt::Sycl>* srv_;

	/**
	 * The next id for identifying issues on the remote side.
	 */
	uint64_t next_id_;
public:
	/**
	 * Main constructor
	 */
	data_client(data_server<Schema, Encoding, rmt::Sycl>& srv__):
		srv_{&srv__},
		next_id_{0u}
	{}

	/**
	 * Send data to.
	 */
	error_or<id<Schema>> send(const data<Schema, Encoding, storage::Default>& dat){
		id<Schema> dat_id{next_id_};
		auto eov = srv_->send(dat, dat_id);
		if(eov.is_error()){
			auto& err = eov.get_error();
			return std::move(err);
		}

		++next_id_;
		return dat_id;
	}
};
}