CIRCT
24.0.0git
Loading...
Searching...
No Matches
lib
Dialect
ESI
runtime
cpp
include
esi
backends
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
22
namespace
esi
{
23
namespace
cosim
{
24
25
/// TODO: make this a proper backend (as much as possible).
26
class
RpcServer
{
27
public
:
28
RpcServer
(
Context
&
ctxt
);
29
~RpcServer
();
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. Frames which
42
/// arrive for a read port before it's connected are held until it is.
43
///
44
/// Write ports apply backpressure: `tryWrite()` returns false, and
45
/// `write()` blocks, while the channel's in-flight limit (messages queued
46
/// here plus messages sent but not yet consumed by the client) is reached.
47
/// `write()` throws if the port is disconnected meanwhile. The simulation
48
/// should use `tryWrite()`: blocking it can deadlock, since the client may
49
/// need it to make progress before consuming anything.
50
ReadChannelPort
&
registerReadPort
(
const
std::string &name,
51
const
std::string &type);
52
WriteChannelPort
&
registerWritePort
(
const
std::string &name,
53
const
std::string &type);
54
55
/// Report that the simulation has consumed one message read from `port`
56
/// (which must have been returned by `registerReadPort`), in the order they
57
/// were read. This returns a credit to the client which sent it (if it's
58
/// still connected) so it may send another message. Non-blocking.
59
void
messageConsumed
(
ReadChannelPort
&port);
60
61
// Stop the RPC server.
62
// The optional millisecond timeout is advisory; the WebSocket transport
63
// closes connections promptly, so the value is unused in v4 of the
64
// protocol.
65
void
stop
(uint32_t timeoutMS = 0);
66
67
// Start the RPC server. If no port is provided, the RPC server will let the
68
// OS pick a port.
69
void
run
(
int
port = -1);
70
71
// Return which port the RPC server is executing on.
72
int
getPort
();
73
74
/// Hide the implementation details from this header file.
75
class
Impl
;
76
77
private
:
78
Context
&
ctxt
;
79
std::unique_ptr<Impl>
impl
;
80
};
81
82
}
// namespace cosim
83
}
// namespace esi
84
85
#endif
// ESI_COSIM_RPCSERVER_H
Context.h
Ports.h
Impl
esi::cosim::RpcServer::Impl Impl
Definition
RpcServer.cpp:285
esi::Context
AcceleratorConnections, Accelerators, and Manifests must all share a context.
Definition
Context.h:34
esi::ReadChannelPort
A ChannelPort which reads data from the accelerator.
Definition
Ports.h:479
esi::WriteChannelPort
A ChannelPort which sends data to the accelerator.
Definition
Ports.h:308
esi::cosim::RpcServer::getPort
int getPort()
Definition
RpcServer.cpp:1423
esi::cosim::RpcServer::RpcServer
RpcServer(Context &ctxt)
Definition
RpcServer.cpp:1381
esi::cosim::RpcServer::ctxt
Context & ctxt
Definition
RpcServer.h:78
esi::cosim::RpcServer::messageConsumed
void messageConsumed(ReadChannelPort &port)
Report that the simulation has consumed one message read from port (which must have been returned by ...
Definition
RpcServer.cpp:1405
esi::cosim::RpcServer::registerReadPort
ReadChannelPort & registerReadPort(const std::string &name, const std::string &type)
Register a read or write port which communicates over RPC.
Definition
RpcServer.cpp:1391
esi::cosim::RpcServer::run
void run(int port=-1)
Definition
RpcServer.cpp:1411
esi::cosim::RpcServer::~RpcServer
~RpcServer()
esi::cosim::RpcServer::stop
void stop(uint32_t timeoutMS=0)
Definition
RpcServer.cpp:1417
esi::cosim::RpcServer::getContext
Context & getContext()
Get the context.
Definition
RpcServer.h:32
esi::cosim::RpcServer::setManifest
void setManifest(int esiVersion, const std::vector< uint8_t > &compressedManifest)
Set the manifest and version.
Definition
RpcServer.cpp:1384
esi::cosim::RpcServer::impl
std::unique_ptr< Impl > impl
Definition
RpcServer.h:79
esi::cosim::RpcServer::registerWritePort
WriteChannelPort & registerWritePort(const std::string &name, const std::string &type)
Definition
RpcServer.cpp:1398
esi::cosim
Definition
RpcServer.h:23
esi
Definition
esi.py:1
Generated on
for CIRCT by
1.15.0