37 uncompress(dst.data(), &dstSize, compressed.data(), compressed.size());
39 throw std::runtime_error(
"zlib uncompress failed with rc=" +
41 return std::string(
reinterpret_cast<char *
>(dst.data()), dstSize);
51 throw std::runtime_error(
"Invalid magic number: " +
toHex(
reg));
58 throw std::runtime_error(
"Unsupported ESI header version: " +
59 std::to_string(version));
61 uint64_t size =
mmio->
read(manifestPtr);
62 uint64_t numWords = (size + 7) / 8;
63 std::vector<uint64_t> manifestWords(numWords);
64 for (
size_t i = 0; i < numWords; ++i)
65 manifestWords[i] =
mmio->
read(manifestPtr + 8 + (i * 8));
67 std::vector<uint8_t> manifest;
68 for (
size_t i = 0; i < size; ++i) {
69 uint64_t word = manifestWords[i / 8];
70 manifest.push_back(word >> (8 * (i % 8)));
81 if (
auto f = details.find(
"service"); f != details.end()) {
89 const std::string &implName,
91 if (
auto f = details.find(
"service"); f != details.end())
93 symbol = std::any_cast<std::string>(f->second).substr(1);
100 const std::map<std::string, ChannelPort &> &channels,
102 return new Function(
id.back(), channels);
106 AppID id,
const std::map<std::string, ChannelPort &> &channels)
110 assert(
channels.size() == 2 &&
"FuncService must have exactly two channels");
116 return new Function(
id, {{
"arg", arg}, {
"result", result}});
124 std::future<MessageData>
126 std::scoped_lock<std::mutex> lock(callMutex);
128 return result.readAsync();
134 if (
auto f = details.find(
"service"); f != details.end())
136 symbol = std::any_cast<std::string>(f->second).substr(1);
143 const std::map<std::string, ChannelPort &> &channels,
145 return new Callback(acc,
id.back(), channels);
150 const std::map<std::string, ChannelPort &> &channels)
156 throw std::runtime_error(
"CallService must have exactly two channels");
164 arg.connect([
this, callback](
MessageData argMsg) ->
bool {
165 MessageData resultMsg = callback(std::move(argMsg));
166 this->result.write(std::move(resultMsg));
172 acc.getServiceThread()->addListener(
175 MessageData resultMsg = callback(std::move(argMsg));
176 this->result.write(std::move(resultMsg));
183 std::string implName,
188 return new FuncService(acc,
id, implName, details, clients);
190 return new CallService(acc,
id, implName, details, clients);
196 if (svcName ==
"esi.service.std.func")
198 if (svcName ==
"esi.service.std.call")
assert(baseType &&"element must be base type")
constexpr uint32_t MAX_MANIFEST_SIZE
Abstract class representing a connection to an accelerator.
std::map< std::string, ChannelPort & > channels
Bundles represent a collection of channels.
A logical chunk of data representing serialized data.
A ChannelPort which reads data from the accelerator.
A ChannelPort which sends data to the accelerator.
A function call which gets attached to a service port.
Callback(AcceleratorConnection &acc, AppID id, const std::map< std::string, ChannelPort & > &channels)
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.
Service for servicing function calls from the accelerator.
CallService(AcceleratorConnection *acc, AppIDPath id, std::string implName, ServiceImplDetails details, HWClientDetails clients)
virtual std::string getServiceSymbol() const override
virtual ServicePort * getPort(AppIDPath id, const BundleType *type, const std::map< std::string, ChannelPort & > &, AcceleratorConnection &) 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.
CustomService(AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients)
std::string serviceSymbol
A function call which gets attached to a service port.
std::future< MessageData > call(const MessageData &arg)
static Function * get(AppID id, WriteChannelPort &arg, ReadChannelPort &result)
Function(AppID id, const std::map< std::string, ChannelPort & > &channels)
Service for calling functions.
virtual std::string getServiceSymbol() const override
virtual ServicePort * getPort(AppIDPath id, const BundleType *type, const std::map< std::string, ChannelPort & > &, AcceleratorConnection &) const override
Get specialized port for this service to attach to the given appid path.
FuncService(AcceleratorConnection *acc, AppIDPath id, const std::string &implName, ServiceImplDetails details, HWClientDetails clients)
virtual std::string getServiceSymbol() const override
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.
MMIOSysInfo(const MMIO *)
virtual uint64_t read(uint32_t addr) const =0
virtual std::string getServiceSymbol() const override
Add a custom interface to a service client at a particular point in the design hierarchy.
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'.
const std::type_info & Type
virtual std::string getJsonManifest() const
Return the JSON-formatted system manifest.
virtual std::vector< uint8_t > getCompressedManifest() const =0
Return the zlib compressed JSON system manifest.
virtual std::string getServiceSymbol() const override
constexpr uint64_t MagicNumber
std::map< std::string, std::any > ServiceImplDetails
std::string toHex(uint32_t val)
constexpr uint32_t MetadataOffset
std::vector< HWClientDetail > HWClientDetails
def reg(value, clock, reset=None, reset_value=None, name=None, sym_name=None)