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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#pragma once
#include <forstio/io_codec/rpc.hpp>
#include <forstio/codec/data.hpp>
#include <forstio/id_map.hpp>
#include <CL/sycl.hpp>
namespace saw {
namespace rmt {
struct Sycl {};
}
template<>
class remote<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>{};
}
};
template<>
struct remote_address<rmt::Sycl> {
private:
remote<rmt::Sycl>* ctx_;
SAW_FORBID_COPY(remote_address);
SAW_FORBID_MOVE(remote_address);
public:
remote_address(remote<rmt::Sycl>& r_ctx):
ctx_{&r_ctx}
{}
};
template<>
class remote<rmt::Sycl> {
private:
SAW_FORBID_COPY(remote);
SAW_FORBID_MOVE(remote);
public:
/**
* Default constructor
*/
remote(){}
/**
* For now we don't need to specify the location since
* we just create a default.
*/
conveyor<own<remote_address<rmt::Sycl>>> resolve_address(){
return heap<remote_address<rmt::Sycl>>(*this);
}
/**
* Spin up a rpc server
*/
template<typename Iface, typename Encoding>
conveyor<rpc_server<Iface, Encoding, rmt::Sycl>> listen(const remote_address<rmt::Sycl>&){
return {};
}
};
}
|