1 //===- RPC.h - Interface for remote procedure calls from the GPU ----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file provides the interface to support remote procedure calls (RPC) from
10 // the GPU. This is required to implement host services like printf or malloc.
11 // The interface to the RPC server is provided by the 'libc' project in LLVM.
12 // For more information visit https://libc.llvm.org/gpu/.
14 //===----------------------------------------------------------------------===//
16 #ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_RPC_H
17 #define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_RPC_H
19 #include "llvm/Support/Error.h"
23 namespace llvm::omp::target
{
25 struct GenericDeviceTy
;
26 class GenericGlobalHandlerTy
;
30 /// A generic class implementing the interface between the RPC server provided
31 /// by the 'libc' project and 'libomptarget'. If the RPC server is not availible
32 /// these routines will perform no action.
35 RPCServerTy(uint32_t NumDevices
);
37 /// Check if this device image is using an RPC server. This checks for the
38 /// precense of an externally visible symbol in the device image that will
39 /// be present whenever RPC code is called.
40 llvm::Expected
<bool> isDeviceUsingRPC(plugin::GenericDeviceTy
&Device
,
41 plugin::GenericGlobalHandlerTy
&Handler
,
42 plugin::DeviceImageTy
&Image
);
44 /// Initialize the RPC server for the given device. This will allocate host
45 /// memory for the internal server and copy the data to the client on the
46 /// device. The device must be loaded before this is valid.
47 llvm::Error
initDevice(plugin::GenericDeviceTy
&Device
,
48 plugin::GenericGlobalHandlerTy
&Handler
,
49 plugin::DeviceImageTy
&Image
);
51 /// Runs the RPC server associated with the \p Device until the pending work
53 llvm::Error
runServer(plugin::GenericDeviceTy
&Device
);
55 /// Deinitialize the RPC server for the given device. This will free the
56 /// memory associated with the k
57 llvm::Error
deinitDevice(plugin::GenericDeviceTy
&Device
);
62 } // namespace llvm::omp::target