20#ifndef ESI_RUNTIME_SERVICES_H
21#define ESI_RUNTIME_SERVICES_H
52 virtual std::optional<std::string>
toString(
bool oneLine =
false)
const {
61 using Type =
const std::type_info &;
75 std::string implName = {},
124 virtual std::optional<uint64_t>
getCycleCount()
const {
return std::nullopt; }
140 static constexpr std::string_view
StdName =
"esi.service.std.mmio";
153 virtual uint64_t
read(uint32_t addr)
const = 0;
155 virtual void write(uint32_t addr, uint64_t data) = 0;
158 const std::map<AppIDPath, RegionDescriptor> &
getRegions()
const {
165 std::string implName = {},
172 virtual BundlePort *
getPort(AppIDPath
id,
173 const BundleType *type)
const override;
183 std::map<AppIDPath, RegionDescriptor>
regions;
196 virtual uint64_t
read(uint32_t addr)
const;
198 virtual void write(uint32_t addr, uint64_t data);
200 virtual std::optional<std::string>
202 return "MMIO region " +
toHex(
desc.base) +
" - " +
244 operator void *()
const {
return getPtr(); }
250 std::size_t size)
const;
276 virtual std::unique_ptr<HostMemRegion>
allocate(std::size_t size,
282 static constexpr std::string_view
StdName =
"esi.service.std.hostmem";
296 virtual std::unique_ptr<HostMemRegion>
325 using ServicePort::ServicePort;
331 std::future<MessageData>
read();
333 virtual std::optional<std::string>
338 return "channel to_host " + dataType->
toString(oneLine);
349 using ServicePort::ServicePort;
357 virtual std::optional<std::string>
362 return "channel from_host " + dataType->
toString(oneLine);
387 using ServicePort::ServicePort;
397 return dynamic_cast<const ChannelType *
>(
type->findChannel(
"arg").first)
403 type->findChannel(
"result").first)
407 virtual std::optional<std::string>
411 return "function " + resultType->
toString(oneLine) +
"(" +
456 return dynamic_cast<const ChannelType *
>(
type->findChannel(
"arg").first)
462 type->findChannel(
"result").first)
466 virtual std::optional<std::string>
470 return "callback " + resultType->
toString(oneLine) +
"(" +
487 static constexpr std::string_view
StdName =
"esi.service.std.telemetry";
496 std::string implName = {},
506 std::optional<uint64_t>
offset);
510 std::future<MessageData>
read();
513 virtual std::optional<std::string>
518 return "telemetry " + dataType->
toString(oneLine);
528 std::map<AppIDPath, Metric *> ports;
550 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.
Channels are the basic communication primitives.
const Type * getInner() const
Engines implement the actual channel communication between the host and the accelerator.
A concrete flat message backed by a single vector of bytes.
A ChannelPort which reads data from the accelerator.
Root class of the ESI type system.
std::string toString(bool oneLine=false) const
A ChannelPort which sends data to the accelerator.
static Callback * get(AcceleratorConnection &acc, AppID id, const BundleType *type, WriteChannelPort &result, ReadChannelPort &arg)
const esi::Type * getArgType() const
WriteChannelPort * result
const esi::Type * getResultType() const
Callback(AcceleratorConnection &acc, AppID id, const BundleType *, PortMap channels)
virtual std::optional< std::string > toString(bool oneLine=false) const override
AcceleratorConnection & acc
void connect(std::function< MessageData(const MessageData &)> callback, bool quick=false, const ChannelPort::ConnectOptions &options={})
Connect a callback to code which will be executed when the accelerator invokes the callback.
virtual std::string getServiceSymbol() const override
CallService(AcceleratorConnection &acc, AppIDPath id, ServiceImplDetails details)
virtual BundlePort * getPort(AppIDPath id, const BundleType *type) const override
Get specialized port for this service to attach to the given appid path.
A port which writes data to the accelerator (from_host).
virtual std::optional< std::string > toString(bool oneLine=false) const override
WriteChannelPort * dataPort
static FromHost * get(AppID id, const BundleType *type, WriteChannelPort &dataPort)
friend class ChannelService
void write(const MessageData &data)
A port which reads data from the accelerator (to_host).
std::future< MessageData > read()
virtual std::optional< std::string > toString(bool oneLine=false) const override
static ToHost * get(AppID id, const BundleType *type, ReadChannelPort &dataPort)
ReadChannelPort * dataPort
friend class ChannelService
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.
ChannelService(AppIDPath id, AcceleratorConnection &, ServiceImplDetails details, HWClientDetails clients)
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
CustomService(AppIDPath idPath, AcceleratorConnection &, const ServiceImplDetails &details, const HWClientDetails &clients)
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(bool oneLine=false) const override
static Function * get(AppID id, BundleType *type, WriteChannelPort &arg, ReadChannelPort &result)
void connect(const ChannelPort::ConnectOptions &options={})
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.
FuncService(AppIDPath id, AcceleratorConnection &, ServiceImplDetails details, HWClientDetails clients)
Interface for anything which can allocate HostMemRegions.
virtual ~HostMemAllocator()=default
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 ~HostMem()=default
virtual std::string getServiceSymbol() const override
virtual void start()
In cases where necessary, enable host memory services.
Service(AcceleratorConnection &conn)
static constexpr std::string_view StdName
services::HostMemRegion HostMemRegion
RAII memory region for host memory. See services::HostMemRegion.
virtual void unmapMemory(void *ptr) const
Unmap memory which was previously mapped with 'mapMemory'.
virtual std::unique_ptr< HostMemRegion > allocate(std::size_t size, Options opts) const override=0
Allocate a region of host memory in accelerator accessible address space.
virtual bool mapMemory(void *ptr, std::size_t size, Options opts) const
Try to make a region of host memory accessible to the accelerator.
std::optional< uint64_t > getCycleCount() const override
Get the current cycle count of the accelerator system's core clock.
virtual std::vector< uint8_t > getCompressedManifest() const override
Return the zlib compressed JSON system manifest.
std::optional< uint64_t > getCoreClockFrequency() const override
Get the "core" clock frequency of the accelerator system in Hz.
uint32_t getEsiVersion() const override
Get the ESI version number to check version compatibility.
MMIOSysInfo(const MMIO *)
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 std::optional< std::string > toString(bool oneLine=false) const override
MMIORegion(AppID id, MMIO *parent, RegionDescriptor desc)
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 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.
MMIO(AcceleratorConnection &, const AppIDPath &idPath, const HWClientDetails &clients)
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
BundlePort(AppID id, const BundleType *type, PortMap channels)
Construct a port.
virtual std::optional< std::string > toString(bool oneLine=false) 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::optional< uint64_t > getCoreClockFrequency() const
Get the "core" clock frequency of the accelerator system in Hz.
Service(AcceleratorConnection &conn)
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 std::optional< uint64_t > getCycleCount() const
Get the current cycle count of the accelerator system.
virtual ~SysInfo()=default
std::optional< uint64_t > offset
virtual std::optional< std::string > toString(bool oneLine=false) const override
friend class TelemetryService
void connect()
Connect to a particular telemetry port. Offset should be non-nullopt.
std::future< MessageData > read()
Metric(AppID id, const BundleType *type, PortMap channels, const TelemetryService *telemetryService, std::optional< uint64_t > offset)
const TelemetryService * telemetryService
std::list< TelemetryService * > children
std::map< AppIDPath, Metric * > getTelemetryPorts()
MMIO::MMIORegion * getMMIORegion() const
std::map< AppIDPath, Metric * > telemetryPorts
std::map< AppIDPath, uint64_t > portAddressAssignments
static constexpr std::string_view StdName
TelemetryService(AppIDPath id, AcceleratorConnection &, ServiceImplDetails details, HWClientDetails clients)
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 Service * getChildService(Service::Type service, AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={}) override
Create a "child" service of this service.
std::map< std::string, services::Service * > ServiceTable
std::string toHex(void *val)
std::map< std::string, ChannelPort & > PortMap
std::vector< HWClientDetail > HWClientDetails
std::map< std::string, std::any > ServiceImplDetails
Options for allocating host memory.
RAII memory region for host memory in accelerator-accessible address space.
virtual std::size_t getSize() const =0
virtual void * getPtr() const =0
Get a pointer to the host memory.
virtual ~HostMemRegion()=default
virtual void flush()
Flush the memory region to ensure that the device sees the latest contents.
std::optional< uint64_t > getDeviceAddress(const void *ptr, std::size_t size) const
Device address of the host range [ptr, ptr + size) if that range lies entirely inside this region; st...
virtual void * getDevicePtr() const
Sometimes the pointer the device sees is different from the pointer the host sees.
Describe a region (slice) of MMIO space.