37 class TraceChannelPort;
41 Impl(
Mode mode, filesystem::path manifestJson, filesystem::path traceFile)
42 : manifestJson(manifestJson), traceFile(traceFile) {
43 if (!filesystem::exists(manifestJson))
44 throw runtime_error(
"manifest file '" + manifestJson.string() +
49 traceWrite =
new ofstream(traceFile);
50 if (!traceWrite->is_open())
51 throw runtime_error(
"failed to open trace file '" + traceFile.string() +
54 assert(
false &&
"not implemented");
72 std::map<std::string, ChannelPort &> requestChannelsFor(
AppIDPath,
77 void write(
const AppIDPath &
id,
const string &portName,
const void *data,
87 void TraceAccelerator::Impl::write(
const AppIDPath &
id,
const string &portName,
88 const void *data,
size_t size) {
92 *traceWrite <<
"write " <<
id <<
'.' << portName <<
": " << b64data << endl;
95 unique_ptr<AcceleratorConnection>
99 string traceFile =
"trace.log";
103 regex connPattern(
"(\\w):([^:]+)(:(\\w+))?");
105 if (regex_search(connectionString, match, connPattern)) {
107 manifestPath = match[2];
108 if (match[3].matched)
109 traceFile = match[3];
111 throw runtime_error(
"connection string must be of the form "
112 "'<mode>:<manifest path>[:<traceFile>]'");
120 throw runtime_error(
"unknown mode '" + modeStr +
"'");
122 return make_unique<TraceAccelerator>(
123 ctxt, mode, filesystem::path(manifestPath), filesystem::path(traceFile));
127 filesystem::path manifestJson,
128 filesystem::path traceFile)
130 impl = make_unique<Impl>(mode, manifestJson, traceFile);
137 return impl->createService(svcType, idPath, details, clients);
140 class TraceSysInfo :
public SysInfo {
142 TraceSysInfo(filesystem::path manifestJson) : manifestJson(manifestJson) {}
144 uint32_t getEsiVersion()
const override {
return ESIVersion; }
146 string getJsonManifest()
const override {
148 ifstream manifest(manifestJson);
149 if (!manifest.is_open())
150 throw runtime_error(
"failed to open manifest file '" +
151 manifestJson.string() +
"'");
153 buffer << manifest.rdbuf();
158 vector<uint8_t> getCompressedManifest()
const override {
159 throw runtime_error(
"compressed manifest not supported by trace backend");
163 filesystem::path manifestJson;
171 const AppIDPath &
id,
const string &portName)
174 virtual void write(
const MessageData &data)
override {
175 impl.write(
id, portName,
data.getBytes(),
data.getSize());
198 bool ReadTraceChannelPort::read(
MessageData &data) {
199 if ((++numReads & 0x1) == 1)
202 std::ptrdiff_t numBits = getType()->getBitWidth();
205 throw runtime_error(
"unsupported type for read: " + getType()->getID());
207 std::ptrdiff_t size = (numBits + 7) / 8;
208 std::vector<uint8_t> bytes(size);
209 for (std::ptrdiff_t i = 0; i < size; ++i)
210 bytes[i] = rand() % 256;
225 map<string, ChannelPort &>
228 map<string, ChannelPort &>
channels;
229 for (
auto [name, dir, type] : bundleType->
getChannels()) {
232 port =
new WriteTraceChannelPort(*
this, type, idPath, name);
234 port =
new ReadTraceChannelPort(*
this, type);
241 map<string, ChannelPort &>
244 return impl->requestChannelsFor(idPath, bundleType);
251 if (svcType ==
typeid(
SysInfo))
252 return new TraceSysInfo(manifestJson);
254 return new TraceCustomService(*
this, idPath, details, clients);
assert(baseType &&"element must be base type")
constexpr uint32_t ESIVersion
REGISTER_ACCELERATOR("trace", TraceAccelerator)
Abstract class representing a connection to an accelerator.
static bool isWrite(BundleType::Direction bundleDir)
Compute the direction of a channel given the bundle direction and the bundle port's direction.
Bundles represent a collection of channels.
const ChannelVector & getChannels() const
Unidirectional channels are the basic communication primitive between the host and accelerator.
AcceleratorConnections, Accelerators, and Manifests must all share a context.
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.
Connect to an ESI simulation.
std::unique_ptr< Impl > impl
std::map< std::string, ChannelPort & > requestChannelsFor(AppIDPath, const BundleType *) override
Request the host side channel ports for a particular instance (identified by the AppID path).
virtual Service * createService(Service::Type service, AppIDPath idPath, std::string implName, const ServiceImplDetails &details, const HWClientDetails &clients) override
Called by getServiceImpl exclusively.
A service for which there are no standard services registered.
Parent class of all APIs modeled as 'services'.
const std::type_info & Type
Information about the Accelerator system.
def connect(destination, source)
void encodeBase64(const void *data, size_t size, std::string &out)
std::map< std::string, std::any > ServiceImplDetails
std::vector< HWClientDetail > HWClientDetails
Service * createService(Service::Type svcType, AppIDPath idPath, const ServiceImplDetails &details, const HWClientDetails &clients)
vector< unique_ptr< ChannelPort > > channels
std::map< std::string, ChannelPort & > requestChannelsFor(AppIDPath, const BundleType *)
Request the host side channel ports for a particular instance (identified by the AppID path).
filesystem::path manifestJson
Impl(Mode mode, filesystem::path manifestJson, filesystem::path traceFile)
void adoptChannelPort(ChannelPort *port)
filesystem::path traceFile