1ec8f4a38SAtmn Patel //===----------------- Client.cpp - Client Implementation -----------------===//
2ec8f4a38SAtmn Patel //
3ec8f4a38SAtmn Patel // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ec8f4a38SAtmn Patel // See https://llvm.org/LICENSE.txt for license information.
5ec8f4a38SAtmn Patel // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ec8f4a38SAtmn Patel //
7ec8f4a38SAtmn Patel //===----------------------------------------------------------------------===//
8ec8f4a38SAtmn Patel //
9ec8f4a38SAtmn Patel // gRPC (Client) for the remote plugin.
10ec8f4a38SAtmn Patel //
11ec8f4a38SAtmn Patel //===----------------------------------------------------------------------===//
12ec8f4a38SAtmn Patel
13ec8f4a38SAtmn Patel #include <cmath>
14ec8f4a38SAtmn Patel
15ec8f4a38SAtmn Patel #include "Client.h"
16ec8f4a38SAtmn Patel #include "omptarget.h"
17ec8f4a38SAtmn Patel #include "openmp.pb.h"
18ec8f4a38SAtmn Patel
19ec8f4a38SAtmn Patel using namespace std::chrono;
20ec8f4a38SAtmn Patel
21ec8f4a38SAtmn Patel using grpc::ClientContext;
22ec8f4a38SAtmn Patel using grpc::ClientReader;
23ec8f4a38SAtmn Patel using grpc::ClientWriter;
24ec8f4a38SAtmn Patel using grpc::Status;
25ec8f4a38SAtmn Patel
26ec8f4a38SAtmn Patel template <typename Fn1, typename Fn2, typename TReturn>
remoteCall(Fn1 Preprocessor,Fn2 Postprocessor,TReturn ErrorValue,bool CanTimeOut)27*21e92612SAtmn Patel auto RemoteOffloadClient::remoteCall(Fn1 Preprocessor, Fn2 Postprocessor,
28*21e92612SAtmn Patel TReturn ErrorValue, bool CanTimeOut) {
29ec8f4a38SAtmn Patel ArenaAllocatorLock->lock();
30ec8f4a38SAtmn Patel if (Arena->SpaceAllocated() >= MaxSize)
31ec8f4a38SAtmn Patel Arena->Reset();
32ec8f4a38SAtmn Patel ArenaAllocatorLock->unlock();
33ec8f4a38SAtmn Patel
34ec8f4a38SAtmn Patel ClientContext Context;
35*21e92612SAtmn Patel if (CanTimeOut) {
36ec8f4a38SAtmn Patel auto Deadline =
37ec8f4a38SAtmn Patel std::chrono::system_clock::now() + std::chrono::seconds(Timeout);
38ec8f4a38SAtmn Patel Context.set_deadline(Deadline);
39ec8f4a38SAtmn Patel }
40ec8f4a38SAtmn Patel
41ec8f4a38SAtmn Patel Status RPCStatus;
42*21e92612SAtmn Patel auto Reply = Preprocessor(RPCStatus, Context);
43ec8f4a38SAtmn Patel
44ec8f4a38SAtmn Patel if (!RPCStatus.ok()) {
45*21e92612SAtmn Patel CLIENT_DBG("%s", RPCStatus.error_message().c_str())
46ec8f4a38SAtmn Patel } else {
47*21e92612SAtmn Patel return Postprocessor(Reply);
48ec8f4a38SAtmn Patel }
49ec8f4a38SAtmn Patel
50*21e92612SAtmn Patel CLIENT_DBG("Failed")
51ec8f4a38SAtmn Patel return ErrorValue;
52ec8f4a38SAtmn Patel }
53ec8f4a38SAtmn Patel
shutdown(void)54ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::shutdown(void) {
55ec8f4a38SAtmn Patel ClientContext Context;
56ec8f4a38SAtmn Patel Null Request;
57ec8f4a38SAtmn Patel I32 Reply;
58*21e92612SAtmn Patel CLIENT_DBG("Shutting down server.")
59ec8f4a38SAtmn Patel auto Status = Stub->Shutdown(&Context, Request, &Reply);
60ec8f4a38SAtmn Patel if (Status.ok())
61ec8f4a38SAtmn Patel return Reply.number();
62ec8f4a38SAtmn Patel return 1;
63ec8f4a38SAtmn Patel }
64ec8f4a38SAtmn Patel
registerLib(__tgt_bin_desc * Desc)65ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::registerLib(__tgt_bin_desc *Desc) {
66ec8f4a38SAtmn Patel return remoteCall(
67*21e92612SAtmn Patel /* Preprocessor */
68ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
69ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<TargetBinaryDescription>(
70ec8f4a38SAtmn Patel Arena.get());
71ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
72ec8f4a38SAtmn Patel loadTargetBinaryDescription(Desc, *Request);
73ec8f4a38SAtmn Patel Request->set_bin_ptr((uint64_t)Desc);
74ec8f4a38SAtmn Patel
75ec8f4a38SAtmn Patel RPCStatus = Stub->RegisterLib(&Context, *Request, Reply);
76ec8f4a38SAtmn Patel return Reply;
77ec8f4a38SAtmn Patel },
78*21e92612SAtmn Patel /* Postprocessor */
79ec8f4a38SAtmn Patel [&](const auto &Reply) {
80ec8f4a38SAtmn Patel if (Reply->number() == 0) {
81*21e92612SAtmn Patel CLIENT_DBG("Registered library")
82ec8f4a38SAtmn Patel return 0;
83ec8f4a38SAtmn Patel }
84ec8f4a38SAtmn Patel return 1;
85ec8f4a38SAtmn Patel },
86ec8f4a38SAtmn Patel /* Error Value */ 1);
87ec8f4a38SAtmn Patel }
88ec8f4a38SAtmn Patel
unregisterLib(__tgt_bin_desc * Desc)89ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::unregisterLib(__tgt_bin_desc *Desc) {
90ec8f4a38SAtmn Patel return remoteCall(
91*21e92612SAtmn Patel /* Preprocessor */
92ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
93ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<Pointer>(Arena.get());
94ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
95ec8f4a38SAtmn Patel
96ec8f4a38SAtmn Patel Request->set_number((uint64_t)Desc);
97ec8f4a38SAtmn Patel
98ec8f4a38SAtmn Patel RPCStatus = Stub->UnregisterLib(&Context, *Request, Reply);
99ec8f4a38SAtmn Patel return Reply;
100ec8f4a38SAtmn Patel },
101*21e92612SAtmn Patel /* Postprocessor */
102ec8f4a38SAtmn Patel [&](const auto &Reply) {
103ec8f4a38SAtmn Patel if (Reply->number() == 0) {
104*21e92612SAtmn Patel CLIENT_DBG("Unregistered library")
105ec8f4a38SAtmn Patel return 0;
106ec8f4a38SAtmn Patel }
107*21e92612SAtmn Patel CLIENT_DBG("Failed to unregister library")
108ec8f4a38SAtmn Patel return 1;
109ec8f4a38SAtmn Patel },
110ec8f4a38SAtmn Patel /* Error Value */ 1);
111ec8f4a38SAtmn Patel }
112ec8f4a38SAtmn Patel
isValidBinary(__tgt_device_image * Image)113ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::isValidBinary(__tgt_device_image *Image) {
114ec8f4a38SAtmn Patel return remoteCall(
115*21e92612SAtmn Patel /* Preprocessor */
116ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
117ec8f4a38SAtmn Patel auto *Request =
118ec8f4a38SAtmn Patel protobuf::Arena::CreateMessage<TargetDeviceImagePtr>(Arena.get());
119ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
120ec8f4a38SAtmn Patel
121ec8f4a38SAtmn Patel Request->set_image_ptr((uint64_t)Image->ImageStart);
122ec8f4a38SAtmn Patel
123ec8f4a38SAtmn Patel auto *EntryItr = Image->EntriesBegin;
124ec8f4a38SAtmn Patel while (EntryItr != Image->EntriesEnd)
125ec8f4a38SAtmn Patel Request->add_entry_ptrs((uint64_t)EntryItr++);
126ec8f4a38SAtmn Patel
127ec8f4a38SAtmn Patel RPCStatus = Stub->IsValidBinary(&Context, *Request, Reply);
128ec8f4a38SAtmn Patel return Reply;
129ec8f4a38SAtmn Patel },
130*21e92612SAtmn Patel /* Postprocessor */
131ec8f4a38SAtmn Patel [&](const auto &Reply) {
132ec8f4a38SAtmn Patel if (Reply->number()) {
133*21e92612SAtmn Patel CLIENT_DBG("Validated binary")
134ec8f4a38SAtmn Patel } else {
135*21e92612SAtmn Patel CLIENT_DBG("Could not validate binary")
136ec8f4a38SAtmn Patel }
137ec8f4a38SAtmn Patel return Reply->number();
138ec8f4a38SAtmn Patel },
139ec8f4a38SAtmn Patel /* Error Value */ 0);
140ec8f4a38SAtmn Patel }
141ec8f4a38SAtmn Patel
getNumberOfDevices()142ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::getNumberOfDevices() {
143ec8f4a38SAtmn Patel return remoteCall(
144*21e92612SAtmn Patel /* Preprocessor */
145ec8f4a38SAtmn Patel [&](Status &RPCStatus, ClientContext &Context) {
146ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<Null>(Arena.get());
147ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
148ec8f4a38SAtmn Patel
149ec8f4a38SAtmn Patel RPCStatus = Stub->GetNumberOfDevices(&Context, *Request, Reply);
150ec8f4a38SAtmn Patel
151ec8f4a38SAtmn Patel return Reply;
152ec8f4a38SAtmn Patel },
153*21e92612SAtmn Patel /* Postprocessor */
154ec8f4a38SAtmn Patel [&](const auto &Reply) {
155ec8f4a38SAtmn Patel if (Reply->number()) {
156*21e92612SAtmn Patel CLIENT_DBG("Found %d devices", Reply->number())
157ec8f4a38SAtmn Patel } else {
158*21e92612SAtmn Patel CLIENT_DBG("Could not get the number of devices")
159ec8f4a38SAtmn Patel }
160ec8f4a38SAtmn Patel return Reply->number();
161ec8f4a38SAtmn Patel },
162ec8f4a38SAtmn Patel /*Error Value*/ -1);
163ec8f4a38SAtmn Patel }
164ec8f4a38SAtmn Patel
initDevice(int32_t DeviceId)165ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::initDevice(int32_t DeviceId) {
166ec8f4a38SAtmn Patel return remoteCall(
167*21e92612SAtmn Patel /* Preprocessor */
168ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
169ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<I32>(Arena.get());
170ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
171ec8f4a38SAtmn Patel
172ec8f4a38SAtmn Patel Request->set_number(DeviceId);
173ec8f4a38SAtmn Patel
174ec8f4a38SAtmn Patel RPCStatus = Stub->InitDevice(&Context, *Request, Reply);
175ec8f4a38SAtmn Patel
176ec8f4a38SAtmn Patel return Reply;
177ec8f4a38SAtmn Patel },
178*21e92612SAtmn Patel /* Postprocessor */
179ec8f4a38SAtmn Patel [&](const auto &Reply) {
180ec8f4a38SAtmn Patel if (!Reply->number()) {
181*21e92612SAtmn Patel CLIENT_DBG("Initialized device %d", DeviceId)
182ec8f4a38SAtmn Patel } else {
183*21e92612SAtmn Patel CLIENT_DBG("Could not initialize device %d", DeviceId)
184ec8f4a38SAtmn Patel }
185ec8f4a38SAtmn Patel return Reply->number();
186ec8f4a38SAtmn Patel },
187ec8f4a38SAtmn Patel /* Error Value */ -1);
188ec8f4a38SAtmn Patel }
189ec8f4a38SAtmn Patel
initRequires(int64_t RequiresFlags)190ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::initRequires(int64_t RequiresFlags) {
191ec8f4a38SAtmn Patel return remoteCall(
192*21e92612SAtmn Patel /* Preprocessor */
193ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
194ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<I64>(Arena.get());
195ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
196ec8f4a38SAtmn Patel Request->set_number(RequiresFlags);
197ec8f4a38SAtmn Patel RPCStatus = Stub->InitRequires(&Context, *Request, Reply);
198ec8f4a38SAtmn Patel return Reply;
199ec8f4a38SAtmn Patel },
200*21e92612SAtmn Patel /* Postprocessor */
201ec8f4a38SAtmn Patel [&](const auto &Reply) {
202ec8f4a38SAtmn Patel if (Reply->number()) {
203*21e92612SAtmn Patel CLIENT_DBG("Initialized requires")
204ec8f4a38SAtmn Patel } else {
205*21e92612SAtmn Patel CLIENT_DBG("Could not initialize requires")
206ec8f4a38SAtmn Patel }
207ec8f4a38SAtmn Patel return Reply->number();
208ec8f4a38SAtmn Patel },
209ec8f4a38SAtmn Patel /* Error Value */ -1);
210ec8f4a38SAtmn Patel }
211ec8f4a38SAtmn Patel
loadBinary(int32_t DeviceId,__tgt_device_image * Image)212ec8f4a38SAtmn Patel __tgt_target_table *RemoteOffloadClient::loadBinary(int32_t DeviceId,
213ec8f4a38SAtmn Patel __tgt_device_image *Image) {
214ec8f4a38SAtmn Patel return remoteCall(
215*21e92612SAtmn Patel /* Preprocessor */
216ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
217ec8f4a38SAtmn Patel auto *ImageMessage =
218ec8f4a38SAtmn Patel protobuf::Arena::CreateMessage<Binary>(Arena.get());
219ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<TargetTable>(Arena.get());
220ec8f4a38SAtmn Patel ImageMessage->set_image_ptr((uint64_t)Image->ImageStart);
221ec8f4a38SAtmn Patel ImageMessage->set_device_id(DeviceId);
222ec8f4a38SAtmn Patel
223ec8f4a38SAtmn Patel RPCStatus = Stub->LoadBinary(&Context, *ImageMessage, Reply);
224ec8f4a38SAtmn Patel return Reply;
225ec8f4a38SAtmn Patel },
226*21e92612SAtmn Patel /* Postprocessor */
227ec8f4a38SAtmn Patel [&](auto &Reply) {
228ec8f4a38SAtmn Patel if (Reply->entries_size() == 0) {
229*21e92612SAtmn Patel CLIENT_DBG("Could not load image %p onto device %d", Image, DeviceId)
230ec8f4a38SAtmn Patel return (__tgt_target_table *)nullptr;
231ec8f4a38SAtmn Patel }
232ec8f4a38SAtmn Patel DevicesToTables[DeviceId] = std::make_unique<__tgt_target_table>();
233ec8f4a38SAtmn Patel unloadTargetTable(*Reply, DevicesToTables[DeviceId].get(),
234ec8f4a38SAtmn Patel RemoteEntries[DeviceId]);
235ec8f4a38SAtmn Patel
236ec8f4a38SAtmn Patel CLIENT_DBG("Loaded Image %p to device %d with %d entries", Image,
237*21e92612SAtmn Patel DeviceId, Reply->entries_size())
238ec8f4a38SAtmn Patel
239ec8f4a38SAtmn Patel return DevicesToTables[DeviceId].get();
240ec8f4a38SAtmn Patel },
241ec8f4a38SAtmn Patel /* Error Value */ (__tgt_target_table *)nullptr,
242*21e92612SAtmn Patel /* CanTimeOut */ false);
243ec8f4a38SAtmn Patel }
244ec8f4a38SAtmn Patel
isDataExchangeable(int32_t SrcDevId,int32_t DstDevId)245ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::isDataExchangeable(int32_t SrcDevId,
246ec8f4a38SAtmn Patel int32_t DstDevId) {
247ec8f4a38SAtmn Patel return remoteCall(
248*21e92612SAtmn Patel /* Preprocessor */
249ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
250ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<DevicePair>(Arena.get());
251ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
252ec8f4a38SAtmn Patel
253ec8f4a38SAtmn Patel Request->set_src_dev_id(SrcDevId);
254ec8f4a38SAtmn Patel Request->set_dst_dev_id(DstDevId);
255ec8f4a38SAtmn Patel
256ec8f4a38SAtmn Patel RPCStatus = Stub->IsDataExchangeable(&Context, *Request, Reply);
257ec8f4a38SAtmn Patel return Reply;
258ec8f4a38SAtmn Patel },
259*21e92612SAtmn Patel /* Postprocessor */
260ec8f4a38SAtmn Patel [&](auto &Reply) {
261ec8f4a38SAtmn Patel if (Reply->number()) {
262*21e92612SAtmn Patel CLIENT_DBG("Data is exchangeable between %d, %d", SrcDevId, DstDevId)
263ec8f4a38SAtmn Patel } else {
264ec8f4a38SAtmn Patel CLIENT_DBG("Data is not exchangeable between %d, %d", SrcDevId,
265*21e92612SAtmn Patel DstDevId)
266ec8f4a38SAtmn Patel }
267ec8f4a38SAtmn Patel return Reply->number();
268ec8f4a38SAtmn Patel },
269ec8f4a38SAtmn Patel /* Error Value */ -1);
270ec8f4a38SAtmn Patel }
271ec8f4a38SAtmn Patel
dataAlloc(int32_t DeviceId,int64_t Size,void * HstPtr)272ec8f4a38SAtmn Patel void *RemoteOffloadClient::dataAlloc(int32_t DeviceId, int64_t Size,
273ec8f4a38SAtmn Patel void *HstPtr) {
274ec8f4a38SAtmn Patel return remoteCall(
275*21e92612SAtmn Patel /* Preprocessor */
276ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
277ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<Pointer>(Arena.get());
278ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<AllocData>(Arena.get());
279ec8f4a38SAtmn Patel
280ec8f4a38SAtmn Patel Request->set_device_id(DeviceId);
281ec8f4a38SAtmn Patel Request->set_size(Size);
282ec8f4a38SAtmn Patel Request->set_hst_ptr((uint64_t)HstPtr);
283ec8f4a38SAtmn Patel
284ec8f4a38SAtmn Patel RPCStatus = Stub->DataAlloc(&Context, *Request, Reply);
285ec8f4a38SAtmn Patel return Reply;
286ec8f4a38SAtmn Patel },
287*21e92612SAtmn Patel /* Postprocessor */
288ec8f4a38SAtmn Patel [&](auto &Reply) {
289ec8f4a38SAtmn Patel if (Reply->number()) {
290ec8f4a38SAtmn Patel CLIENT_DBG("Allocated %ld bytes on device %d at %p", Size, DeviceId,
291*21e92612SAtmn Patel (void *)Reply->number())
292ec8f4a38SAtmn Patel } else {
293ec8f4a38SAtmn Patel CLIENT_DBG("Could not allocate %ld bytes on device %d at %p", Size,
294*21e92612SAtmn Patel DeviceId, (void *)Reply->number())
295ec8f4a38SAtmn Patel }
296ec8f4a38SAtmn Patel return (void *)Reply->number();
297ec8f4a38SAtmn Patel },
298ec8f4a38SAtmn Patel /* Error Value */ (void *)nullptr);
299ec8f4a38SAtmn Patel }
300ec8f4a38SAtmn Patel
dataSubmit(int32_t DeviceId,void * TgtPtr,void * HstPtr,int64_t Size)301*21e92612SAtmn Patel int32_t RemoteOffloadClient::dataSubmit(int32_t DeviceId, void *TgtPtr,
302*21e92612SAtmn Patel void *HstPtr, int64_t Size) {
303ec8f4a38SAtmn Patel
304ec8f4a38SAtmn Patel return remoteCall(
305*21e92612SAtmn Patel /* Preprocessor */
306ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
307ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
308*21e92612SAtmn Patel std::unique_ptr<ClientWriter<SubmitData>> Writer(
309*21e92612SAtmn Patel Stub->DataSubmit(&Context, Reply));
310ec8f4a38SAtmn Patel
311ec8f4a38SAtmn Patel if (Size > BlockSize) {
312ec8f4a38SAtmn Patel int64_t Start = 0, End = BlockSize;
313ec8f4a38SAtmn Patel for (auto I = 0; I < ceil((float)Size / BlockSize); I++) {
314ec8f4a38SAtmn Patel auto *Request =
315*21e92612SAtmn Patel protobuf::Arena::CreateMessage<SubmitData>(Arena.get());
316ec8f4a38SAtmn Patel
317ec8f4a38SAtmn Patel Request->set_device_id(DeviceId);
318ec8f4a38SAtmn Patel Request->set_data((char *)HstPtr + Start, End - Start);
319ec8f4a38SAtmn Patel Request->set_hst_ptr((uint64_t)HstPtr);
320ec8f4a38SAtmn Patel Request->set_tgt_ptr((uint64_t)TgtPtr);
321ec8f4a38SAtmn Patel Request->set_start(Start);
322ec8f4a38SAtmn Patel Request->set_size(Size);
323ec8f4a38SAtmn Patel
324ec8f4a38SAtmn Patel if (!Writer->Write(*Request)) {
325*21e92612SAtmn Patel CLIENT_DBG("Broken stream when submitting data")
326ec8f4a38SAtmn Patel Reply->set_number(0);
327ec8f4a38SAtmn Patel return Reply;
328ec8f4a38SAtmn Patel }
329ec8f4a38SAtmn Patel
330ec8f4a38SAtmn Patel Start += BlockSize;
331ec8f4a38SAtmn Patel End += BlockSize;
332ec8f4a38SAtmn Patel if (End >= Size)
333ec8f4a38SAtmn Patel End = Size;
334ec8f4a38SAtmn Patel }
335ec8f4a38SAtmn Patel } else {
336ec8f4a38SAtmn Patel auto *Request =
337*21e92612SAtmn Patel protobuf::Arena::CreateMessage<SubmitData>(Arena.get());
338ec8f4a38SAtmn Patel
339ec8f4a38SAtmn Patel Request->set_device_id(DeviceId);
340ec8f4a38SAtmn Patel Request->set_data(HstPtr, Size);
341ec8f4a38SAtmn Patel Request->set_hst_ptr((uint64_t)HstPtr);
342ec8f4a38SAtmn Patel Request->set_tgt_ptr((uint64_t)TgtPtr);
343ec8f4a38SAtmn Patel Request->set_start(0);
344ec8f4a38SAtmn Patel Request->set_size(Size);
345ec8f4a38SAtmn Patel
346ec8f4a38SAtmn Patel if (!Writer->Write(*Request)) {
347*21e92612SAtmn Patel CLIENT_DBG("Broken stream when submitting data")
348ec8f4a38SAtmn Patel Reply->set_number(0);
349ec8f4a38SAtmn Patel return Reply;
350ec8f4a38SAtmn Patel }
351ec8f4a38SAtmn Patel }
352ec8f4a38SAtmn Patel
353ec8f4a38SAtmn Patel Writer->WritesDone();
354ec8f4a38SAtmn Patel RPCStatus = Writer->Finish();
355ec8f4a38SAtmn Patel
356ec8f4a38SAtmn Patel return Reply;
357ec8f4a38SAtmn Patel },
358*21e92612SAtmn Patel /* Postprocessor */
359ec8f4a38SAtmn Patel [&](auto &Reply) {
360ec8f4a38SAtmn Patel if (!Reply->number()) {
361*21e92612SAtmn Patel CLIENT_DBG(" submitted %ld bytes on device %d at %p", Size, DeviceId,
362*21e92612SAtmn Patel TgtPtr)
363ec8f4a38SAtmn Patel } else {
364ec8f4a38SAtmn Patel CLIENT_DBG("Could not async submit %ld bytes on device %d at %p",
365ec8f4a38SAtmn Patel Size, DeviceId, TgtPtr)
366ec8f4a38SAtmn Patel }
367ec8f4a38SAtmn Patel return Reply->number();
368ec8f4a38SAtmn Patel },
369ec8f4a38SAtmn Patel /* Error Value */ -1,
370*21e92612SAtmn Patel /* CanTimeOut */ false);
371ec8f4a38SAtmn Patel }
372ec8f4a38SAtmn Patel
dataRetrieve(int32_t DeviceId,void * HstPtr,void * TgtPtr,int64_t Size)373*21e92612SAtmn Patel int32_t RemoteOffloadClient::dataRetrieve(int32_t DeviceId, void *HstPtr,
374*21e92612SAtmn Patel void *TgtPtr, int64_t Size) {
375ec8f4a38SAtmn Patel return remoteCall(
376*21e92612SAtmn Patel /* Preprocessor */
377ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
378ec8f4a38SAtmn Patel auto *Request =
379*21e92612SAtmn Patel protobuf::Arena::CreateMessage<RetrieveData>(Arena.get());
380ec8f4a38SAtmn Patel
381ec8f4a38SAtmn Patel Request->set_device_id(DeviceId);
382ec8f4a38SAtmn Patel Request->set_size(Size);
383ec8f4a38SAtmn Patel Request->set_hst_ptr((int64_t)HstPtr);
384ec8f4a38SAtmn Patel Request->set_tgt_ptr((int64_t)TgtPtr);
385ec8f4a38SAtmn Patel
386ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<Data>(Arena.get());
387ec8f4a38SAtmn Patel std::unique_ptr<ClientReader<Data>> Reader(
388*21e92612SAtmn Patel Stub->DataRetrieve(&Context, *Request));
389ec8f4a38SAtmn Patel Reader->WaitForInitialMetadata();
390ec8f4a38SAtmn Patel while (Reader->Read(Reply)) {
391ec8f4a38SAtmn Patel if (Reply->ret()) {
392ec8f4a38SAtmn Patel CLIENT_DBG("Could not async retrieve %ld bytes on device %d at %p "
393ec8f4a38SAtmn Patel "for %p",
394ec8f4a38SAtmn Patel Size, DeviceId, TgtPtr, HstPtr)
395ec8f4a38SAtmn Patel return Reply;
396ec8f4a38SAtmn Patel }
397ec8f4a38SAtmn Patel
398ec8f4a38SAtmn Patel if (Reply->start() == 0 && Reply->size() == Reply->data().size()) {
399ec8f4a38SAtmn Patel memcpy(HstPtr, Reply->data().data(), Reply->data().size());
400ec8f4a38SAtmn Patel
401ec8f4a38SAtmn Patel return Reply;
402ec8f4a38SAtmn Patel }
403ec8f4a38SAtmn Patel
404ec8f4a38SAtmn Patel memcpy((void *)((char *)HstPtr + Reply->start()),
405ec8f4a38SAtmn Patel Reply->data().data(), Reply->data().size());
406ec8f4a38SAtmn Patel }
407ec8f4a38SAtmn Patel RPCStatus = Reader->Finish();
408ec8f4a38SAtmn Patel
409ec8f4a38SAtmn Patel return Reply;
410ec8f4a38SAtmn Patel },
411*21e92612SAtmn Patel /* Postprocessor */
412ec8f4a38SAtmn Patel [&](auto &Reply) {
413ec8f4a38SAtmn Patel if (!Reply->ret()) {
414*21e92612SAtmn Patel CLIENT_DBG("Retrieved %ld bytes on Device %d", Size, DeviceId)
415ec8f4a38SAtmn Patel } else {
416ec8f4a38SAtmn Patel CLIENT_DBG("Could not async retrieve %ld bytes on Device %d", Size,
417*21e92612SAtmn Patel DeviceId)
418ec8f4a38SAtmn Patel }
419ec8f4a38SAtmn Patel return Reply->ret();
420ec8f4a38SAtmn Patel },
421ec8f4a38SAtmn Patel /* Error Value */ -1,
422*21e92612SAtmn Patel /* CanTimeOut */ false);
423ec8f4a38SAtmn Patel }
424ec8f4a38SAtmn Patel
dataExchange(int32_t SrcDevId,void * SrcPtr,int32_t DstDevId,void * DstPtr,int64_t Size)425*21e92612SAtmn Patel int32_t RemoteOffloadClient::dataExchange(int32_t SrcDevId, void *SrcPtr,
426ec8f4a38SAtmn Patel int32_t DstDevId, void *DstPtr,
427*21e92612SAtmn Patel int64_t Size) {
428ec8f4a38SAtmn Patel return remoteCall(
429*21e92612SAtmn Patel /* Preprocessor */
430ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
431ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
432ec8f4a38SAtmn Patel auto *Request =
433*21e92612SAtmn Patel protobuf::Arena::CreateMessage<ExchangeData>(Arena.get());
434ec8f4a38SAtmn Patel
435ec8f4a38SAtmn Patel Request->set_src_dev_id(SrcDevId);
436ec8f4a38SAtmn Patel Request->set_src_ptr((uint64_t)SrcPtr);
437ec8f4a38SAtmn Patel Request->set_dst_dev_id(DstDevId);
438ec8f4a38SAtmn Patel Request->set_dst_ptr((uint64_t)DstPtr);
439ec8f4a38SAtmn Patel Request->set_size(Size);
440ec8f4a38SAtmn Patel
441*21e92612SAtmn Patel RPCStatus = Stub->DataExchange(&Context, *Request, Reply);
442ec8f4a38SAtmn Patel return Reply;
443ec8f4a38SAtmn Patel },
444*21e92612SAtmn Patel /* Postprocessor */
445ec8f4a38SAtmn Patel [&](auto &Reply) {
446ec8f4a38SAtmn Patel if (Reply->number()) {
447ec8f4a38SAtmn Patel CLIENT_DBG(
448ec8f4a38SAtmn Patel "Exchanged %ld bytes on device %d at %p for %p on device %d",
449*21e92612SAtmn Patel Size, SrcDevId, SrcPtr, DstPtr, DstDevId)
450ec8f4a38SAtmn Patel } else {
451ec8f4a38SAtmn Patel CLIENT_DBG("Could not exchange %ld bytes on device %d at %p for %p "
452ec8f4a38SAtmn Patel "on device %d",
453*21e92612SAtmn Patel Size, SrcDevId, SrcPtr, DstPtr, DstDevId)
454ec8f4a38SAtmn Patel }
455ec8f4a38SAtmn Patel return Reply->number();
456ec8f4a38SAtmn Patel },
457ec8f4a38SAtmn Patel /* Error Value */ -1);
458ec8f4a38SAtmn Patel }
459ec8f4a38SAtmn Patel
dataDelete(int32_t DeviceId,void * TgtPtr)460ec8f4a38SAtmn Patel int32_t RemoteOffloadClient::dataDelete(int32_t DeviceId, void *TgtPtr) {
461ec8f4a38SAtmn Patel return remoteCall(
462*21e92612SAtmn Patel /* Preprocessor */
463ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
464ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
465ec8f4a38SAtmn Patel auto *Request = protobuf::Arena::CreateMessage<DeleteData>(Arena.get());
466ec8f4a38SAtmn Patel
467ec8f4a38SAtmn Patel Request->set_device_id(DeviceId);
468ec8f4a38SAtmn Patel Request->set_tgt_ptr((uint64_t)TgtPtr);
469ec8f4a38SAtmn Patel
470ec8f4a38SAtmn Patel RPCStatus = Stub->DataDelete(&Context, *Request, Reply);
471ec8f4a38SAtmn Patel return Reply;
472ec8f4a38SAtmn Patel },
473*21e92612SAtmn Patel /* Postprocessor */
474ec8f4a38SAtmn Patel [&](auto &Reply) {
475ec8f4a38SAtmn Patel if (!Reply->number()) {
476ec8f4a38SAtmn Patel CLIENT_DBG("Deleted data at %p on device %d", TgtPtr, DeviceId)
477ec8f4a38SAtmn Patel } else {
478ec8f4a38SAtmn Patel CLIENT_DBG("Could not delete data at %p on device %d", TgtPtr,
479ec8f4a38SAtmn Patel DeviceId)
480ec8f4a38SAtmn Patel }
481ec8f4a38SAtmn Patel return Reply->number();
482ec8f4a38SAtmn Patel },
483ec8f4a38SAtmn Patel /* Error Value */ -1);
484ec8f4a38SAtmn Patel }
485ec8f4a38SAtmn Patel
runTargetRegion(int32_t DeviceId,void * TgtEntryPtr,void ** TgtArgs,ptrdiff_t * TgtOffsets,int32_t ArgNum)486*21e92612SAtmn Patel int32_t RemoteOffloadClient::runTargetRegion(int32_t DeviceId,
487*21e92612SAtmn Patel void *TgtEntryPtr, void **TgtArgs,
488*21e92612SAtmn Patel ptrdiff_t *TgtOffsets,
489*21e92612SAtmn Patel int32_t ArgNum) {
490ec8f4a38SAtmn Patel return remoteCall(
491*21e92612SAtmn Patel /* Preprocessor */
492ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
493ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
494ec8f4a38SAtmn Patel auto *Request =
495*21e92612SAtmn Patel protobuf::Arena::CreateMessage<TargetRegion>(Arena.get());
496ec8f4a38SAtmn Patel
497ec8f4a38SAtmn Patel Request->set_device_id(DeviceId);
498ec8f4a38SAtmn Patel
499ec8f4a38SAtmn Patel Request->set_tgt_entry_ptr(
500ec8f4a38SAtmn Patel (uint64_t)RemoteEntries[DeviceId][TgtEntryPtr]);
501ec8f4a38SAtmn Patel
502ec8f4a38SAtmn Patel char **ArgPtr = (char **)TgtArgs;
503ec8f4a38SAtmn Patel for (auto I = 0; I < ArgNum; I++, ArgPtr++)
504ec8f4a38SAtmn Patel Request->add_tgt_args((uint64_t)*ArgPtr);
505ec8f4a38SAtmn Patel
506ec8f4a38SAtmn Patel char *OffsetPtr = (char *)TgtOffsets;
507ec8f4a38SAtmn Patel for (auto I = 0; I < ArgNum; I++, OffsetPtr++)
508ec8f4a38SAtmn Patel Request->add_tgt_offsets((uint64_t)*OffsetPtr);
509ec8f4a38SAtmn Patel
510ec8f4a38SAtmn Patel Request->set_arg_num(ArgNum);
511ec8f4a38SAtmn Patel
512*21e92612SAtmn Patel RPCStatus = Stub->RunTargetRegion(&Context, *Request, Reply);
513ec8f4a38SAtmn Patel return Reply;
514ec8f4a38SAtmn Patel },
515*21e92612SAtmn Patel /* Postprocessor */
516ec8f4a38SAtmn Patel [&](auto &Reply) {
517ec8f4a38SAtmn Patel if (!Reply->number()) {
518*21e92612SAtmn Patel CLIENT_DBG("Ran target region async on device %d", DeviceId)
519ec8f4a38SAtmn Patel } else {
520*21e92612SAtmn Patel CLIENT_DBG("Could not run target region async on device %d", DeviceId)
521ec8f4a38SAtmn Patel }
522ec8f4a38SAtmn Patel return Reply->number();
523ec8f4a38SAtmn Patel },
524ec8f4a38SAtmn Patel /* Error Value */ -1,
525*21e92612SAtmn Patel /* CanTimeOut */ false);
526ec8f4a38SAtmn Patel }
527ec8f4a38SAtmn Patel
runTargetTeamRegion(int32_t DeviceId,void * TgtEntryPtr,void ** TgtArgs,ptrdiff_t * TgtOffsets,int32_t ArgNum,int32_t TeamNum,int32_t ThreadLimit,uint64_t LoopTripcount)528*21e92612SAtmn Patel int32_t RemoteOffloadClient::runTargetTeamRegion(
529ec8f4a38SAtmn Patel int32_t DeviceId, void *TgtEntryPtr, void **TgtArgs, ptrdiff_t *TgtOffsets,
530ec8f4a38SAtmn Patel int32_t ArgNum, int32_t TeamNum, int32_t ThreadLimit,
531*21e92612SAtmn Patel uint64_t LoopTripcount) {
532ec8f4a38SAtmn Patel return remoteCall(
533*21e92612SAtmn Patel /* Preprocessor */
534ec8f4a38SAtmn Patel [&](auto &RPCStatus, auto &Context) {
535ec8f4a38SAtmn Patel auto *Reply = protobuf::Arena::CreateMessage<I32>(Arena.get());
536ec8f4a38SAtmn Patel auto *Request =
537*21e92612SAtmn Patel protobuf::Arena::CreateMessage<TargetTeamRegion>(Arena.get());
538ec8f4a38SAtmn Patel
539ec8f4a38SAtmn Patel Request->set_device_id(DeviceId);
540ec8f4a38SAtmn Patel
541ec8f4a38SAtmn Patel Request->set_tgt_entry_ptr(
542ec8f4a38SAtmn Patel (uint64_t)RemoteEntries[DeviceId][TgtEntryPtr]);
543ec8f4a38SAtmn Patel
544ec8f4a38SAtmn Patel char **ArgPtr = (char **)TgtArgs;
545ec8f4a38SAtmn Patel for (auto I = 0; I < ArgNum; I++, ArgPtr++) {
546ec8f4a38SAtmn Patel Request->add_tgt_args((uint64_t)*ArgPtr);
547ec8f4a38SAtmn Patel }
548ec8f4a38SAtmn Patel
549ec8f4a38SAtmn Patel char *OffsetPtr = (char *)TgtOffsets;
550ec8f4a38SAtmn Patel for (auto I = 0; I < ArgNum; I++, OffsetPtr++)
551ec8f4a38SAtmn Patel Request->add_tgt_offsets((uint64_t)*OffsetPtr);
552ec8f4a38SAtmn Patel
553ec8f4a38SAtmn Patel Request->set_arg_num(ArgNum);
554ec8f4a38SAtmn Patel Request->set_team_num(TeamNum);
555ec8f4a38SAtmn Patel Request->set_thread_limit(ThreadLimit);
556ec8f4a38SAtmn Patel Request->set_loop_tripcount(LoopTripcount);
557ec8f4a38SAtmn Patel
558*21e92612SAtmn Patel RPCStatus = Stub->RunTargetTeamRegion(&Context, *Request, Reply);
559ec8f4a38SAtmn Patel return Reply;
560ec8f4a38SAtmn Patel },
561*21e92612SAtmn Patel /* Postprocessor */
562ec8f4a38SAtmn Patel [&](auto &Reply) {
563ec8f4a38SAtmn Patel if (!Reply->number()) {
564*21e92612SAtmn Patel CLIENT_DBG("Ran target team region async on device %d", DeviceId)
565ec8f4a38SAtmn Patel } else {
566ec8f4a38SAtmn Patel CLIENT_DBG("Could not run target team region async on device %d",
567*21e92612SAtmn Patel DeviceId)
568ec8f4a38SAtmn Patel }
569ec8f4a38SAtmn Patel return Reply->number();
570ec8f4a38SAtmn Patel },
571ec8f4a38SAtmn Patel /* Error Value */ -1,
572*21e92612SAtmn Patel /* CanTimeOut */ false);
573ec8f4a38SAtmn Patel }
574ec8f4a38SAtmn Patel
shutdown(void)575ec8f4a38SAtmn Patel int32_t RemoteClientManager::shutdown(void) {
576ec8f4a38SAtmn Patel int32_t Ret = 0;
577ec8f4a38SAtmn Patel for (auto &Client : Clients)
578ec8f4a38SAtmn Patel Ret &= Client.shutdown();
579ec8f4a38SAtmn Patel return Ret;
580ec8f4a38SAtmn Patel }
581ec8f4a38SAtmn Patel
registerLib(__tgt_bin_desc * Desc)582ec8f4a38SAtmn Patel int32_t RemoteClientManager::registerLib(__tgt_bin_desc *Desc) {
583ec8f4a38SAtmn Patel int32_t Ret = 0;
584ec8f4a38SAtmn Patel for (auto &Client : Clients)
585ec8f4a38SAtmn Patel Ret &= Client.registerLib(Desc);
586ec8f4a38SAtmn Patel return Ret;
587ec8f4a38SAtmn Patel }
588ec8f4a38SAtmn Patel
unregisterLib(__tgt_bin_desc * Desc)589ec8f4a38SAtmn Patel int32_t RemoteClientManager::unregisterLib(__tgt_bin_desc *Desc) {
590ec8f4a38SAtmn Patel int32_t Ret = 0;
591ec8f4a38SAtmn Patel for (auto &Client : Clients)
592ec8f4a38SAtmn Patel Ret &= Client.unregisterLib(Desc);
593ec8f4a38SAtmn Patel return Ret;
594ec8f4a38SAtmn Patel }
595ec8f4a38SAtmn Patel
isValidBinary(__tgt_device_image * Image)596ec8f4a38SAtmn Patel int32_t RemoteClientManager::isValidBinary(__tgt_device_image *Image) {
597ec8f4a38SAtmn Patel int32_t ClientIdx = 0;
598ec8f4a38SAtmn Patel for (auto &Client : Clients) {
599ec8f4a38SAtmn Patel if (auto Ret = Client.isValidBinary(Image))
600ec8f4a38SAtmn Patel return Ret;
601ec8f4a38SAtmn Patel ClientIdx++;
602ec8f4a38SAtmn Patel }
603ec8f4a38SAtmn Patel return 0;
604ec8f4a38SAtmn Patel }
605ec8f4a38SAtmn Patel
getNumberOfDevices()606ec8f4a38SAtmn Patel int32_t RemoteClientManager::getNumberOfDevices() {
607ec8f4a38SAtmn Patel auto ClientIdx = 0;
608ec8f4a38SAtmn Patel for (auto &Client : Clients) {
609ec8f4a38SAtmn Patel if (auto NumDevices = Client.getNumberOfDevices()) {
610ec8f4a38SAtmn Patel Devices.push_back(NumDevices);
611ec8f4a38SAtmn Patel }
612ec8f4a38SAtmn Patel ClientIdx++;
613ec8f4a38SAtmn Patel }
614ec8f4a38SAtmn Patel
615ec8f4a38SAtmn Patel return std::accumulate(Devices.begin(), Devices.end(), 0);
616ec8f4a38SAtmn Patel }
617ec8f4a38SAtmn Patel
mapDeviceId(int32_t DeviceId)618ec8f4a38SAtmn Patel std::pair<int32_t, int32_t> RemoteClientManager::mapDeviceId(int32_t DeviceId) {
619ec8f4a38SAtmn Patel for (size_t ClientIdx = 0; ClientIdx < Devices.size(); ClientIdx++) {
620*21e92612SAtmn Patel if (DeviceId < Devices[ClientIdx])
621ec8f4a38SAtmn Patel return {ClientIdx, DeviceId};
622ec8f4a38SAtmn Patel DeviceId -= Devices[ClientIdx];
623ec8f4a38SAtmn Patel }
624ec8f4a38SAtmn Patel return {-1, -1};
625ec8f4a38SAtmn Patel }
626ec8f4a38SAtmn Patel
initDevice(int32_t DeviceId)627ec8f4a38SAtmn Patel int32_t RemoteClientManager::initDevice(int32_t DeviceId) {
628ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
629ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
630ec8f4a38SAtmn Patel return Clients[ClientIdx].initDevice(DeviceIdx);
631ec8f4a38SAtmn Patel }
632ec8f4a38SAtmn Patel
initRequires(int64_t RequiresFlags)633ec8f4a38SAtmn Patel int32_t RemoteClientManager::initRequires(int64_t RequiresFlags) {
634ec8f4a38SAtmn Patel for (auto &Client : Clients)
635ec8f4a38SAtmn Patel Client.initRequires(RequiresFlags);
636ec8f4a38SAtmn Patel
637ec8f4a38SAtmn Patel return RequiresFlags;
638ec8f4a38SAtmn Patel }
639ec8f4a38SAtmn Patel
loadBinary(int32_t DeviceId,__tgt_device_image * Image)640ec8f4a38SAtmn Patel __tgt_target_table *RemoteClientManager::loadBinary(int32_t DeviceId,
641ec8f4a38SAtmn Patel __tgt_device_image *Image) {
642ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
643ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
644ec8f4a38SAtmn Patel return Clients[ClientIdx].loadBinary(DeviceIdx, Image);
645ec8f4a38SAtmn Patel }
646ec8f4a38SAtmn Patel
isDataExchangeable(int32_t SrcDevId,int32_t DstDevId)647ec8f4a38SAtmn Patel int32_t RemoteClientManager::isDataExchangeable(int32_t SrcDevId,
648ec8f4a38SAtmn Patel int32_t DstDevId) {
649ec8f4a38SAtmn Patel int32_t SrcClientIdx, SrcDeviceIdx, DstClientIdx, DstDeviceIdx;
650ec8f4a38SAtmn Patel std::tie(SrcClientIdx, SrcDeviceIdx) = mapDeviceId(SrcDevId);
651ec8f4a38SAtmn Patel std::tie(DstClientIdx, DstDeviceIdx) = mapDeviceId(DstDevId);
652ec8f4a38SAtmn Patel return Clients[SrcClientIdx].isDataExchangeable(SrcDeviceIdx, DstDeviceIdx);
653ec8f4a38SAtmn Patel }
654ec8f4a38SAtmn Patel
dataAlloc(int32_t DeviceId,int64_t Size,void * HstPtr)655ec8f4a38SAtmn Patel void *RemoteClientManager::dataAlloc(int32_t DeviceId, int64_t Size,
656ec8f4a38SAtmn Patel void *HstPtr) {
657ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
658ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
659ec8f4a38SAtmn Patel return Clients[ClientIdx].dataAlloc(DeviceIdx, Size, HstPtr);
660ec8f4a38SAtmn Patel }
661ec8f4a38SAtmn Patel
dataDelete(int32_t DeviceId,void * TgtPtr)662ec8f4a38SAtmn Patel int32_t RemoteClientManager::dataDelete(int32_t DeviceId, void *TgtPtr) {
663ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
664ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
665ec8f4a38SAtmn Patel return Clients[ClientIdx].dataDelete(DeviceIdx, TgtPtr);
666ec8f4a38SAtmn Patel }
667ec8f4a38SAtmn Patel
dataSubmit(int32_t DeviceId,void * TgtPtr,void * HstPtr,int64_t Size)668*21e92612SAtmn Patel int32_t RemoteClientManager::dataSubmit(int32_t DeviceId, void *TgtPtr,
669*21e92612SAtmn Patel void *HstPtr, int64_t Size) {
670ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
671ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
672*21e92612SAtmn Patel return Clients[ClientIdx].dataSubmit(DeviceIdx, TgtPtr, HstPtr, Size);
673ec8f4a38SAtmn Patel }
674ec8f4a38SAtmn Patel
dataRetrieve(int32_t DeviceId,void * HstPtr,void * TgtPtr,int64_t Size)675*21e92612SAtmn Patel int32_t RemoteClientManager::dataRetrieve(int32_t DeviceId, void *HstPtr,
676*21e92612SAtmn Patel void *TgtPtr, int64_t Size) {
677ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
678ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
679*21e92612SAtmn Patel return Clients[ClientIdx].dataRetrieve(DeviceIdx, HstPtr, TgtPtr, Size);
680ec8f4a38SAtmn Patel }
681ec8f4a38SAtmn Patel
dataExchange(int32_t SrcDevId,void * SrcPtr,int32_t DstDevId,void * DstPtr,int64_t Size)682*21e92612SAtmn Patel int32_t RemoteClientManager::dataExchange(int32_t SrcDevId, void *SrcPtr,
683ec8f4a38SAtmn Patel int32_t DstDevId, void *DstPtr,
684*21e92612SAtmn Patel int64_t Size) {
685ec8f4a38SAtmn Patel int32_t SrcClientIdx, SrcDeviceIdx, DstClientIdx, DstDeviceIdx;
686ec8f4a38SAtmn Patel std::tie(SrcClientIdx, SrcDeviceIdx) = mapDeviceId(SrcDevId);
687ec8f4a38SAtmn Patel std::tie(DstClientIdx, DstDeviceIdx) = mapDeviceId(DstDevId);
688*21e92612SAtmn Patel return Clients[SrcClientIdx].dataExchange(SrcDeviceIdx, SrcPtr, DstDeviceIdx,
689*21e92612SAtmn Patel DstPtr, Size);
690ec8f4a38SAtmn Patel }
691ec8f4a38SAtmn Patel
runTargetRegion(int32_t DeviceId,void * TgtEntryPtr,void ** TgtArgs,ptrdiff_t * TgtOffsets,int32_t ArgNum)692*21e92612SAtmn Patel int32_t RemoteClientManager::runTargetRegion(int32_t DeviceId,
693*21e92612SAtmn Patel void *TgtEntryPtr, void **TgtArgs,
694*21e92612SAtmn Patel ptrdiff_t *TgtOffsets,
695*21e92612SAtmn Patel int32_t ArgNum) {
696ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
697ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
698*21e92612SAtmn Patel return Clients[ClientIdx].runTargetRegion(DeviceIdx, TgtEntryPtr, TgtArgs,
699*21e92612SAtmn Patel TgtOffsets, ArgNum);
700ec8f4a38SAtmn Patel }
701ec8f4a38SAtmn Patel
runTargetTeamRegion(int32_t DeviceId,void * TgtEntryPtr,void ** TgtArgs,ptrdiff_t * TgtOffsets,int32_t ArgNum,int32_t TeamNum,int32_t ThreadLimit,uint64_t LoopTripCount)702*21e92612SAtmn Patel int32_t RemoteClientManager::runTargetTeamRegion(
703ec8f4a38SAtmn Patel int32_t DeviceId, void *TgtEntryPtr, void **TgtArgs, ptrdiff_t *TgtOffsets,
704ec8f4a38SAtmn Patel int32_t ArgNum, int32_t TeamNum, int32_t ThreadLimit,
705*21e92612SAtmn Patel uint64_t LoopTripCount) {
706ec8f4a38SAtmn Patel int32_t ClientIdx, DeviceIdx;
707ec8f4a38SAtmn Patel std::tie(ClientIdx, DeviceIdx) = mapDeviceId(DeviceId);
708*21e92612SAtmn Patel return Clients[ClientIdx].runTargetTeamRegion(DeviceIdx, TgtEntryPtr, TgtArgs,
709*21e92612SAtmn Patel TgtOffsets, ArgNum, TeamNum,
710*21e92612SAtmn Patel ThreadLimit, LoopTripCount);
711ec8f4a38SAtmn Patel }
712