20#ifndef ESI_RUNTIME_SERVICES_H
21#define ESI_RUNTIME_SERVICES_H
30class AcceleratorConnection;
41 virtual std::optional<std::string>
toString()
const {
return std::nullopt; }
48 using Type =
const std::type_info &;
62 std::string implName = {},
119 static constexpr std::string_view
StdName =
"esi.service.std.mmio";
132 virtual uint64_t
read(uint32_t addr)
const = 0;
134 virtual void write(uint32_t addr, uint64_t data) = 0;
137 const std::map<AppIDPath, RegionDescriptor> &
getRegions()
const {
144 std::string implName = {},
151 virtual BundlePort *
getPort(AppIDPath
id,
152 const BundleType *type)
const override;
156 std::map<AppIDPath, RegionDescriptor>
regions;
169 virtual uint64_t
read(uint32_t addr)
const;
171 virtual void write(uint32_t addr, uint64_t data);
173 virtual std::optional<std::string>
toString()
const override {
201 static constexpr std::string_view
StdName =
"esi.service.std.hostmem";
216 operator void *()
const {
return getPtr(); }
236 virtual std::unique_ptr<HostMemRegion>
allocate(std::size_t size,
265 using ServicePort::ServicePort;
285 virtual std::optional<std::string>
toString()
const override {
288 return "function " + resultType->
getID() +
"(" + argType->
getID() +
")";
341 virtual std::optional<std::string>
toString()
const override {
344 return "callback " + resultType->
getID() +
"(" + argType->
getID() +
")";
360 static constexpr std::string_view
StdName =
"esi.service.std.telemetry";
379 std::future<MessageData>
read();
381 virtual std::optional<std::string>
toString()
const override {
385 return "telemetry " + dataType->
getID();
409 std::string implName,
Abstract class representing a connection to an accelerator.
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
BundlePort(AppID id, const BundleType *type, PortMap channels)
Construct a port.
Bundles represent a collection of channels.
std::pair< const Type *, Direction > findChannel(std::string name) const
Channels are the basic communication primitives.
A logical chunk of data representing serialized data.
A ChannelPort which reads data from the accelerator.
Root class of the ESI type system.
A ChannelPort which sends data to the accelerator.
A function call which gets attached to a service port.
static Callback * get(AcceleratorConnection &acc, AppID id, const BundleType *type, WriteChannelPort &result, ReadChannelPort &arg)
virtual std::optional< std::string > toString() const override
const esi::Type * getArgType() const
WriteChannelPort * result
const esi::Type * getResultType() const
void connect(std::function< MessageData(const MessageData &)> callback, bool quick=false)
Connect a callback to code which will be executed when the accelerator invokes the callback.
AcceleratorConnection & acc
Service for servicing function calls from the accelerator.
virtual std::string getServiceSymbol() const override
virtual BundlePort * getPort(AppIDPath id, const BundleType *type) const override
Get specialized port for this service to attach to the given appid path.
A service for which there are no standard services registered.
virtual BundlePort * getPort(AppIDPath id, const BundleType *type) const override
Get specialized port for this service to attach to the given appid path.
virtual ~CustomService()=default
virtual std::string getServiceSymbol() const override
std::string serviceSymbol
A function call which gets attached to a service port.
const esi::Type * getArgType() const
const esi::Type * getResultType() const
std::future< MessageData > call(const MessageData &arg)
virtual std::optional< std::string > toString() const override
static Function * get(AppID id, BundleType *type, WriteChannelPort &arg, ReadChannelPort &result)
Service for calling functions.
virtual std::string getServiceSymbol() const override
virtual BundlePort * getPort(AppIDPath id, const BundleType *type) const override
Get specialized port for this service to attach to the given appid path.
virtual ~HostMem()=default
virtual std::string getServiceSymbol() const override
virtual void start()
In cases where necessary, enable host memory services.
static constexpr std::string_view StdName
virtual std::unique_ptr< HostMemRegion > allocate(std::size_t size, Options opts) const =0
Allocate a region of host memory in accelerator accessible address space.
virtual void unmapMemory(void *ptr) const
Unmap memory which was previously mapped with 'mapMemory'.
virtual bool mapMemory(void *ptr, std::size_t size, Options opts) const
Try to make a region of host memory accessible to the accelerator.
Implement the SysInfo API for a standard MMIO protocol.
virtual std::vector< uint8_t > getCompressedManifest() const override
Return the zlib compressed JSON system manifest.
uint32_t getEsiVersion() const override
Get the ESI version number to check version compatibility.
A "slice" of some parent MMIO space.
virtual uint64_t read(uint32_t addr) const
Read a 64-bit value from this region, not the global address space.
virtual void write(uint32_t addr, uint64_t data)
Write a 64-bit value to this region, not the global address space.
virtual RegionDescriptor getDescriptor() const
Get the offset (and size) of the region in the parent (usually global) MMIO address space.
virtual std::optional< std::string > toString() const override
virtual uint64_t read(uint32_t addr) const =0
Read a 64-bit value from the global MMIO space.
virtual void write(uint32_t addr, uint64_t data)=0
Write a 64-bit value to the global MMIO space.
virtual BundlePort * getPort(AppIDPath id, const BundleType *type) const override
Get a MMIO region port for a particular region descriptor.
std::map< AppIDPath, RegionDescriptor > regions
MMIO base address table.
static constexpr std::string_view StdName
virtual Service * getChildService(Service::Type service, AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={}) override
If the service is a MMIO service, return a region of the MMIO space which peers into ours.
const std::map< AppIDPath, RegionDescriptor > & getRegions() const
Get the regions of MMIO space that this service manages.
virtual std::string getServiceSymbol() const override
Add a custom interface to a service client at a particular point in the design hierarchy.
virtual ~ServicePort()=default
virtual std::optional< std::string > toString() const
Registry of services which can be instantiated directly by the Accelerator class if the backend doesn...
static Service::Type lookupServiceType(const std::string &)
Resolve a service type from a string.
static Service * createService(AcceleratorConnection *acc, Service::Type svcType, AppIDPath id, std::string implName, ServiceImplDetails details, HWClientDetails clients)
Create a service instance from the given details.
Parent class of all APIs modeled as 'services'.
virtual BundlePort * getPort(AppIDPath id, const BundleType *type) const
Get specialized port for this service to attach to the given appid path.
virtual std::string getServiceSymbol() const =0
AcceleratorConnection & getConnection() const
const std::type_info & Type
virtual Service * getChildService(Service::Type service, AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={})
Create a "child" service of this service.
Service(AcceleratorConnection &conn)
virtual ~Service()=default
AcceleratorConnection & conn
Information about the Accelerator system.
virtual std::string getJsonManifest() const
Return the JSON-formatted system manifest.
virtual uint32_t getEsiVersion() const =0
Get the ESI version number to check version compatibility.
virtual std::vector< uint8_t > getCompressedManifest() const =0
Return the zlib compressed JSON system manifest.
virtual std::string getServiceSymbol() const override
virtual ~SysInfo()=default
A telemetry port which gets attached to a service port.
static Telemetry * get(AppID id, BundleType *type, WriteChannelPort &get, ReadChannelPort &data)
virtual std::optional< std::string > toString() const override
std::future< MessageData > read()
void connect()
Connect to a particular telemetry port.
WriteChannelPort * get_req
Service for retrieving telemetry data from the accelerator.
const std::map< AppIDPath, Telemetry * > & getTelemetryPorts()
std::map< AppIDPath, Telemetry * > telemetryPorts
static constexpr std::string_view StdName
virtual std::string getServiceSymbol() const override
virtual BundlePort * getPort(AppIDPath id, const BundleType *type) const override
Get specialized port for this service to attach to the given appid path.
std::map< std::string, std::any > ServiceImplDetails
std::string toHex(void *val)
std::map< std::string, ChannelPort & > PortMap
std::vector< HWClientDetail > HWClientDetails
RAII memory region for host memory.
virtual void * getDevicePtr() const
Sometimes the pointer the device sees is different from the pointer the host sees.
virtual ~HostMemRegion()=default
virtual void * getPtr() const =0
Get a pointer to the host memory.
virtual void flush()
Flush the memory region to ensure that the device sees the latest contents.
virtual std::size_t getSize() const =0
Options for allocating host memory.
Describe a region (slice) of MMIO space.