CIRCT 22.0.0git
Loading...
Searching...
No Matches
RpcServer.h
Go to the documentation of this file.
1//===- RpcServer.h - Run a cosim server -------------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Setup and run a server accepting connections via the 'cosim' RPC protocol.
10// Then, one can request ports to and from the clients.
11//
12// Abstract this out to support multi-party communication in the future.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef ESI_COSIM_RPCSERVER_H
17#define ESI_COSIM_RPCSERVER_H
18
19#include "esi/Context.h"
20#include "esi/Ports.h"
21
22namespace esi {
23namespace cosim {
24
25/// TODO: make this a proper backend (as much as possible).
26class RpcServer {
27public:
30
31 /// Get the context.
32 Context &getContext() { return ctxt; }
33
34 /// Set the manifest and version. There is a race condition here in that the
35 /// RPC server can be started and a connection from the client could happen
36 /// before the manifest is set. TODO: rework the DPI API to require that the
37 /// manifest gets set first.
38 void setManifest(int esiVersion,
39 const std::vector<uint8_t> &compressedManifest);
40
41 /// Register a read or write port which communicates over RPC.
42 ReadChannelPort &registerReadPort(const std::string &name,
43 const std::string &type);
44 WriteChannelPort &registerWritePort(const std::string &name,
45 const std::string &type);
46
47 // Stop the RPC server.
48 // If a millisecond timeout is provided, will forcefully stop the underlying
49 // RPC server once the timeout expires. If not, the RPC server will attempt to
50 // stop gracefully, implying that any outstanding RPC calls must be served
51 // before the server actually stops (see grpc::ServerInterface::Shutdown for
52 // more).
53 void stop(uint32_t timeoutMS = 0);
54
55 // Start the RPC server. If no port is provided, the RPC server will let the
56 // OS pick a port.
57 void run(int port = -1);
58
59 // Return which port the RPC server is executing on.
60 int getPort();
61
62 /// Hide the implementation details from this header file.
63 class Impl;
64
65private:
67 std::unique_ptr<Impl> impl;
68};
69
70} // namespace cosim
71} // namespace esi
72
73#endif // ESI_COSIM_RPCSERVER_H
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition Context.h:34
A ChannelPort which reads data from the accelerator.
Definition Ports.h:318
A ChannelPort which sends data to the accelerator.
Definition Ports.h:206
TODO: make this a proper backend (as much as possible).
Definition RpcServer.h:26
ReadChannelPort & registerReadPort(const std::string &name, const std::string &type)
Register a read or write port which communicates over RPC.
void run(int port=-1)
void stop(uint32_t timeoutMS=0)
Context & getContext()
Get the context.
Definition RpcServer.h:32
void setManifest(int esiVersion, const std::vector< uint8_t > &compressedManifest)
Set the manifest and version.
std::unique_ptr< Impl > impl
Definition RpcServer.h:67
WriteChannelPort & registerWritePort(const std::string &name, const std::string &type)
Definition esi.py:1