46 const std::vector<uint32_t> &widths,
bool write,
50 const std::vector<uint32_t> &widths,
bool read,
53 const std::vector<uint32_t> &widths,
bool read,
bool write);
55 const std::vector<uint32_t> &widths,
56 uint32_t xferCount,
bool read,
bool write);
61 uint32_t xferCount,
bool read,
64 uint32_t addAmt, uint32_t numItems);
66 uint32_t addAmt, uint32_t numItems);
68 uint32_t xTrans, uint32_t yTrans,
71 uint32_t xTrans, uint32_t yTrans,
72 uint32_t numCoords,
size_t batchSizeLimit);
77constexpr std::array<uint32_t, 5>
defaultWidths = {32, 64, 128, 256, 512};
90 const char *unit =
"B/s";
91 double value = bytesPerSec;
92 if (bytesPerSec >= 1e9) {
94 value = bytesPerSec / 1e9;
95 }
else if (bytesPerSec >= 1e6) {
97 value = bytesPerSec / 1e6;
98 }
else if (bytesPerSec >= 1e3) {
100 value = bytesPerSec / 1e3;
102 std::ostringstream oss;
103 oss.setf(std::ios::fixed);
105 oss << value <<
" " << unit;
111 const char *units[] = {
"B",
"KB",
"MB",
"GB",
"TB"};
112 double v = (double)bytes;
114 while (v >= 1024.0 && u < 4) {
118 std::ostringstream oss;
119 oss.setf(std::ios::fixed);
120 oss.precision(u == 0 ? 0 : 2);
121 oss << v <<
" " << units[u];
128 return std::to_string(us) +
" us";
129 double ms = us / 1000.0;
131 std::ostringstream oss;
132 oss.setf(std::ios::fixed);
133 oss.precision(ms < 10.0 ? 2 : (ms < 100.0 ? 1 : 0));
137 double sec = ms / 1000.0;
138 std::ostringstream oss;
139 oss.setf(std::ios::fixed);
140 oss.precision(sec < 10.0 ? 3 : 2);
149 void *ptr = _aligned_malloc(size, alignment);
151 throw std::bad_alloc();
154 void *ptr = std::aligned_alloc(alignment, size);
156 throw std::bad_alloc();
169int main(
int argc,
const char *argv[]) {
171 cli.description(
"Test an ESI system running the ESI tester image.");
172 cli.require_subcommand(1);
174 CLI::App *callback_test =
175 cli.add_subcommand(
"callback",
"initiate callback test");
176 uint32_t cb_iters = 1;
177 callback_test->add_option(
"-i,--iters", cb_iters,
178 "Number of iterations to run");
180 CLI::App *hostmemtestSub =
181 cli.add_subcommand(
"hostmem",
"Run the host memory test");
183 bool hmWrite =
false;
186 hostmemtestSub->add_flag(
"-w,--write", hmWrite,
187 "Enable host memory write test");
188 hostmemtestSub->add_flag(
"-r,--read", hmRead,
"Enable host memory read test");
189 hostmemtestSub->add_option(
190 "--widths", hostmemWidths,
193 CLI::App *dmatestSub = cli.add_subcommand(
"dma",
"Run the DMA test");
194 bool dmaRead =
false;
195 bool dmaWrite =
false;
197 dmatestSub->add_flag(
"-w,--write", dmaWrite,
"Enable dma write test");
198 dmatestSub->add_flag(
"-r,--read", dmaRead,
"Enable dma read test");
199 dmatestSub->add_option(
"--widths", dmaWidths,
203 CLI::App *bandwidthSub =
204 cli.add_subcommand(
"bandwidth",
"Run the bandwidth test");
205 uint32_t xferCount = 1000;
206 bandwidthSub->add_option(
"-c,--count", xferCount,
207 "Number of transfers to perform");
208 bool bandwidthRead =
false;
209 bool bandwidthWrite =
false;
212 bandwidthSub->add_option(
"--widths", bandwidthWidths,
213 "Width of the transfers to perform (default: " +
215 bandwidthSub->add_flag(
"-w,--write", bandwidthWrite,
216 "Enable bandwidth write");
217 bandwidthSub->add_flag(
"-r,--read", bandwidthRead,
"Enable bandwidth read");
219 CLI::App *hostmembwSub =
220 cli.add_subcommand(
"hostmembw",
"Run the host memory bandwidth test");
221 uint32_t hmBwCount = 1000;
222 bool hmBwRead =
false;
223 bool hmBwWrite =
false;
225 hostmembwSub->add_option(
"-c,--count", hmBwCount,
226 "Number of hostmem transfers");
227 hostmembwSub->add_option(
228 "--widths", hmBwWidths,
230 hostmembwSub->add_flag(
"-w,--write", hmBwWrite,
231 "Measure hostmem write bandwidth");
232 hostmembwSub->add_flag(
"-r,--read", hmBwRead,
233 "Measure hostmem read bandwidth");
235 CLI::App *loopbackSub =
236 cli.add_subcommand(
"loopback",
"Test LoopbackInOutAdd function service");
237 uint32_t loopbackIters = 10;
238 bool loopbackPipeline =
false;
239 loopbackSub->add_option(
"-i,--iters", loopbackIters,
240 "Number of function invocations (default 10)");
241 loopbackSub->add_flag(
"-p,--pipeline", loopbackPipeline,
242 "Pipeline all calls then collect results");
244 CLI::App *aggBwSub = cli.add_subcommand(
246 "Aggregate hostmem bandwidth across four units (readmem*, writemem*)");
247 uint32_t aggWidth = 512;
248 uint32_t aggCount = 1000;
249 bool aggRead =
false;
250 bool aggWrite =
false;
251 aggBwSub->add_option(
253 "Bit width (default 512; other widths ignored if absent)");
254 aggBwSub->add_option(
"-c,--count", aggCount,
"Flits per unit (default 1000)");
255 aggBwSub->add_flag(
"-r,--read", aggRead,
"Include read units");
256 aggBwSub->add_flag(
"-w,--write", aggWrite,
"Include write units");
258 CLI::App *streamingAddSub = cli.add_subcommand(
259 "streaming_add",
"Test StreamingAdder function service with list input");
260 uint32_t streamingAddAmt = 5;
261 uint32_t streamingNumItems = 5;
262 bool streamingTranslate =
false;
263 streamingAddSub->add_option(
"-a,--add", streamingAddAmt,
264 "Amount to add to each element (default 5)");
265 streamingAddSub->add_option(
"-n,--num-items", streamingNumItems,
266 "Number of random items in the list (default 5)");
267 streamingAddSub->add_flag(
"-t,--translate", streamingTranslate,
268 "Use message translation (list translation)");
270 CLI::App *coordTranslateSub = cli.add_subcommand(
272 "Test CoordTranslator function service with list of coordinates");
273 uint32_t coordXTrans = 10;
274 uint32_t coordYTrans = 20;
275 uint32_t coordNumItems = 5;
276 coordTranslateSub->add_option(
"-x,--x-translation", coordXTrans,
277 "X translation amount (default 10)");
278 coordTranslateSub->add_option(
"-y,--y-translation", coordYTrans,
279 "Y translation amount (default 20)");
280 coordTranslateSub->add_option(
"-n,--num-coords", coordNumItems,
281 "Number of random coordinates (default 5)");
283 CLI::App *serialCoordTranslateSub = cli.add_subcommand(
285 "Test SerialCoordTranslator function service with list of coordinates");
286 uint32_t serialBatchSize = 240;
287 serialCoordTranslateSub->add_option(
"-x,--x-translation", coordXTrans,
288 "X translation amount (default 10)");
289 serialCoordTranslateSub->add_option(
"-y,--y-translation", coordYTrans,
290 "Y translation amount (default 20)");
291 serialCoordTranslateSub->add_option(
292 "-n,--num-coords", coordNumItems,
293 "Number of random coordinates (default 5)");
294 serialCoordTranslateSub
295 ->add_option(
"-b,--batch-size", serialBatchSize,
296 "Coordinates per header (default 240, max 65535)")
297 ->check(CLI::Range(1u, 0xFFFFu));
299 CLI::App *channelTestSub = cli.add_subcommand(
300 "channel",
"Test ChannelService to_host and from_host");
301 uint32_t channelIters = 10;
302 channelTestSub->add_option(
"-i,--iters", channelIters,
303 "Number of loopback iterations (default 10)");
305 if (
int rc = cli.
esiParse(argc, argv))
307 if (!cli.get_help_ptr()->empty())
314 ctxt.
getLogger().
info(
"esitester",
"Connected to accelerator.");
315 Manifest manifest(ctxt, info.getJsonManifest());
318 acc->getServiceThread()->addPoll(*accel);
320 if (*callback_test) {
322 }
else if (*hostmemtestSub) {
323 hostmemTest(acc, accel, hostmemWidths, hmWrite, hmRead);
324 }
else if (*loopbackSub) {
326 }
else if (*dmatestSub) {
327 dmaTest(acc, accel, dmaWidths, dmaRead, dmaWrite);
328 }
else if (*bandwidthSub) {
329 bandwidthTest(acc, accel, bandwidthWidths, xferCount, bandwidthRead,
331 }
else if (*hostmembwSub) {
334 }
else if (*aggBwSub) {
337 }
else if (*streamingAddSub) {
338 if (streamingTranslate)
343 }
else if (*coordTranslateSub) {
345 }
else if (*serialCoordTranslateSub) {
347 coordNumItems, serialBatchSize);
348 }
else if (*channelTestSub) {
353 }
catch (std::exception &e) {
358 std::cout <<
"Exiting successfully\n";
363 uint32_t iterations) {
366 throw std::runtime_error(
"No cb_test child found in accelerator");
367 auto &ports = cb_test->second->getPorts();
368 auto cmd_port = ports.find(
AppID(
"cmd"));
369 if (cmd_port == ports.end())
370 throw std::runtime_error(
"No cmd port found in cb_test child");
373 throw std::runtime_error(
"cb_test cmd port is not MMIO");
375 auto f = ports.find(
AppID(
"cb"));
376 if (f == ports.end())
377 throw std::runtime_error(
"No cb port found in accelerator");
381 throw std::runtime_error(
"cb port is not a CallService::Callback");
383 std::atomic<uint32_t> callbackCount = 0;
386 callbackCount.fetch_add(1);
387 conn->getLogger().
debug(
388 [&](std::string &subsystem, std::string &msg,
389 std::unique_ptr<std::map<std::string, std::any>> &details) {
390 subsystem =
"ESITESTER";
391 msg =
"Received callback";
392 details = std::make_unique<std::map<std::string, std::any>>();
393 details->emplace(
"data", data);
395 std::cout <<
"callback: " << *data.as<uint64_t>() << std::endl;
400 for (uint32_t i = 0; i < iterations; ++i) {
401 conn->getLogger().info(
"esitester",
"Issuing callback command iteration " +
402 std::to_string(i) +
"/" +
403 std::to_string(iterations));
404 cmdMMIO->write(0x10, i);
406 for (uint32_t wait = 0; wait < 1000; ++wait) {
407 if (callbackCount.load() > i)
409 std::this_thread::sleep_for(std::chrono::milliseconds(1));
411 if (callbackCount.load() <= i)
412 throw std::runtime_error(
"Callback test failed. No callback received");
420 std::cout <<
"Running hostmem WRITE test with width " << width << std::endl;
421 uint64_t *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
422 auto check = [&](
bool print) {
424 for (
size_t i = 0; i < 9; ++i) {
426 printf(
"[write] dataPtr[%zu] = 0x%016lx\n", i, dataPtr[i]);
427 if (i < (width + 63) / 64 && dataPtr[i] == 0xFFFFFFFFFFFFFFFFull)
433 auto writeMemChildIter = acc->getChildren().find(
AppID(
"writemem", width));
434 if (writeMemChildIter == acc->getChildren().end())
435 throw std::runtime_error(
436 "hostmem write test failed. No writemem child found");
437 auto &writeMemPorts = writeMemChildIter->second->getPorts();
439 auto cmdPortIter = writeMemPorts.find(
AppID(
"cmd", width));
440 if (cmdPortIter == writeMemPorts.end())
441 throw std::runtime_error(
442 "hostmem write test failed. No (cmd,width) MMIO port");
445 throw std::runtime_error(
446 "hostmem write test failed. (cmd,width) port not MMIO");
448 auto issuedPortIter = writeMemPorts.find(
AppID(
"addrCmdIssued"));
449 if (issuedPortIter == writeMemPorts.end())
450 throw std::runtime_error(
451 "hostmem write test failed. addrCmdIssued missing");
452 auto *addrCmdIssuedPort =
454 if (!addrCmdIssuedPort)
455 throw std::runtime_error(
456 "hostmem write test failed. addrCmdIssued not telemetry");
457 addrCmdIssuedPort->connect();
459 auto responsesPortIter = writeMemPorts.find(
AppID(
"addrCmdResponses"));
460 if (responsesPortIter == writeMemPorts.end())
461 throw std::runtime_error(
462 "hostmem write test failed. addrCmdResponses missing");
463 auto *addrCmdResponsesPort =
465 if (!addrCmdResponsesPort)
466 throw std::runtime_error(
467 "hostmem write test failed. addrCmdResponses not telemetry");
468 addrCmdResponsesPort->connect();
470 for (
size_t i = 0, e = 9; i < e; ++i)
471 dataPtr[i] = 0xFFFFFFFFFFFFFFFFull;
473 cmdMMIO->write(0x10,
reinterpret_cast<uint64_t
>(region.
getDevicePtr()));
474 cmdMMIO->write(0x18, 1);
475 cmdMMIO->write(0x20, 1);
477 for (
int i = 0; i < 100; ++i) {
478 auto issued = addrCmdIssuedPort->readInt();
479 auto responses = addrCmdResponsesPort->readInt();
480 if (issued == 1 && responses == 1) {
484 std::this_thread::sleep_for(std::chrono::microseconds(100));
488 throw std::runtime_error(
"hostmem write test (" + std::to_string(width) +
489 " bits) timeout waiting for completion");
492 throw std::runtime_error(
"hostmem write test failed (" +
493 std::to_string(width) +
" bits)");
499 std::cout <<
"Running hostmem READ test with width " << width << std::endl;
500 auto readMemChildIter = acc->getChildren().find(
AppID(
"readmem", width));
501 if (readMemChildIter == acc->getChildren().end())
502 throw std::runtime_error(
503 "hostmem read test failed. No readmem child found");
505 auto &readMemPorts = readMemChildIter->second->getPorts();
506 auto addrCmdPortIter = readMemPorts.find(
AppID(
"cmd", width));
507 if (addrCmdPortIter == readMemPorts.end())
508 throw std::runtime_error(
509 "hostmem read test failed. No AddressCommand MMIO port");
513 throw std::runtime_error(
514 "hostmem read test failed. AddressCommand port not MMIO");
516 auto lastReadPortIter = readMemPorts.find(
AppID(
"lastReadLSB"));
517 if (lastReadPortIter == readMemPorts.end())
518 throw std::runtime_error(
"hostmem read test failed. lastReadLSB missing");
522 throw std::runtime_error(
523 "hostmem read test failed. lastReadLSB not telemetry");
524 lastReadPort->connect();
526 auto issuedPortIter = readMemPorts.find(
AppID(
"addrCmdIssued"));
527 if (issuedPortIter == readMemPorts.end())
528 throw std::runtime_error(
"hostmem read test failed. addrCmdIssued missing");
529 auto *addrCmdIssuedPort =
531 if (!addrCmdIssuedPort)
532 throw std::runtime_error(
533 "hostmem read test failed. addrCmdIssued not telemetry");
534 addrCmdIssuedPort->connect();
536 auto responsesPortIter = readMemPorts.find(
AppID(
"addrCmdResponses"));
537 if (responsesPortIter == readMemPorts.end())
538 throw std::runtime_error(
539 "hostmem read test failed. addrCmdResponses missing");
540 auto *addrCmdResponsesPort =
542 if (!addrCmdResponsesPort)
543 throw std::runtime_error(
544 "hostmem read test failed. addrCmdResponses not telemetry");
545 addrCmdResponsesPort->connect();
547 for (
size_t i = 0; i < 8; ++i) {
548 auto *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
549 dataPtr[0] = 0x12345678ull << i;
550 dataPtr[1] = 0xDEADBEEFull << i;
552 addrCmdMMIO->write(0x10,
reinterpret_cast<uint64_t
>(region.
getDevicePtr()));
553 addrCmdMMIO->write(0x18, 1);
554 addrCmdMMIO->write(0x20, 1);
556 for (
int waitLoop = 0; waitLoop < 100; ++waitLoop) {
557 auto issued = addrCmdIssuedPort->readInt();
558 auto responses = addrCmdResponsesPort->readInt();
559 if (issued == 1 && responses == 1) {
563 std::this_thread::sleep_for(std::chrono::milliseconds(10));
566 throw std::runtime_error(
"hostmem read (" + std::to_string(width) +
567 " bits) timeout waiting for completion");
568 uint64_t captured = lastReadPort->readInt();
569 uint64_t expected = dataPtr[0];
571 expected &= ((1ull << width) - 1);
572 if (captured != expected)
573 throw std::runtime_error(
"hostmem read test (" + std::to_string(width) +
574 " bits) failed. Expected " +
581 const std::vector<uint32_t> &widths,
bool write,
586 auto scratchRegion = hostmem->allocate(1024 * 1024,
587 {.writeable =
true});
588 uint64_t *dataPtr =
static_cast<uint64_t *
>(scratchRegion->getPtr());
589 conn->getLogger().info(
"esitester",
590 "Running host memory test with region size " +
591 std::to_string(scratchRegion->getSize()) +
592 " bytes at 0x" +
toHex(dataPtr));
593 for (
size_t i = 0; i < scratchRegion->getSize() / 8; ++i)
595 scratchRegion->flush();
598 for (
size_t width : widths) {
604 }
catch (std::exception &e) {
605 conn->getLogger().error(
"esitester",
"Hostmem test failed for width " +
606 std::to_string(width) +
": " +
612 throw std::runtime_error(
"Hostmem test failed");
613 std::cout <<
"Hostmem test passed" << std::endl;
618 Logger &logger = conn->getLogger();
619 logger.
info(
"esitester",
620 "== Running DMA read test with width " + std::to_string(width));
623 acc->resolvePort({
AppID(
"tohostdma", width),
AppID(
"cmd")}, lastPath);
625 throw std::runtime_error(
"dma read test failed. No tohostdma[" +
626 std::to_string(width) +
"] found");
629 throw std::runtime_error(
"dma read test failed. MMIO port is not MMIO");
632 acc->resolvePort({
AppID(
"tohostdma", width),
AppID(
"out")}, lastPath);
636 size_t xferCount = 24;
639 toHostMMIO->write(0, xferCount);
640 for (
size_t i = 0; i < xferCount; ++i) {
643 uint64_t val = *data.as<uint64_t>();
645 throw std::runtime_error(
"dma read test failed. Out of order data");
648 logger.
debug(
"esitester",
649 "Cycle count [" + std::to_string(i) +
"] = 0x" + data.toHex());
652 std::cout <<
" DMA read test for " << width <<
" bits passed" << std::endl;
657 Logger &logger = conn->getLogger();
658 logger.
info(
"esitester",
659 "Running DMA write test with width " + std::to_string(width));
662 acc->resolvePort({
AppID(
"fromhostdma", width),
AppID(
"cmd")}, lastPath);
663 if (!fromHostMMIOPort)
664 throw std::runtime_error(
"dma read test for " +
toString(width) +
665 " bits failed. No fromhostdma[" +
666 std::to_string(width) +
"] found");
669 throw std::runtime_error(
"dma write test for " +
toString(width) +
670 " bits failed. MMIO port is not MMIO");
673 acc->resolvePort({
AppID(
"fromhostdma", width),
AppID(
"in")}, lastPath);
675 throw std::runtime_error(
"dma write test for " +
toString(width) +
676 " bits failed. No out port found");
680 size_t xferCount = 24;
681 uint8_t *data =
new uint8_t[width];
682 for (
size_t i = 0; i < width / 8; ++i)
684 fromHostMMIO->read(8);
685 fromHostMMIO->write(0, xferCount);
686 for (
size_t i = 1; i < xferCount + 1; ++i) {
693 std::this_thread::sleep_for(std::chrono::milliseconds(10));
695 }
while (!successWrite && ++attempts < 100);
697 throw std::runtime_error(
"dma write test for " +
toString(width) +
698 " bits failed. Write failed");
699 uint64_t lastReadMMIO;
700 for (
size_t a = 0; a < 20; ++a) {
701 lastReadMMIO = fromHostMMIO->read(8);
702 if (lastReadMMIO == i)
704 std::this_thread::sleep_for(std::chrono::milliseconds(10));
706 throw std::runtime_error(
"dma write for " +
toString(width) +
707 " bits test failed. Read from MMIO failed");
712 std::cout <<
" DMA write test for " << width <<
" bits passed" << std::endl;
716 const std::vector<uint32_t> &widths,
bool read,
720 for (
size_t width : widths)
723 }
catch (std::exception &e) {
725 std::cerr <<
"DMA write test for " << width
726 <<
" bits failed: " << e.what() << std::endl;
729 for (
size_t width : widths)
732 throw std::runtime_error(
"DMA test failed");
733 std::cout <<
"DMA test passed" << std::endl;
741 size_t width,
size_t xferCount) {
745 acc->resolvePort({
AppID(
"tohostdma", width),
AppID(
"cmd")}, lastPath);
747 throw std::runtime_error(
"bandwidth test failed. No tohostdma[" +
748 std::to_string(width) +
"] found");
751 throw std::runtime_error(
"bandwidth test failed. MMIO port is not MMIO");
754 acc->resolvePort({
AppID(
"tohostdma", width),
AppID(
"out")}, lastPath);
758 Logger &logger = conn->getLogger();
759 logger.
info(
"esitester",
"Starting read bandwidth test with " +
760 std::to_string(xferCount) +
" x " +
761 std::to_string(width) +
" bit transfers");
763 auto start = std::chrono::high_resolution_clock::now();
764 toHostMMIO->write(0, xferCount);
765 for (
size_t i = 0; i < xferCount; ++i) {
768 [i, &data](std::string &subsystem, std::string &msg,
769 std::unique_ptr<std::map<std::string, std::any>> &details) {
770 subsystem =
"esitester";
771 msg =
"Cycle count [" + std::to_string(i) +
"] = 0x" + data.toHex();
774 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
775 std::chrono::high_resolution_clock::now() - start);
777 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
778 logger.
info(
"esitester",
779 " Bandwidth test: " + std::to_string(xferCount) +
" x " +
780 std::to_string(width) +
" bit transfers in " +
781 std::to_string(duration.count()) +
" microseconds");
786 size_t width,
size_t xferCount) {
790 acc->resolvePort({
AppID(
"fromhostdma", width),
AppID(
"cmd")}, lastPath);
791 if (!fromHostMMIOPort)
792 throw std::runtime_error(
"bandwidth test failed. No fromhostdma[" +
793 std::to_string(width) +
"] found");
796 throw std::runtime_error(
"bandwidth test failed. MMIO port is not MMIO");
799 acc->resolvePort({
AppID(
"fromhostdma", width),
AppID(
"in")}, lastPath);
803 Logger &logger = conn->getLogger();
804 logger.
info(
"esitester",
"Starting write bandwidth test with " +
805 std::to_string(xferCount) +
" x " +
806 std::to_string(width) +
" bit transfers");
807 std::vector<uint8_t> dataVec(width / 8);
808 for (
size_t i = 0; i < width / 8; ++i)
811 auto start = std::chrono::high_resolution_clock::now();
812 fromHostMMIO->write(0, xferCount);
813 for (
size_t i = 0; i < xferCount; ++i) {
816 [i, &data](std::string &subsystem, std::string &msg,
817 std::unique_ptr<std::map<std::string, std::any>> &details) {
818 subsystem =
"esitester";
819 msg =
"Cycle count [" + std::to_string(i) +
"] = 0x" + data.toHex();
822 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
823 std::chrono::high_resolution_clock::now() - start);
825 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
826 logger.
info(
"esitester",
827 " Bandwidth test: " + std::to_string(xferCount) +
" x " +
828 std::to_string(width) +
" bit transfers in " +
829 std::to_string(duration.count()) +
" microseconds");
834 const std::vector<uint32_t> &widths,
835 uint32_t xferCount,
bool read,
bool write) {
837 for (uint32_t w : widths)
840 for (uint32_t w : widths)
851 uint32_t width, uint32_t xferCount) {
852 Logger &logger = conn->getLogger();
853 logger.
info(
"esitester",
"Starting hostmem WRITE bandwidth test: " +
854 std::to_string(xferCount) +
" x " +
855 std::to_string(width) +
" bits");
857 auto writeMemChildIter = acc->getChildren().find(
AppID(
"writemem", width));
858 if (writeMemChildIter == acc->getChildren().end())
859 throw std::runtime_error(
"hostmem write bandwidth: writemem child missing");
860 auto &writeMemPorts = writeMemChildIter->second->getPorts();
862 auto cmdPortIter = writeMemPorts.find(
AppID(
"cmd", width));
863 if (cmdPortIter == writeMemPorts.end())
864 throw std::runtime_error(
"hostmem write bandwidth: cmd MMIO missing");
867 throw std::runtime_error(
"hostmem write bandwidth: cmd not MMIO");
869 auto issuedIter = writeMemPorts.find(
AppID(
"addrCmdIssued"));
870 auto respIter = writeMemPorts.find(
AppID(
"addrCmdResponses"));
871 auto cycleCount = writeMemPorts.find(
AppID(
"addrCmdCycles"));
872 if (issuedIter == writeMemPorts.end() || respIter == writeMemPorts.end() ||
873 cycleCount == writeMemPorts.end())
874 throw std::runtime_error(
"hostmem write bandwidth: telemetry missing");
880 if (!issuedPort || !respPort || !cyclePort)
881 throw std::runtime_error(
882 "hostmem write bandwidth: telemetry type mismatch");
884 issuedPort->connect();
889 uint64_t *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
890 size_t words = region.
getSize() / 8;
891 for (
size_t i = 0; i < words; ++i)
892 dataPtr[i] = i + 0xA5A50000;
895 auto start = std::chrono::high_resolution_clock::now();
897 uint64_t devPtr =
reinterpret_cast<uint64_t
>(region.
getDevicePtr());
898 cmdMMIO->write(0x10, devPtr);
899 cmdMMIO->write(0x18, xferCount);
900 cmdMMIO->write(0x20, 1);
903 bool completed =
false;
904 for (
int wait = 0; wait < 100000; ++wait) {
905 uint64_t respNow = respPort->
readInt();
906 if (respNow == xferCount) {
910 std::this_thread::sleep_for(std::chrono::microseconds(50));
913 throw std::runtime_error(
"hostmem write bandwidth timeout");
914 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
915 std::chrono::high_resolution_clock::now() - start);
917 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
918 uint64_t cycles = cyclePort->
readInt();
919 double bytesPerCycle = (double)xferCount * (width / 8.0) / (double)cycles;
920 std::cout <<
"[WRITE] Hostmem bandwidth (" << std::to_string(width)
922 << std::to_string(xferCount) <<
" flits in "
923 << std::to_string(duration.count()) <<
" us, "
924 << std::to_string(cycles) <<
" cycles, " << bytesPerCycle
925 <<
" bytes/cycle" << std::endl;
931 uint32_t width, uint32_t xferCount) {
932 Logger &logger = conn->getLogger();
933 logger.
info(
"esitester",
"Starting hostmem READ bandwidth test: " +
934 std::to_string(xferCount) +
" x " +
935 std::to_string(width) +
" bits");
937 auto readMemChildIter = acc->getChildren().find(
AppID(
"readmem", width));
938 if (readMemChildIter == acc->getChildren().end())
939 throw std::runtime_error(
"hostmem read bandwidth: readmem child missing");
940 auto &readMemPorts = readMemChildIter->second->getPorts();
942 auto cmdPortIter = readMemPorts.find(
AppID(
"cmd", width));
943 if (cmdPortIter == readMemPorts.end())
944 throw std::runtime_error(
"hostmem read bandwidth: cmd MMIO missing");
947 throw std::runtime_error(
"hostmem read bandwidth: cmd not MMIO");
949 auto issuedIter = readMemPorts.find(
AppID(
"addrCmdIssued"));
950 auto respIter = readMemPorts.find(
AppID(
"addrCmdResponses"));
951 auto cyclePort = readMemPorts.find(
AppID(
"addrCmdCycles"));
952 if (issuedIter == readMemPorts.end() || respIter == readMemPorts.end() ||
953 cyclePort == readMemPorts.end())
954 throw std::runtime_error(
"hostmem read bandwidth: telemetry missing");
960 if (!issuedPort || !respPort || !cycleCntPort)
961 throw std::runtime_error(
"hostmem read bandwidth: telemetry type mismatch");
962 issuedPort->connect();
967 uint64_t *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
968 size_t words64 = region.
getSize() / 8;
969 for (
size_t i = 0; i < words64; ++i)
970 dataPtr[i] = 0xCAFEBABE0000ull + i;
972 uint64_t devPtr =
reinterpret_cast<uint64_t
>(region.
getDevicePtr());
973 auto start = std::chrono::high_resolution_clock::now();
975 cmdMMIO->write(0x10, devPtr);
976 cmdMMIO->write(0x18, xferCount);
977 cmdMMIO->write(0x20, 1);
980 for (
int wait = 0; wait < 100000; ++wait) {
981 uint64_t respNow = respPort->
readInt();
982 if (respNow == xferCount) {
986 std::this_thread::sleep_for(std::chrono::microseconds(50));
989 throw std::runtime_error(
"hostmem read bandwidth timeout");
990 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
991 std::chrono::high_resolution_clock::now() - start);
993 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
994 uint64_t cycles = cycleCntPort->
readInt();
995 double bytesPerCycle = (double)xferCount * (width / 8.0) / (double)cycles;
996 std::cout <<
"[ READ] Hostmem bandwidth (" << width
998 <<
" flits in " << duration.count() <<
" us, " << cycles
999 <<
" cycles, " << bytesPerCycle <<
" bytes/cycle" << std::endl;
1004 const std::vector<uint32_t> &widths,
bool read,
1007 hostmemSvc->
start();
1008 auto region = hostmemSvc->allocate(1024 * 1024 * 1024,
1009 {.writeable =
true});
1010 for (uint32_t w : widths) {
1019 uint32_t iterations,
bool pipeline) {
1020 Logger &logger = conn->getLogger();
1023 throw std::runtime_error(
"Loopback test: no 'loopback' child");
1024 auto &ports = loopbackChild->second->getPorts();
1025 auto addIter = ports.find(
AppID(
"add"));
1026 if (addIter == ports.end())
1027 throw std::runtime_error(
"Loopback test: no 'add' port");
1032 throw std::runtime_error(
1033 "Loopback test: 'add' port not a FuncService::Function");
1034 funcPort->connect();
1035 if (iterations == 0) {
1036 logger.
info(
"esitester",
"Loopback add test: 0 iterations (skipped)");
1039 std::mt19937_64 rng(0xC0FFEE);
1040 std::uniform_int_distribution<uint32_t> dist(0, (1u << 24) - 1);
1043 auto start = std::chrono::high_resolution_clock::now();
1044 for (uint32_t i = 0; i < iterations; ++i) {
1045 uint32_t argVal = dist(rng);
1046 uint32_t expected = (argVal + 11) & 0xFFFF;
1047 uint8_t argBytes[3] = {
1048 static_cast<uint8_t
>(argVal & 0xFF),
1049 static_cast<uint8_t
>((argVal >> 8) & 0xFF),
1050 static_cast<uint8_t
>((argVal >> 16) & 0xFF),
1053 MessageData resMsg = funcPort->call(argMsg).get();
1054 uint16_t got = *resMsg.
as<uint16_t>();
1055 std::cout <<
"[loopback] i=" << i <<
" arg=0x" <<
esi::toHex(argVal)
1058 if (got != expected)
1059 throw std::runtime_error(
"Loopback mismatch (non-pipelined)");
1061 auto end = std::chrono::high_resolution_clock::now();
1062 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start)
1064 double callsPerSec = (double)iterations * 1e6 / (
double)us;
1065 logger.
info(
"esitester",
"Loopback add test passed (non-pipelined, " +
1066 std::to_string(iterations) +
" calls, " +
1067 std::to_string(us) +
" us, " +
1068 std::to_string(callsPerSec) +
" calls/s)");
1071 std::vector<std::future<MessageData>> futures;
1072 futures.reserve(iterations);
1073 std::vector<uint32_t> expectedVals;
1074 expectedVals.reserve(iterations);
1076 auto issueStart = std::chrono::high_resolution_clock::now();
1077 for (uint32_t i = 0; i < iterations; ++i) {
1078 uint32_t argVal = dist(rng);
1079 uint32_t expected = (argVal + 11) & 0xFFFF;
1080 uint8_t argBytes[3] = {
1081 static_cast<uint8_t
>(argVal & 0xFF),
1082 static_cast<uint8_t
>((argVal >> 8) & 0xFF),
1083 static_cast<uint8_t
>((argVal >> 16) & 0xFF),
1085 futures.emplace_back(funcPort->call(
MessageData(argBytes, 3)));
1086 expectedVals.emplace_back(expected);
1088 auto issueEnd = std::chrono::high_resolution_clock::now();
1090 for (uint32_t i = 0; i < iterations; ++i) {
1092 uint16_t got = *resMsg.
as<uint16_t>();
1093 uint16_t exp = (uint16_t)expectedVals[i];
1094 std::cout <<
"[loopback-pipelined] i=" << i <<
" got=0x"
1097 throw std::runtime_error(
"Loopback mismatch (pipelined) idx=" +
1100 auto collectEnd = std::chrono::high_resolution_clock::now();
1102 auto issueUs = std::chrono::duration_cast<std::chrono::microseconds>(
1103 issueEnd - issueStart)
1105 auto totalUs = std::chrono::duration_cast<std::chrono::microseconds>(
1106 collectEnd - issueStart)
1109 double issueRate = (double)iterations * 1e6 / (
double)issueUs;
1110 double completionRate = (double)iterations * 1e6 / (
double)totalUs;
1112 logger.
info(
"esitester",
"Loopback add test passed (pipelined). Issued " +
1113 std::to_string(iterations) +
" in " +
1114 std::to_string(issueUs) +
" us (" +
1115 std::to_string(issueRate) +
1116 " calls/s), total " + std::to_string(totalUs) +
1117 " us (" + std::to_string(completionRate) +
1118 " calls/s effective)");
1124 uint32_t xferCount,
bool read,
1126 Logger &logger = conn->getLogger();
1127 if (!read && !write) {
1128 std::cout <<
"aggbandwidth: nothing to do (enable --read and/or --write)\n";
1133 "Aggregate hostmem bandwidth start width=" + std::to_string(width) +
1134 " count=" + std::to_string(xferCount) +
1135 " read=" + (read ?
"Y" :
"N") +
" write=" + (write ?
"Y" :
"N"));
1138 hostmemSvc->
start();
1142 bool isRead =
false;
1143 bool isWrite =
false;
1144 std::unique_ptr<esi::services::HostMem::HostMemRegion> region;
1148 bool launched =
false;
1151 uint64_t duration_us = 0;
1152 uint64_t cycleCount = 0;
1153 std::chrono::high_resolution_clock::time_point start;
1155 std::vector<Unit> units;
1156 const std::vector<std::string> readPrefixes = {
"readmem",
"readmem_0",
1157 "readmem_1",
"readmem_2"};
1158 const std::vector<std::string> writePrefixes = {
"writemem",
"writemem_0",
1159 "writemem_1",
"writemem_2"};
1161 auto addUnits = [&](
const std::vector<std::string> &pref,
bool doRead,
1163 for (
auto &p : pref) {
1165 auto childIt = acc->getChildren().find(
id);
1166 if (childIt == acc->getChildren().end())
1168 auto &ports = childIt->second->getPorts();
1169 auto cmdIt = ports.find(
AppID(
"cmd", width));
1170 auto respIt = ports.find(
AppID(
"addrCmdResponses"));
1171 auto cycIt = ports.find(
AppID(
"addrCmdCycles"));
1172 if (cmdIt == ports.end() || respIt == ports.end() || cycIt == ports.end())
1177 if (!cmd || !resp || !cyc)
1184 u.isWrite = doWrite;
1185 u.region = hostmemSvc->allocate(1024 * 1024 * 1024, {.writeable =
true});
1187 uint64_t *ptr =
static_cast<uint64_t *
>(u.region->getPtr());
1188 size_t words = u.region->getSize() / 8;
1189 for (
size_t i = 0; i < words; ++i)
1191 (p[0] ==
'w' ? (0xA5A500000000ull + i) : (0xCAFEBABE0000ull + i));
1196 u.bytes = uint64_t(xferCount) * (width / 8);
1197 units.emplace_back(std::move(u));
1201 addUnits(readPrefixes,
true,
false);
1203 addUnits(writePrefixes,
false,
true);
1204 if (units.empty()) {
1205 std::cout <<
"aggbandwidth: no matching units present for width " << width
1210 auto wallStart = std::chrono::high_resolution_clock::now();
1212 for (
auto &u : units) {
1213 uint64_t devPtr =
reinterpret_cast<uint64_t
>(u.region->getDevicePtr());
1214 u.cmd->write(0x10, devPtr);
1215 u.cmd->write(0x18, xferCount);
1216 u.cmd->write(0x20, 1);
1217 u.start = std::chrono::high_resolution_clock::now();
1222 const uint64_t timeoutLoops = 200000;
1225 bool allDone =
true;
1226 for (
auto &u : units) {
1229 if (u.resp->readInt() == xferCount) {
1230 auto end = std::chrono::high_resolution_clock::now();
1232 std::chrono::duration_cast<std::chrono::microseconds>(end - u.start)
1234 u.cycleCount = u.cycles->readInt();
1242 if (++loops >= timeoutLoops)
1243 throw std::runtime_error(
"aggbandwidth: timeout");
1244 std::this_thread::sleep_for(std::chrono::microseconds(50));
1246 auto wallUs = std::chrono::duration_cast<std::chrono::microseconds>(
1247 std::chrono::high_resolution_clock::now() - wallStart)
1250 uint64_t totalBytes = 0;
1251 uint64_t totalReadBytes = 0;
1252 uint64_t totalWriteBytes = 0;
1253 for (
auto &u : units) {
1254 totalBytes += u.bytes;
1256 totalReadBytes += u.bytes;
1258 totalWriteBytes += u.bytes;
1259 double unitBps = (double)u.bytes * 1e6 / (
double)u.duration_us;
1260 std::cout <<
"[agg-unit] " << u.prefix <<
"[" << width <<
"] "
1261 << (u.isRead ?
"READ" : (u.isWrite ?
"WRITE" :
"UNK"))
1262 <<
" bytes=" <<
humanBytes(u.bytes) <<
" (" << u.bytes <<
" B)"
1263 <<
" time=" <<
humanTimeUS(u.duration_us) <<
" (" << u.duration_us
1264 <<
" us) cycles=" << u.cycleCount
1270 totalReadBytes ? (double)totalReadBytes * 1e6 / (
double)wallUs : 0.0;
1271 double aggWriteBps =
1272 totalWriteBytes ? (double)totalWriteBytes * 1e6 / (
double)wallUs : 0.0;
1273 double aggCombinedBps =
1274 totalBytes ? (double)totalBytes * 1e6 / (
double)wallUs : 0.0;
1276 std::cout <<
"[agg-total] units=" << units.size()
1277 <<
" read_bytes=" <<
humanBytes(totalReadBytes) <<
" ("
1278 << totalReadBytes <<
" B)"
1280 <<
" write_bytes=" <<
humanBytes(totalWriteBytes) <<
" ("
1281 << totalWriteBytes <<
" B)"
1283 <<
" combined_bytes=" <<
humanBytes(totalBytes) <<
" ("
1284 << totalBytes <<
" B)"
1286 <<
" wall_time=" <<
humanTimeUS(wallUs) <<
" (" << wallUs <<
" us)"
1288 logger.
info(
"esitester",
"Aggregate hostmem bandwidth test complete");
1294#pragma pack(push, 1)
1302 "StreamingAddArg must be 9 bytes packed");
1307#pragma pack(push, 1)
1314 "StreamingAddResult must be 5 bytes packed");
1320 uint32_t addAmt, uint32_t numItems) {
1321 Logger &logger = conn->getLogger();
1322 logger.
info(
"esitester",
"Starting streaming add test with add_amt=" +
1323 std::to_string(addAmt) +
1324 ", num_items=" + std::to_string(numItems));
1327 std::mt19937 rng(0xDEADBEEF);
1328 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1329 std::vector<uint32_t> inputData;
1330 inputData.reserve(numItems);
1331 for (uint32_t i = 0; i < numItems; ++i)
1332 inputData.push_back(dist(rng));
1335 auto streamingAdderChild =
1337 if (streamingAdderChild == accel->
getChildren().end())
1338 throw std::runtime_error(
1339 "Streaming add test: no 'streaming_adder' child found");
1341 auto &ports = streamingAdderChild->second->getPorts();
1342 auto addIter = ports.find(
AppID(
"streaming_add"));
1343 if (addIter == ports.end())
1344 throw std::runtime_error(
1345 "Streaming add test: no 'streaming_add' port found");
1357 for (
size_t i = 0; i < inputData.size(); ++i) {
1360 arg.
input = inputData[i];
1361 arg.
last = (i == inputData.size() - 1) ? 1 : 0;
1363 MessageData(
reinterpret_cast<const uint8_t *
>(&arg),
sizeof(arg)));
1364 logger.
debug(
"esitester",
"Sent {add_amt=" + std::to_string(arg.
addAmt) +
1365 ", input=" + std::to_string(arg.
input) +
1366 ", last=" + (arg.
last ?
"true" :
"false") +
1371 std::vector<uint32_t> results;
1372 bool lastSeen =
false;
1375 resultPort.
read(resMsg);
1377 throw std::runtime_error(
1378 "Streaming add test: unexpected result message size");
1382 lastSeen = res->
last != 0;
1383 results.push_back(res->data);
1384 logger.
debug(
"esitester",
"Received result=" + std::to_string(res->data) +
1385 " (last=" + (lastSeen ?
"true" :
"false") +
1390 if (results.size() != inputData.size())
1391 throw std::runtime_error(
1392 "Streaming add test: result size mismatch. Expected " +
1393 std::to_string(inputData.size()) +
", got " +
1394 std::to_string(results.size()));
1397 std::cout <<
"Streaming add test results:" << std::endl;
1398 for (
size_t i = 0; i < inputData.size(); ++i) {
1399 uint32_t expected = inputData[i] + addAmt;
1400 std::cout <<
" input[" << i <<
"]=" << inputData[i] <<
" + " << addAmt
1401 <<
" = " << results[i] <<
" (expected " << expected <<
")";
1402 if (results[i] != expected) {
1403 std::cout <<
" MISMATCH!";
1406 std::cout << std::endl;
1413 throw std::runtime_error(
"Streaming add test failed: result mismatch");
1415 logger.
info(
"esitester",
"Streaming add test passed");
1416 std::cout <<
"Streaming add test passed" << std::endl;
1435#pragma pack(push, 1)
1443 uint32_t *
inputData() {
return reinterpret_cast<uint32_t *
>(
this + 1); }
1445 return reinterpret_cast<const uint32_t *
>(
this + 1);
1464#pragma pack(push, 1)
1470 uint32_t *
data() {
return reinterpret_cast<uint32_t *
>(
this + 1); }
1472 return reinterpret_cast<const uint32_t *
>(
this + 1);
1486 uint32_t numItems) {
1487 Logger &logger = conn->getLogger();
1488 logger.
info(
"esitester",
1489 "Starting streaming add test (translated) with add_amt=" +
1490 std::to_string(addAmt) +
1491 ", num_items=" + std::to_string(numItems));
1494 std::mt19937 rng(0xDEADBEEF);
1495 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1496 std::vector<uint32_t> inputData;
1497 inputData.reserve(numItems);
1498 for (uint32_t i = 0; i < numItems; ++i)
1499 inputData.push_back(dist(rng));
1502 auto streamingAdderChild =
1504 if (streamingAdderChild == accel->
getChildren().end())
1505 throw std::runtime_error(
1506 "Streaming add test: no 'streaming_adder' child found");
1508 auto &ports = streamingAdderChild->second->getPorts();
1509 auto addIter = ports.find(
AppID(
"streaming_add"));
1510 if (addIter == ports.end())
1511 throw std::runtime_error(
1512 "Streaming add test: no 'streaming_add' port found");
1527 size_t allocSize = ((argSize + alignment - 1) / alignment) * alignment;
1530 throw std::bad_alloc();
1532 std::unique_ptr<void,
decltype(argDeleter)> argBuffer(argRaw, argDeleter);
1535 arg->addAmt = addAmt;
1536 for (uint32_t i = 0; i < numItems; ++i)
1537 arg->inputData()[i] = inputData[i];
1539 logger.
debug(
"esitester",
1540 "Sending translated argument: " + std::to_string(argSize) +
1541 " bytes, list_length=" + std::to_string(arg->inputLength) +
1542 ", add_amt=" + std::to_string(arg->addAmt));
1545 argPort.
write(
MessageData(
reinterpret_cast<const uint8_t *
>(arg), argSize));
1550 resultPort.
read(resMsg);
1552 logger.
debug(
"esitester",
"Received translated result: " +
1553 std::to_string(resMsg.
getSize()) +
" bytes");
1556 throw std::runtime_error(
1557 "Streaming add test (translated): result too small");
1559 const auto *result =
1564 throw std::runtime_error(
1565 "Streaming add test (translated): result data truncated");
1568 if (result->dataLength != inputData.size())
1569 throw std::runtime_error(
1570 "Streaming add test (translated): result size mismatch. Expected " +
1571 std::to_string(inputData.size()) +
", got " +
1572 std::to_string(result->dataLength));
1575 std::cout <<
"Streaming add test results:" << std::endl;
1576 for (
size_t i = 0; i < inputData.size(); ++i) {
1577 uint32_t expected = inputData[i] + addAmt;
1578 std::cout <<
" input[" << i <<
"]=" << inputData[i] <<
" + " << addAmt
1579 <<
" = " << result->data()[i] <<
" (expected " << expected <<
")";
1580 if (result->data()[i] != expected) {
1581 std::cout <<
" MISMATCH!";
1584 std::cout << std::endl;
1591 throw std::runtime_error(
1592 "Streaming add test (translated) failed: result mismatch");
1594 logger.
info(
"esitester",
"Streaming add test passed (translated)");
1595 std::cout <<
"Streaming add test passed" << std::endl;
1606#pragma pack(push, 1)
1612static_assert(
sizeof(
Coord) == 8,
"Coord must be 8 bytes packed");
1623#pragma pack(push, 1)
1633 return reinterpret_cast<const Coord *
>(
this + 1);
1650#pragma pack(push, 1)
1658 return reinterpret_cast<const Coord *
>(
this + 1);
1671 uint32_t xTrans, uint32_t yTrans,
1672 uint32_t numCoords) {
1673 Logger &logger = conn->getLogger();
1674 logger.
info(
"esitester",
"Starting coord translate test with x_trans=" +
1675 std::to_string(xTrans) +
1676 ", y_trans=" + std::to_string(yTrans) +
1677 ", num_coords=" + std::to_string(numCoords));
1682 std::mt19937 rng(0xDEADBEEF);
1683 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1684 std::vector<Coord> inputCoords;
1685 inputCoords.reserve(numCoords);
1686 for (uint32_t i = 0; i < numCoords; ++i) {
1690 inputCoords.push_back(c);
1694 auto coordTranslatorChild =
1696 if (coordTranslatorChild == accel->
getChildren().end())
1697 throw std::runtime_error(
1698 "Coord translate test: no 'coord_translator' child found");
1700 auto &ports = coordTranslatorChild->second->getPorts();
1701 auto translateIter = ports.find(
AppID(
"translate_coords"));
1702 if (translateIter == ports.end())
1703 throw std::runtime_error(
1704 "Coord translate test: no 'translate_coords' port found");
1710 throw std::runtime_error(
1711 "Coord translate test: 'translate_coords' port not a "
1712 "FuncService::Function");
1713 funcPort->connect();
1719 size_t allocSize = ((argSize + alignment - 1) / alignment) * alignment;
1722 throw std::bad_alloc();
1724 std::unique_ptr<void,
decltype(argDeleter)> argBuffer(argRaw, argDeleter);
1727 arg->xTranslation = xTrans;
1728 arg->yTranslation = yTrans;
1729 for (uint32_t i = 0; i < numCoords; ++i)
1730 arg->coords()[i] = inputCoords[i];
1734 "Sending coord translate argument: " + std::to_string(argSize) +
1735 " bytes, coords_length=" + std::to_string(arg->coordsLength) +
1736 ", x_trans=" + std::to_string(arg->xTranslation) +
1737 ", y_trans=" + std::to_string(arg->yTranslation));
1742 ->call(
MessageData(
reinterpret_cast<const uint8_t *
>(arg), argSize))
1746 logger.
debug(
"esitester",
"Received coord translate result: " +
1747 std::to_string(resMsg.
getSize()) +
" bytes");
1750 throw std::runtime_error(
"Coord translate test: result too small");
1752 const auto *result =
1756 throw std::runtime_error(
"Coord translate test: result data truncated");
1759 if (result->coordsLength != inputCoords.size())
1760 throw std::runtime_error(
1761 "Coord translate test: result size mismatch. Expected " +
1762 std::to_string(inputCoords.size()) +
", got " +
1763 std::to_string(result->coordsLength));
1766 std::cout <<
"Coord translate test results:" << std::endl;
1767 for (
size_t i = 0; i < inputCoords.size(); ++i) {
1768 uint32_t expectedX = inputCoords[i].x + xTrans;
1769 uint32_t expectedY = inputCoords[i].y + yTrans;
1770 std::cout <<
" coord[" << i <<
"]=(" << inputCoords[i].x <<
","
1771 << inputCoords[i].y <<
") + (" << xTrans <<
"," << yTrans
1772 <<
") = (" << result->
coords()[i].
x <<
","
1773 << result->coords()[i].y <<
")";
1774 if (result->coords()[i].x != expectedX ||
1775 result->coords()[i].y != expectedY) {
1776 std::cout <<
" MISMATCH! (expected (" << expectedX <<
"," << expectedY
1780 std::cout << std::endl;
1784 throw std::runtime_error(
"Coord translate test failed: result mismatch");
1786 logger.
info(
"esitester",
"Coord translate test passed");
1787 std::cout <<
"Coord translate test passed" << std::endl;
1794#pragma pack(push, 1)
1812#pragma pack(push, 1)
1830 uint32_t yTrans, uint32_t numCoords,
1831 size_t batchSizeLimit) {
1832 Logger &logger = conn->getLogger();
1833 logger.
info(
"esitester",
"Starting serial coord translate test");
1836 std::mt19937 rng(0xDEADBEEF);
1837 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1838 std::vector<Coord> inputCoords;
1839 inputCoords.reserve(numCoords);
1840 for (uint32_t i = 0; i < numCoords; ++i) {
1841 inputCoords.push_back({dist(rng), dist(rng)});
1846 throw std::runtime_error(
"Serial coord translate test: no "
1847 "'coord_translator_serial' child found");
1849 auto &ports = child->second->getPorts();
1850 auto portIter = ports.find(
AppID(
"translate_coords_serial"));
1851 if (portIter == ports.end())
1852 throw std::runtime_error(
1853 "Serial coord translate test: no 'translate_coords_serial' port found");
1862 while (sent < numCoords) {
1863 size_t batchSize = std::min(batchSizeLimit, numCoords - sent);
1873 sizeof(headerFrame)));
1876 for (
size_t i = 0; i < batchSize; ++i) {
1879 dataFrame.
data.
x = inputCoords[sent + i].x;
1880 dataFrame.
data.
y = inputCoords[sent + i].y;
1882 sizeof(dataFrame)));
1889 argPort.
write(footer);
1894 std::vector<Coord> results;
1898 resultPort.
read(msg);
1900 throw std::runtime_error(
"Unexpected result message size");
1905 if (batchCount == 0)
1909 for (uint16_t i = 0; i < batchCount; ++i) {
1910 resultPort.
read(msg);
1912 throw std::runtime_error(
"Unexpected result message size");
1913 const auto *dFrame =
1915 results.push_back({dFrame->data.y, dFrame->data.x});
1921 std::cout <<
"Serial coord translate test results:" << std::endl;
1922 if (results.size() != inputCoords.size()) {
1923 std::cout <<
"Result size mismatch. Expected " << inputCoords.size()
1924 <<
", got " << results.size() << std::endl;
1927 for (
size_t i = 0; i < std::min(inputCoords.size(), results.size()); ++i) {
1928 uint32_t expX = inputCoords[i].x + xTrans;
1929 uint32_t expY = inputCoords[i].y + yTrans;
1930 std::cout <<
" coord[" << i <<
"]=(" << inputCoords[i].x <<
","
1931 << inputCoords[i].y <<
") + (" << xTrans <<
"," << yTrans
1932 <<
") = (" << results[i].x <<
"," << results[i].y
1933 <<
") (expected (" << expX <<
"," << expY <<
"))";
1934 if (results[i].x != expX || results[i].y != expY) {
1935 std::cout <<
" MISMATCH!";
1938 std::cout << std::endl;
1945 throw std::runtime_error(
"Serial coord translate test failed");
1947 logger.
info(
"esitester",
"Serial coord translate test passed");
1948 std::cout <<
"Serial coord translate test passed" << std::endl;
1952 uint32_t iterations) {
1953 Logger &logger = conn->getLogger();
1957 throw std::runtime_error(
"Channel test: no 'channel_test' child");
1958 auto &ports = channelChild->second->getPorts();
1961 auto cmdIter = ports.find(
AppID(
"cmd"));
1962 if (cmdIter == ports.end())
1963 throw std::runtime_error(
"Channel test: no 'cmd' port");
1966 throw std::runtime_error(
"Channel test: 'cmd' is not MMIO");
1969 auto producerIter = ports.find(
AppID(
"producer"));
1970 if (producerIter == ports.end())
1971 throw std::runtime_error(
"Channel test: no 'producer' port");
1972 auto *producerPort =
1975 throw std::runtime_error(
1976 "Channel test: 'producer' is not a ChannelService::ToHost");
1977 producerPort->connect();
1981 cmdMMIO->write(0x0, iterations);
1983 for (uint32_t i = 0; i < iterations; ++i) {
1984 MessageData recvData = producerPort->read().get();
1985 uint32_t got = *recvData.
as<uint32_t>();
1986 std::cout <<
"[channel] producer i=" << i <<
" got=" << got << std::endl;
1988 throw std::runtime_error(
"Channel producer: expected " +
1989 std::to_string(i) +
", got " +
1990 std::to_string(got));
1992 logger.
info(
"esitester",
"Channel test: producer passed (" +
1993 std::to_string(iterations) +
1994 " incrementing values)");
1997 auto loopbackInIter = ports.find(
AppID(
"loopback_in"));
1998 if (loopbackInIter == ports.end())
1999 throw std::runtime_error(
"Channel test: no 'loopback_in' port");
2000 auto *fromHostPort =
2003 throw std::runtime_error(
2004 "Channel test: 'loopback_in' is not a ChannelService::FromHost");
2005 fromHostPort->connect();
2007 auto loopbackOutIter = ports.find(
AppID(
"loopback_out"));
2008 if (loopbackOutIter == ports.end())
2009 throw std::runtime_error(
"Channel test: no 'loopback_out' port");
2010 auto *loopbackOutPort =
2012 if (!loopbackOutPort)
2013 throw std::runtime_error(
2014 "Channel test: 'loopback_out' is not a ChannelService::ToHost");
2015 loopbackOutPort->connect();
2017 std::mt19937_64 rng(0xDEADBEEF);
2018 std::uniform_int_distribution<uint32_t> dist(0, UINT32_MAX);
2020 for (uint32_t i = 0; i < iterations; ++i) {
2021 uint32_t sendVal = dist(rng);
2023 MessageData recvData = loopbackOutPort->read().get();
2024 uint32_t recvVal = *recvData.
as<uint32_t>();
2025 std::cout <<
"[channel] loopback i=" << i <<
" sent=0x"
2028 if (recvVal != sendVal)
2029 throw std::runtime_error(
"Channel loopback mismatch at i=" +
2033 logger.
info(
"esitester",
"Channel test: loopback passed (" +
2034 std::to_string(iterations) +
" iterations)");
2035 std::cout <<
"Channel test passed" << std::endl;
static void print(TypedAttr val, llvm::raw_ostream &os)
static void writePort(uint16_t port)
Write the port number to a file.
Abstract class representing a connection to an accelerator.
Top level accelerator class.
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
T * getAs() const
Cast this Bundle port to a subclass which is actually useful.
ReadChannelPort & getRawRead(const std::string &name) const
WriteChannelPort & getRawWrite(const std::string &name) const
Get access to the raw byte streams of a channel.
Common options and code for ESI runtime tools.
Context & getContext()
Get the context.
AcceleratorConnection * connect()
Connect to the accelerator using the specified backend and connection.
int esiParse(int argc, const char **argv)
Run the parser.
AcceleratorConnections, Accelerators, and Manifests must all share a context.
const std::map< AppID, Instance * > & getChildren() const
Access the module's children by ID.
virtual void error(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report an error.
virtual void info(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report an informational message.
void debug(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report a debug message.
Class to parse a manifest.
Accelerator * buildAccelerator(AcceleratorConnection &acc) const
A logical chunk of data representing serialized data.
const uint8_t * getBytes() const
const T * as() const
Cast to a type.
size_t getSize() const
Get the size of the data in bytes.
static MessageData from(T &t)
Cast from a type to its raw bytes.
A ChannelPort which reads data from the accelerator.
virtual void connect(std::function< bool(MessageData)> callback, const ConnectOptions &options={})
virtual void disconnect() override
virtual void read(MessageData &outData)
Specify a buffer to read into.
A ChannelPort which sends data to the accelerator.
virtual void disconnect() override
void write(const MessageData &data)
A very basic blocking write API.
virtual void connect(const ConnectOptions &options={}) override
Set up a connection to the accelerator.
A function call which gets attached to a service port.
A port which writes data to the accelerator (from_host).
A port which reads data from the accelerator (to_host).
A function call which gets attached to a service port.
virtual void start()
In cases where necessary, enable host memory services.
A "slice" of some parent MMIO space.
Information about the Accelerator system.
A telemetry port which gets attached to a service port.
void connect()
Connect to a particular telemetry port. Offset should be non-nullopt.
static void * alignedAllocCompat(std::size_t alignment, std::size_t size)
static void hostmemWriteTest(Accelerator *acc, esi::services::HostMem::HostMemRegion ®ion, uint32_t width)
Test the hostmem write functionality.
static void aggregateHostmemBandwidthTest(AcceleratorConnection *, Accelerator *, uint32_t width, uint32_t xferCount, bool read, bool write)
static void dmaTest(AcceleratorConnection *, Accelerator *, const std::vector< uint32_t > &widths, bool read, bool write)
static void hostmemBandwidthTest(AcceleratorConnection *conn, Accelerator *acc, uint32_t xferCount, const std::vector< uint32_t > &widths, bool read, bool write)
static void callbackTest(AcceleratorConnection *, Accelerator *, uint32_t iterations)
static void bandwidthTest(AcceleratorConnection *, Accelerator *, const std::vector< uint32_t > &widths, uint32_t xferCount, bool read, bool write)
static void serialCoordTranslateTest(AcceleratorConnection *, Accelerator *, uint32_t xTrans, uint32_t yTrans, uint32_t numCoords, size_t batchSizeLimit)
constexpr std::array< uint32_t, 5 > defaultWidths
static void hostmemReadBandwidthTest(AcceleratorConnection *conn, Accelerator *acc, esi::services::HostMem::HostMemRegion ®ion, uint32_t width, uint32_t xferCount)
static void bandwidthReadTest(AcceleratorConnection *conn, Accelerator *acc, size_t width, size_t xferCount)
static void channelTest(AcceleratorConnection *, Accelerator *, uint32_t iterations)
static std::string formatBandwidth(double bytesPerSec)
static void hostmemWriteBandwidthTest(AcceleratorConnection *conn, Accelerator *acc, esi::services::HostMem::HostMemRegion ®ion, uint32_t width, uint32_t xferCount)
static void alignedFreeCompat(void *ptr)
static void dmaWriteTest(AcceleratorConnection *conn, Accelerator *acc, size_t width)
static void bandwidthWriteTest(AcceleratorConnection *conn, Accelerator *acc, size_t width, size_t xferCount)
static std::string humanBytes(uint64_t bytes)
static void streamingAddTest(AcceleratorConnection *, Accelerator *, uint32_t addAmt, uint32_t numItems)
Test the StreamingAdder module.
static void loopbackAddTest(AcceleratorConnection *, Accelerator *, uint32_t iterations, bool pipeline)
static void dmaReadTest(AcceleratorConnection *conn, Accelerator *acc, size_t width)
static void streamingAddTranslatedTest(AcceleratorConnection *, Accelerator *, uint32_t addAmt, uint32_t numItems)
static void hostmemTest(AcceleratorConnection *, Accelerator *, const std::vector< uint32_t > &widths, bool write, bool read)
static std::string humanTimeUS(uint64_t us)
int main(int argc, const char *argv[])
static void coordTranslateTest(AcceleratorConnection *, Accelerator *, uint32_t xTrans, uint32_t yTrans, uint32_t numCoords)
static std::string defaultWidthsStr()
static void hostmemReadTest(Accelerator *acc, esi::services::HostMem::HostMemRegion ®ion, uint32_t width)
std::string toString(const std::any &a)
'Stringify' a std::any. This is used to log std::any values by some loggers.
std::string toHex(void *val)
Translated argument struct for CoordTranslator.
std::span< const Coord > coordsSpan() const
const Coord * coords() const
static size_t allocSize(size_t numCoords)
Coord * coords()
Get pointer to trailing coords array.
std::span< Coord > coordsSpan()
Get span view of coords (requires coordsLength to be set first).
Translated result struct for CoordTranslator.
static size_t allocSize(size_t numCoords)
std::span< Coord > coordsSpan()
Get span view of coords (requires coordsLength to be set first).
const Coord * coords() const
Coord * coords()
Get pointer to trailing coords array.
std::span< const Coord > coordsSpan() const
Test the CoordTranslator module using message translation.
Packed struct representing a parallel window argument for StreamingAdder.
Packed struct representing a parallel window result for StreamingAdder.
Test the StreamingAdder module using message translation.
uint32_t * inputData()
Get pointer to trailing input data array.
static size_t allocSize(size_t numItems)
std::span< uint32_t > inputDataSpan()
Get span view of input data (requires inputLength to be set first).
std::span< const uint32_t > inputDataSpan() const
const uint32_t * inputData() const
Translated result struct for StreamingAdder.
uint32_t * data()
Get pointer to trailing result data array.
std::span< uint32_t > dataSpan()
Get span view of result data (requires dataLength to be set first).
static size_t allocSize(size_t numItems)
std::span< const uint32_t > dataSpan() const
const uint32_t * data() const
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 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
SerialCoordOutputData data
SerialCoordOutputHeader header