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);
75constexpr std::array<uint32_t, 5>
defaultWidths = {32, 64, 128, 256, 512};
88 const char *unit =
"B/s";
89 double value = bytesPerSec;
90 if (bytesPerSec >= 1e9) {
92 value = bytesPerSec / 1e9;
93 }
else if (bytesPerSec >= 1e6) {
95 value = bytesPerSec / 1e6;
96 }
else if (bytesPerSec >= 1e3) {
98 value = bytesPerSec / 1e3;
100 std::ostringstream oss;
101 oss.setf(std::ios::fixed);
103 oss << value <<
" " << unit;
109 const char *units[] = {
"B",
"KB",
"MB",
"GB",
"TB"};
110 double v = (double)bytes;
112 while (v >= 1024.0 && u < 4) {
116 std::ostringstream oss;
117 oss.setf(std::ios::fixed);
118 oss.precision(u == 0 ? 0 : 2);
119 oss << v <<
" " << units[u];
126 return std::to_string(us) +
" us";
127 double ms = us / 1000.0;
129 std::ostringstream oss;
130 oss.setf(std::ios::fixed);
131 oss.precision(ms < 10.0 ? 2 : (ms < 100.0 ? 1 : 0));
135 double sec = ms / 1000.0;
136 std::ostringstream oss;
137 oss.setf(std::ios::fixed);
138 oss.precision(sec < 10.0 ? 3 : 2);
147 void *ptr = _aligned_malloc(size, alignment);
149 throw std::bad_alloc();
152 void *ptr = std::aligned_alloc(alignment, size);
154 throw std::bad_alloc();
167int main(
int argc,
const char *argv[]) {
169 cli.description(
"Test an ESI system running the ESI tester image.");
170 cli.require_subcommand(1);
172 CLI::App *callback_test =
173 cli.add_subcommand(
"callback",
"initiate callback test");
174 uint32_t cb_iters = 1;
175 callback_test->add_option(
"-i,--iters", cb_iters,
176 "Number of iterations to run");
178 CLI::App *hostmemtestSub =
179 cli.add_subcommand(
"hostmem",
"Run the host memory test");
181 bool hmWrite =
false;
184 hostmemtestSub->add_flag(
"-w,--write", hmWrite,
185 "Enable host memory write test");
186 hostmemtestSub->add_flag(
"-r,--read", hmRead,
"Enable host memory read test");
187 hostmemtestSub->add_option(
188 "--widths", hostmemWidths,
191 CLI::App *dmatestSub = cli.add_subcommand(
"dma",
"Run the DMA test");
192 bool dmaRead =
false;
193 bool dmaWrite =
false;
195 dmatestSub->add_flag(
"-w,--write", dmaWrite,
"Enable dma write test");
196 dmatestSub->add_flag(
"-r,--read", dmaRead,
"Enable dma read test");
197 dmatestSub->add_option(
"--widths", dmaWidths,
201 CLI::App *bandwidthSub =
202 cli.add_subcommand(
"bandwidth",
"Run the bandwidth test");
203 uint32_t xferCount = 1000;
204 bandwidthSub->add_option(
"-c,--count", xferCount,
205 "Number of transfers to perform");
206 bool bandwidthRead =
false;
207 bool bandwidthWrite =
false;
210 bandwidthSub->add_option(
"--widths", bandwidthWidths,
211 "Width of the transfers to perform (default: " +
213 bandwidthSub->add_flag(
"-w,--write", bandwidthWrite,
214 "Enable bandwidth write");
215 bandwidthSub->add_flag(
"-r,--read", bandwidthRead,
"Enable bandwidth read");
217 CLI::App *hostmembwSub =
218 cli.add_subcommand(
"hostmembw",
"Run the host memory bandwidth test");
219 uint32_t hmBwCount = 1000;
220 bool hmBwRead =
false;
221 bool hmBwWrite =
false;
223 hostmembwSub->add_option(
"-c,--count", hmBwCount,
224 "Number of hostmem transfers");
225 hostmembwSub->add_option(
226 "--widths", hmBwWidths,
228 hostmembwSub->add_flag(
"-w,--write", hmBwWrite,
229 "Measure hostmem write bandwidth");
230 hostmembwSub->add_flag(
"-r,--read", hmBwRead,
231 "Measure hostmem read bandwidth");
233 CLI::App *loopbackSub =
234 cli.add_subcommand(
"loopback",
"Test LoopbackInOutAdd function service");
235 uint32_t loopbackIters = 10;
236 bool loopbackPipeline =
false;
237 loopbackSub->add_option(
"-i,--iters", loopbackIters,
238 "Number of function invocations (default 10)");
239 loopbackSub->add_flag(
"-p,--pipeline", loopbackPipeline,
240 "Pipeline all calls then collect results");
242 CLI::App *aggBwSub = cli.add_subcommand(
244 "Aggregate hostmem bandwidth across four units (readmem*, writemem*)");
245 uint32_t aggWidth = 512;
246 uint32_t aggCount = 1000;
247 bool aggRead =
false;
248 bool aggWrite =
false;
249 aggBwSub->add_option(
251 "Bit width (default 512; other widths ignored if absent)");
252 aggBwSub->add_option(
"-c,--count", aggCount,
"Flits per unit (default 1000)");
253 aggBwSub->add_flag(
"-r,--read", aggRead,
"Include read units");
254 aggBwSub->add_flag(
"-w,--write", aggWrite,
"Include write units");
256 CLI::App *streamingAddSub = cli.add_subcommand(
257 "streaming_add",
"Test StreamingAdder function service with list input");
258 uint32_t streamingAddAmt = 5;
259 uint32_t streamingNumItems = 5;
260 bool streamingTranslate =
false;
261 streamingAddSub->add_option(
"-a,--add", streamingAddAmt,
262 "Amount to add to each element (default 5)");
263 streamingAddSub->add_option(
"-n,--num-items", streamingNumItems,
264 "Number of random items in the list (default 5)");
265 streamingAddSub->add_flag(
"-t,--translate", streamingTranslate,
266 "Use message translation (list translation)");
268 CLI::App *coordTranslateSub = cli.add_subcommand(
270 "Test CoordTranslator function service with list of coordinates");
271 uint32_t coordXTrans = 10;
272 uint32_t coordYTrans = 20;
273 uint32_t coordNumItems = 5;
274 coordTranslateSub->add_option(
"-x,--x-translation", coordXTrans,
275 "X translation amount (default 10)");
276 coordTranslateSub->add_option(
"-y,--y-translation", coordYTrans,
277 "Y translation amount (default 20)");
278 coordTranslateSub->add_option(
"-n,--num-coords", coordNumItems,
279 "Number of random coordinates (default 5)");
281 CLI::App *serialCoordTranslateSub = cli.add_subcommand(
283 "Test SerialCoordTranslator function service with list of coordinates");
284 uint32_t serialBatchSize = 240;
285 serialCoordTranslateSub->add_option(
"-x,--x-translation", coordXTrans,
286 "X translation amount (default 10)");
287 serialCoordTranslateSub->add_option(
"-y,--y-translation", coordYTrans,
288 "Y translation amount (default 20)");
289 serialCoordTranslateSub->add_option(
290 "-n,--num-coords", coordNumItems,
291 "Number of random coordinates (default 5)");
292 serialCoordTranslateSub
293 ->add_option(
"-b,--batch-size", serialBatchSize,
294 "Coordinates per header (default 240, max 65535)")
295 ->check(CLI::Range(1u, 0xFFFFu));
297 if (
int rc = cli.
esiParse(argc, argv))
299 if (!cli.get_help_ptr()->empty())
306 ctxt.
getLogger().
info(
"esitester",
"Connected to accelerator.");
307 Manifest manifest(ctxt, info.getJsonManifest());
312 if (*callback_test) {
314 }
else if (*hostmemtestSub) {
315 hostmemTest(acc, accel, hostmemWidths, hmWrite, hmRead);
316 }
else if (*loopbackSub) {
318 }
else if (*dmatestSub) {
319 dmaTest(acc, accel, dmaWidths, dmaRead, dmaWrite);
320 }
else if (*bandwidthSub) {
321 bandwidthTest(acc, accel, bandwidthWidths, xferCount, bandwidthRead,
323 }
else if (*hostmembwSub) {
326 }
else if (*aggBwSub) {
329 }
else if (*streamingAddSub) {
330 if (streamingTranslate)
335 }
else if (*coordTranslateSub) {
337 }
else if (*serialCoordTranslateSub) {
339 coordNumItems, serialBatchSize);
343 }
catch (std::exception &e) {
348 std::cout <<
"Exiting successfully\n";
353 uint32_t iterations) {
356 throw std::runtime_error(
"No cb_test child found in accelerator");
357 auto &ports = cb_test->second->getPorts();
358 auto cmd_port = ports.find(
AppID(
"cmd"));
359 if (cmd_port == ports.end())
360 throw std::runtime_error(
"No cmd port found in cb_test child");
363 throw std::runtime_error(
"cb_test cmd port is not MMIO");
365 auto f = ports.find(
AppID(
"cb"));
366 if (f == ports.end())
367 throw std::runtime_error(
"No cb port found in accelerator");
371 throw std::runtime_error(
"cb port is not a CallService::Callback");
373 std::atomic<uint32_t> callbackCount = 0;
376 callbackCount.fetch_add(1);
378 [&](std::string &subsystem, std::string &msg,
379 std::unique_ptr<std::map<std::string, std::any>> &details) {
380 subsystem =
"ESITESTER";
381 msg =
"Received callback";
382 details = std::make_unique<std::map<std::string, std::any>>();
383 details->emplace(
"data", data);
385 std::cout <<
"callback: " << *data.as<uint64_t>() << std::endl;
390 for (uint32_t i = 0; i < iterations; ++i) {
391 conn->
getLogger().
info(
"esitester",
"Issuing callback command iteration " +
392 std::to_string(i) +
"/" +
393 std::to_string(iterations));
394 cmdMMIO->write(0x10, i);
396 for (uint32_t wait = 0; wait < 1000; ++wait) {
397 if (callbackCount.load() > i)
399 std::this_thread::sleep_for(std::chrono::milliseconds(1));
401 if (callbackCount.load() <= i)
402 throw std::runtime_error(
"Callback test failed. No callback received");
410 std::cout <<
"Running hostmem WRITE test with width " << width << std::endl;
411 uint64_t *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
412 auto check = [&](
bool print) {
414 for (
size_t i = 0; i < 9; ++i) {
416 printf(
"[write] dataPtr[%zu] = 0x%016lx\n", i, dataPtr[i]);
417 if (i < (width + 63) / 64 && dataPtr[i] == 0xFFFFFFFFFFFFFFFFull)
425 throw std::runtime_error(
426 "hostmem write test failed. No writemem child found");
427 auto &writeMemPorts = writeMemChildIter->second->getPorts();
429 auto cmdPortIter = writeMemPorts.find(
AppID(
"cmd", width));
430 if (cmdPortIter == writeMemPorts.end())
431 throw std::runtime_error(
432 "hostmem write test failed. No (cmd,width) MMIO port");
435 throw std::runtime_error(
436 "hostmem write test failed. (cmd,width) port not MMIO");
438 auto issuedPortIter = writeMemPorts.find(
AppID(
"addrCmdIssued"));
439 if (issuedPortIter == writeMemPorts.end())
440 throw std::runtime_error(
441 "hostmem write test failed. addrCmdIssued missing");
442 auto *addrCmdIssuedPort =
444 if (!addrCmdIssuedPort)
445 throw std::runtime_error(
446 "hostmem write test failed. addrCmdIssued not telemetry");
447 addrCmdIssuedPort->connect();
449 auto responsesPortIter = writeMemPorts.find(
AppID(
"addrCmdResponses"));
450 if (responsesPortIter == writeMemPorts.end())
451 throw std::runtime_error(
452 "hostmem write test failed. addrCmdResponses missing");
453 auto *addrCmdResponsesPort =
455 if (!addrCmdResponsesPort)
456 throw std::runtime_error(
457 "hostmem write test failed. addrCmdResponses not telemetry");
458 addrCmdResponsesPort->connect();
460 for (
size_t i = 0, e = 9; i < e; ++i)
461 dataPtr[i] = 0xFFFFFFFFFFFFFFFFull;
463 cmdMMIO->write(0x10,
reinterpret_cast<uint64_t
>(region.
getDevicePtr()));
464 cmdMMIO->write(0x18, 1);
465 cmdMMIO->write(0x20, 1);
467 for (
int i = 0; i < 100; ++i) {
468 auto issued = addrCmdIssuedPort->readInt();
469 auto responses = addrCmdResponsesPort->readInt();
470 if (issued == 1 && responses == 1) {
474 std::this_thread::sleep_for(std::chrono::microseconds(100));
478 throw std::runtime_error(
"hostmem write test (" + std::to_string(width) +
479 " bits) timeout waiting for completion");
482 throw std::runtime_error(
"hostmem write test failed (" +
483 std::to_string(width) +
" bits)");
489 std::cout <<
"Running hostmem READ test with width " << width << std::endl;
492 throw std::runtime_error(
493 "hostmem read test failed. No readmem child found");
495 auto &readMemPorts = readMemChildIter->second->getPorts();
496 auto addrCmdPortIter = readMemPorts.find(
AppID(
"cmd", width));
497 if (addrCmdPortIter == readMemPorts.end())
498 throw std::runtime_error(
499 "hostmem read test failed. No AddressCommand MMIO port");
503 throw std::runtime_error(
504 "hostmem read test failed. AddressCommand port not MMIO");
506 auto lastReadPortIter = readMemPorts.find(
AppID(
"lastReadLSB"));
507 if (lastReadPortIter == readMemPorts.end())
508 throw std::runtime_error(
"hostmem read test failed. lastReadLSB missing");
512 throw std::runtime_error(
513 "hostmem read test failed. lastReadLSB not telemetry");
514 lastReadPort->connect();
516 auto issuedPortIter = readMemPorts.find(
AppID(
"addrCmdIssued"));
517 if (issuedPortIter == readMemPorts.end())
518 throw std::runtime_error(
"hostmem read test failed. addrCmdIssued missing");
519 auto *addrCmdIssuedPort =
521 if (!addrCmdIssuedPort)
522 throw std::runtime_error(
523 "hostmem read test failed. addrCmdIssued not telemetry");
524 addrCmdIssuedPort->connect();
526 auto responsesPortIter = readMemPorts.find(
AppID(
"addrCmdResponses"));
527 if (responsesPortIter == readMemPorts.end())
528 throw std::runtime_error(
529 "hostmem read test failed. addrCmdResponses missing");
530 auto *addrCmdResponsesPort =
532 if (!addrCmdResponsesPort)
533 throw std::runtime_error(
534 "hostmem read test failed. addrCmdResponses not telemetry");
535 addrCmdResponsesPort->connect();
537 for (
size_t i = 0; i < 8; ++i) {
538 auto *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
539 dataPtr[0] = 0x12345678ull << i;
540 dataPtr[1] = 0xDEADBEEFull << i;
542 addrCmdMMIO->write(0x10,
reinterpret_cast<uint64_t
>(region.
getDevicePtr()));
543 addrCmdMMIO->write(0x18, 1);
544 addrCmdMMIO->write(0x20, 1);
546 for (
int waitLoop = 0; waitLoop < 100; ++waitLoop) {
547 auto issued = addrCmdIssuedPort->readInt();
548 auto responses = addrCmdResponsesPort->readInt();
549 if (issued == 1 && responses == 1) {
553 std::this_thread::sleep_for(std::chrono::milliseconds(10));
556 throw std::runtime_error(
"hostmem read (" + std::to_string(width) +
557 " bits) timeout waiting for completion");
558 uint64_t captured = lastReadPort->readInt();
559 uint64_t expected = dataPtr[0];
561 expected &= ((1ull << width) - 1);
562 if (captured != expected)
563 throw std::runtime_error(
"hostmem read test (" + std::to_string(width) +
564 " bits) failed. Expected " +
571 const std::vector<uint32_t> &widths,
bool write,
576 auto scratchRegion = hostmem->allocate(1024 * 1024,
577 {.writeable =
true});
578 uint64_t *dataPtr =
static_cast<uint64_t *
>(scratchRegion->getPtr());
580 "Running host memory test with region size " +
581 std::to_string(scratchRegion->getSize()) +
582 " bytes at 0x" +
toHex(dataPtr));
583 for (
size_t i = 0; i < scratchRegion->getSize() / 8; ++i)
585 scratchRegion->flush();
588 for (
size_t width : widths) {
594 }
catch (std::exception &e) {
595 conn->
getLogger().
error(
"esitester",
"Hostmem test failed for width " +
596 std::to_string(width) +
": " +
602 throw std::runtime_error(
"Hostmem test failed");
603 std::cout <<
"Hostmem test passed" << std::endl;
609 logger.
info(
"esitester",
610 "== Running DMA read test with width " + std::to_string(width));
615 throw std::runtime_error(
"dma read test failed. No tohostdma[" +
616 std::to_string(width) +
"] found");
619 throw std::runtime_error(
"dma read test failed. MMIO port is not MMIO");
626 size_t xferCount = 24;
629 toHostMMIO->write(0, xferCount);
630 for (
size_t i = 0; i < xferCount; ++i) {
633 uint64_t val = *data.as<uint64_t>();
635 throw std::runtime_error(
"dma read test failed. Out of order data");
638 logger.
debug(
"esitester",
639 "Cycle count [" + std::to_string(i) +
"] = 0x" + data.toHex());
642 std::cout <<
" DMA read test for " << width <<
" bits passed" << std::endl;
648 logger.
info(
"esitester",
649 "Running DMA write test with width " + std::to_string(width));
653 if (!fromHostMMIOPort)
654 throw std::runtime_error(
"dma read test for " +
toString(width) +
655 " bits failed. No fromhostdma[" +
656 std::to_string(width) +
"] found");
659 throw std::runtime_error(
"dma write test for " +
toString(width) +
660 " bits failed. MMIO port is not MMIO");
665 throw std::runtime_error(
"dma write test for " +
toString(width) +
666 " bits failed. No out port found");
670 size_t xferCount = 24;
671 uint8_t *data =
new uint8_t[width];
672 for (
size_t i = 0; i < width / 8; ++i)
674 fromHostMMIO->read(8);
675 fromHostMMIO->write(0, xferCount);
676 for (
size_t i = 1; i < xferCount + 1; ++i) {
683 std::this_thread::sleep_for(std::chrono::milliseconds(10));
685 }
while (!successWrite && ++attempts < 100);
687 throw std::runtime_error(
"dma write test for " +
toString(width) +
688 " bits failed. Write failed");
689 uint64_t lastReadMMIO;
690 for (
size_t a = 0; a < 20; ++a) {
691 lastReadMMIO = fromHostMMIO->read(8);
692 if (lastReadMMIO == i)
694 std::this_thread::sleep_for(std::chrono::milliseconds(10));
696 throw std::runtime_error(
"dma write for " +
toString(width) +
697 " bits test failed. Read from MMIO failed");
702 std::cout <<
" DMA write test for " << width <<
" bits passed" << std::endl;
706 const std::vector<uint32_t> &widths,
bool read,
710 for (
size_t width : widths)
713 }
catch (std::exception &e) {
715 std::cerr <<
"DMA write test for " << width
716 <<
" bits failed: " << e.what() << std::endl;
719 for (
size_t width : widths)
722 throw std::runtime_error(
"DMA test failed");
723 std::cout <<
"DMA test passed" << std::endl;
731 size_t width,
size_t xferCount) {
737 throw std::runtime_error(
"bandwidth test failed. No tohostdma[" +
738 std::to_string(width) +
"] found");
741 throw std::runtime_error(
"bandwidth test failed. MMIO port is not MMIO");
749 logger.
info(
"esitester",
"Starting read bandwidth test with " +
750 std::to_string(xferCount) +
" x " +
751 std::to_string(width) +
" bit transfers");
753 auto start = std::chrono::high_resolution_clock::now();
754 toHostMMIO->write(0, xferCount);
755 for (
size_t i = 0; i < xferCount; ++i) {
758 [i, &data](std::string &subsystem, std::string &msg,
759 std::unique_ptr<std::map<std::string, std::any>> &details) {
760 subsystem =
"esitester";
761 msg =
"Cycle count [" + std::to_string(i) +
"] = 0x" + data.toHex();
764 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
765 std::chrono::high_resolution_clock::now() - start);
767 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
768 logger.
info(
"esitester",
769 " Bandwidth test: " + std::to_string(xferCount) +
" x " +
770 std::to_string(width) +
" bit transfers in " +
771 std::to_string(duration.count()) +
" microseconds");
776 size_t width,
size_t xferCount) {
781 if (!fromHostMMIOPort)
782 throw std::runtime_error(
"bandwidth test failed. No fromhostdma[" +
783 std::to_string(width) +
"] found");
786 throw std::runtime_error(
"bandwidth test failed. MMIO port is not MMIO");
794 logger.
info(
"esitester",
"Starting write bandwidth test with " +
795 std::to_string(xferCount) +
" x " +
796 std::to_string(width) +
" bit transfers");
797 std::vector<uint8_t> dataVec(width / 8);
798 for (
size_t i = 0; i < width / 8; ++i)
801 auto start = std::chrono::high_resolution_clock::now();
802 fromHostMMIO->write(0, xferCount);
803 for (
size_t i = 0; i < xferCount; ++i) {
806 [i, &data](std::string &subsystem, std::string &msg,
807 std::unique_ptr<std::map<std::string, std::any>> &details) {
808 subsystem =
"esitester";
809 msg =
"Cycle count [" + std::to_string(i) +
"] = 0x" + data.toHex();
812 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
813 std::chrono::high_resolution_clock::now() - start);
815 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
816 logger.
info(
"esitester",
817 " Bandwidth test: " + std::to_string(xferCount) +
" x " +
818 std::to_string(width) +
" bit transfers in " +
819 std::to_string(duration.count()) +
" microseconds");
824 const std::vector<uint32_t> &widths,
825 uint32_t xferCount,
bool read,
bool write) {
827 for (uint32_t w : widths)
830 for (uint32_t w : widths)
841 uint32_t width, uint32_t xferCount) {
843 logger.
info(
"esitester",
"Starting hostmem WRITE bandwidth test: " +
844 std::to_string(xferCount) +
" x " +
845 std::to_string(width) +
" bits");
849 throw std::runtime_error(
"hostmem write bandwidth: writemem child missing");
850 auto &writeMemPorts = writeMemChildIter->second->getPorts();
852 auto cmdPortIter = writeMemPorts.find(
AppID(
"cmd", width));
853 if (cmdPortIter == writeMemPorts.end())
854 throw std::runtime_error(
"hostmem write bandwidth: cmd MMIO missing");
857 throw std::runtime_error(
"hostmem write bandwidth: cmd not MMIO");
859 auto issuedIter = writeMemPorts.find(
AppID(
"addrCmdIssued"));
860 auto respIter = writeMemPorts.find(
AppID(
"addrCmdResponses"));
861 auto cycleCount = writeMemPorts.find(
AppID(
"addrCmdCycles"));
862 if (issuedIter == writeMemPorts.end() || respIter == writeMemPorts.end() ||
863 cycleCount == writeMemPorts.end())
864 throw std::runtime_error(
"hostmem write bandwidth: telemetry missing");
870 if (!issuedPort || !respPort || !cyclePort)
871 throw std::runtime_error(
872 "hostmem write bandwidth: telemetry type mismatch");
874 issuedPort->connect();
879 uint64_t *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
880 size_t words = region.
getSize() / 8;
881 for (
size_t i = 0; i < words; ++i)
882 dataPtr[i] = i + 0xA5A50000;
885 auto start = std::chrono::high_resolution_clock::now();
887 uint64_t devPtr =
reinterpret_cast<uint64_t
>(region.
getDevicePtr());
888 cmdMMIO->write(0x10, devPtr);
889 cmdMMIO->write(0x18, xferCount);
890 cmdMMIO->write(0x20, 1);
893 bool completed =
false;
894 for (
int wait = 0; wait < 100000; ++wait) {
895 uint64_t respNow = respPort->
readInt();
896 if (respNow == xferCount) {
900 std::this_thread::sleep_for(std::chrono::microseconds(50));
903 throw std::runtime_error(
"hostmem write bandwidth timeout");
904 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
905 std::chrono::high_resolution_clock::now() - start);
907 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
908 uint64_t cycles = cyclePort->
readInt();
909 double bytesPerCycle = (double)xferCount * (width / 8.0) / (double)cycles;
910 std::cout <<
"[WRITE] Hostmem bandwidth (" << std::to_string(width)
912 << std::to_string(xferCount) <<
" flits in "
913 << std::to_string(duration.count()) <<
" us, "
914 << std::to_string(cycles) <<
" cycles, " << bytesPerCycle
915 <<
" bytes/cycle" << std::endl;
921 uint32_t width, uint32_t xferCount) {
923 logger.
info(
"esitester",
"Starting hostmem READ bandwidth test: " +
924 std::to_string(xferCount) +
" x " +
925 std::to_string(width) +
" bits");
929 throw std::runtime_error(
"hostmem read bandwidth: readmem child missing");
930 auto &readMemPorts = readMemChildIter->second->getPorts();
932 auto cmdPortIter = readMemPorts.find(
AppID(
"cmd", width));
933 if (cmdPortIter == readMemPorts.end())
934 throw std::runtime_error(
"hostmem read bandwidth: cmd MMIO missing");
937 throw std::runtime_error(
"hostmem read bandwidth: cmd not MMIO");
939 auto issuedIter = readMemPorts.find(
AppID(
"addrCmdIssued"));
940 auto respIter = readMemPorts.find(
AppID(
"addrCmdResponses"));
941 auto cyclePort = readMemPorts.find(
AppID(
"addrCmdCycles"));
942 if (issuedIter == readMemPorts.end() || respIter == readMemPorts.end() ||
943 cyclePort == readMemPorts.end())
944 throw std::runtime_error(
"hostmem read bandwidth: telemetry missing");
950 if (!issuedPort || !respPort || !cycleCntPort)
951 throw std::runtime_error(
"hostmem read bandwidth: telemetry type mismatch");
952 issuedPort->connect();
957 uint64_t *dataPtr =
static_cast<uint64_t *
>(region.
getPtr());
958 size_t words64 = region.
getSize() / 8;
959 for (
size_t i = 0; i < words64; ++i)
960 dataPtr[i] = 0xCAFEBABE0000ull + i;
962 uint64_t devPtr =
reinterpret_cast<uint64_t
>(region.
getDevicePtr());
963 auto start = std::chrono::high_resolution_clock::now();
965 cmdMMIO->write(0x10, devPtr);
966 cmdMMIO->write(0x18, xferCount);
967 cmdMMIO->write(0x20, 1);
970 for (
int wait = 0; wait < 100000; ++wait) {
971 uint64_t respNow = respPort->
readInt();
972 if (respNow == xferCount) {
976 std::this_thread::sleep_for(std::chrono::microseconds(50));
979 throw std::runtime_error(
"hostmem read bandwidth timeout");
980 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
981 std::chrono::high_resolution_clock::now() - start);
983 (double)xferCount * (width / 8.0) * 1e6 / (double)duration.count();
984 uint64_t cycles = cycleCntPort->
readInt();
985 double bytesPerCycle = (double)xferCount * (width / 8.0) / (double)cycles;
986 std::cout <<
"[ READ] Hostmem bandwidth (" << width
988 <<
" flits in " << duration.count() <<
" us, " << cycles
989 <<
" cycles, " << bytesPerCycle <<
" bytes/cycle" << std::endl;
994 const std::vector<uint32_t> &widths,
bool read,
998 auto region = hostmemSvc->allocate(1024 * 1024 * 1024,
999 {.writeable =
true});
1000 for (uint32_t w : widths) {
1009 uint32_t iterations,
bool pipeline) {
1013 throw std::runtime_error(
"Loopback test: no 'loopback' child");
1014 auto &ports = loopbackChild->second->getPorts();
1015 auto addIter = ports.find(
AppID(
"add"));
1016 if (addIter == ports.end())
1017 throw std::runtime_error(
"Loopback test: no 'add' port");
1022 throw std::runtime_error(
1023 "Loopback test: 'add' port not a FuncService::Function");
1024 funcPort->connect();
1025 if (iterations == 0) {
1026 logger.
info(
"esitester",
"Loopback add test: 0 iterations (skipped)");
1029 std::mt19937_64 rng(0xC0FFEE);
1030 std::uniform_int_distribution<uint32_t> dist(0, (1u << 24) - 1);
1033 auto start = std::chrono::high_resolution_clock::now();
1034 for (uint32_t i = 0; i < iterations; ++i) {
1035 uint32_t argVal = dist(rng);
1036 uint32_t expected = (argVal + 11) & 0xFFFF;
1037 uint8_t argBytes[3] = {
1038 static_cast<uint8_t
>(argVal & 0xFF),
1039 static_cast<uint8_t
>((argVal >> 8) & 0xFF),
1040 static_cast<uint8_t
>((argVal >> 16) & 0xFF),
1043 MessageData resMsg = funcPort->call(argMsg).get();
1044 uint16_t got = *resMsg.
as<uint16_t>();
1045 std::cout <<
"[loopback] i=" << i <<
" arg=0x" <<
esi::toHex(argVal)
1048 if (got != expected)
1049 throw std::runtime_error(
"Loopback mismatch (non-pipelined)");
1051 auto end = std::chrono::high_resolution_clock::now();
1052 auto us = std::chrono::duration_cast<std::chrono::microseconds>(end - start)
1054 double callsPerSec = (double)iterations * 1e6 / (
double)us;
1055 logger.
info(
"esitester",
"Loopback add test passed (non-pipelined, " +
1056 std::to_string(iterations) +
" calls, " +
1057 std::to_string(us) +
" us, " +
1058 std::to_string(callsPerSec) +
" calls/s)");
1061 std::vector<std::future<MessageData>> futures;
1062 futures.reserve(iterations);
1063 std::vector<uint32_t> expectedVals;
1064 expectedVals.reserve(iterations);
1066 auto issueStart = std::chrono::high_resolution_clock::now();
1067 for (uint32_t i = 0; i < iterations; ++i) {
1068 uint32_t argVal = dist(rng);
1069 uint32_t expected = (argVal + 11) & 0xFFFF;
1070 uint8_t argBytes[3] = {
1071 static_cast<uint8_t
>(argVal & 0xFF),
1072 static_cast<uint8_t
>((argVal >> 8) & 0xFF),
1073 static_cast<uint8_t
>((argVal >> 16) & 0xFF),
1075 futures.emplace_back(funcPort->call(
MessageData(argBytes, 3)));
1076 expectedVals.emplace_back(expected);
1078 auto issueEnd = std::chrono::high_resolution_clock::now();
1080 for (uint32_t i = 0; i < iterations; ++i) {
1082 uint16_t got = *resMsg.
as<uint16_t>();
1083 uint16_t exp = (uint16_t)expectedVals[i];
1084 std::cout <<
"[loopback-pipelined] i=" << i <<
" got=0x"
1087 throw std::runtime_error(
"Loopback mismatch (pipelined) idx=" +
1090 auto collectEnd = std::chrono::high_resolution_clock::now();
1092 auto issueUs = std::chrono::duration_cast<std::chrono::microseconds>(
1093 issueEnd - issueStart)
1095 auto totalUs = std::chrono::duration_cast<std::chrono::microseconds>(
1096 collectEnd - issueStart)
1099 double issueRate = (double)iterations * 1e6 / (
double)issueUs;
1100 double completionRate = (double)iterations * 1e6 / (
double)totalUs;
1102 logger.
info(
"esitester",
"Loopback add test passed (pipelined). Issued " +
1103 std::to_string(iterations) +
" in " +
1104 std::to_string(issueUs) +
" us (" +
1105 std::to_string(issueRate) +
1106 " calls/s), total " + std::to_string(totalUs) +
1107 " us (" + std::to_string(completionRate) +
1108 " calls/s effective)");
1114 uint32_t xferCount,
bool read,
1117 if (!read && !write) {
1118 std::cout <<
"aggbandwidth: nothing to do (enable --read and/or --write)\n";
1123 "Aggregate hostmem bandwidth start width=" + std::to_string(width) +
1124 " count=" + std::to_string(xferCount) +
1125 " read=" + (read ?
"Y" :
"N") +
" write=" + (write ?
"Y" :
"N"));
1128 hostmemSvc->
start();
1132 bool isRead =
false;
1133 bool isWrite =
false;
1134 std::unique_ptr<esi::services::HostMem::HostMemRegion> region;
1138 bool launched =
false;
1141 uint64_t duration_us = 0;
1142 uint64_t cycleCount = 0;
1143 std::chrono::high_resolution_clock::time_point start;
1145 std::vector<Unit> units;
1146 const std::vector<std::string> readPrefixes = {
"readmem",
"readmem_0",
1147 "readmem_1",
"readmem_2"};
1148 const std::vector<std::string> writePrefixes = {
"writemem",
"writemem_0",
1149 "writemem_1",
"writemem_2"};
1151 auto addUnits = [&](
const std::vector<std::string> &pref,
bool doRead,
1153 for (
auto &p : pref) {
1158 auto &ports = childIt->second->getPorts();
1159 auto cmdIt = ports.find(
AppID(
"cmd", width));
1160 auto respIt = ports.find(
AppID(
"addrCmdResponses"));
1161 auto cycIt = ports.find(
AppID(
"addrCmdCycles"));
1162 if (cmdIt == ports.end() || respIt == ports.end() || cycIt == ports.end())
1167 if (!cmd || !resp || !cyc)
1174 u.isWrite = doWrite;
1175 u.region = hostmemSvc->allocate(1024 * 1024 * 1024, {.writeable =
true});
1177 uint64_t *ptr =
static_cast<uint64_t *
>(u.region->getPtr());
1178 size_t words = u.region->getSize() / 8;
1179 for (
size_t i = 0; i < words; ++i)
1181 (p[0] ==
'w' ? (0xA5A500000000ull + i) : (0xCAFEBABE0000ull + i));
1186 u.bytes = uint64_t(xferCount) * (width / 8);
1187 units.emplace_back(std::move(u));
1191 addUnits(readPrefixes,
true,
false);
1193 addUnits(writePrefixes,
false,
true);
1194 if (units.empty()) {
1195 std::cout <<
"aggbandwidth: no matching units present for width " << width
1200 auto wallStart = std::chrono::high_resolution_clock::now();
1202 for (
auto &u : units) {
1203 uint64_t devPtr =
reinterpret_cast<uint64_t
>(u.region->getDevicePtr());
1204 u.cmd->write(0x10, devPtr);
1205 u.cmd->write(0x18, xferCount);
1206 u.cmd->write(0x20, 1);
1207 u.start = std::chrono::high_resolution_clock::now();
1212 const uint64_t timeoutLoops = 200000;
1215 bool allDone =
true;
1216 for (
auto &u : units) {
1219 if (u.resp->readInt() == xferCount) {
1220 auto end = std::chrono::high_resolution_clock::now();
1222 std::chrono::duration_cast<std::chrono::microseconds>(end - u.start)
1224 u.cycleCount = u.cycles->readInt();
1232 if (++loops >= timeoutLoops)
1233 throw std::runtime_error(
"aggbandwidth: timeout");
1234 std::this_thread::sleep_for(std::chrono::microseconds(50));
1236 auto wallUs = std::chrono::duration_cast<std::chrono::microseconds>(
1237 std::chrono::high_resolution_clock::now() - wallStart)
1240 uint64_t totalBytes = 0;
1241 uint64_t totalReadBytes = 0;
1242 uint64_t totalWriteBytes = 0;
1243 for (
auto &u : units) {
1244 totalBytes += u.bytes;
1246 totalReadBytes += u.bytes;
1248 totalWriteBytes += u.bytes;
1249 double unitBps = (double)u.bytes * 1e6 / (
double)u.duration_us;
1250 std::cout <<
"[agg-unit] " << u.prefix <<
"[" << width <<
"] "
1251 << (u.isRead ?
"READ" : (u.isWrite ?
"WRITE" :
"UNK"))
1252 <<
" bytes=" <<
humanBytes(u.bytes) <<
" (" << u.bytes <<
" B)"
1253 <<
" time=" <<
humanTimeUS(u.duration_us) <<
" (" << u.duration_us
1254 <<
" us) cycles=" << u.cycleCount
1260 totalReadBytes ? (double)totalReadBytes * 1e6 / (
double)wallUs : 0.0;
1261 double aggWriteBps =
1262 totalWriteBytes ? (double)totalWriteBytes * 1e6 / (
double)wallUs : 0.0;
1263 double aggCombinedBps =
1264 totalBytes ? (double)totalBytes * 1e6 / (
double)wallUs : 0.0;
1266 std::cout <<
"[agg-total] units=" << units.size()
1267 <<
" read_bytes=" <<
humanBytes(totalReadBytes) <<
" ("
1268 << totalReadBytes <<
" B)"
1270 <<
" write_bytes=" <<
humanBytes(totalWriteBytes) <<
" ("
1271 << totalWriteBytes <<
" B)"
1273 <<
" combined_bytes=" <<
humanBytes(totalBytes) <<
" ("
1274 << totalBytes <<
" B)"
1276 <<
" wall_time=" <<
humanTimeUS(wallUs) <<
" (" << wallUs <<
" us)"
1278 logger.
info(
"esitester",
"Aggregate hostmem bandwidth test complete");
1284#pragma pack(push, 1)
1292 "StreamingAddArg must be 9 bytes packed");
1297#pragma pack(push, 1)
1304 "StreamingAddResult must be 5 bytes packed");
1310 uint32_t addAmt, uint32_t numItems) {
1312 logger.
info(
"esitester",
"Starting streaming add test with add_amt=" +
1313 std::to_string(addAmt) +
1314 ", num_items=" + std::to_string(numItems));
1317 std::mt19937 rng(0xDEADBEEF);
1318 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1319 std::vector<uint32_t> inputData;
1320 inputData.reserve(numItems);
1321 for (uint32_t i = 0; i < numItems; ++i)
1322 inputData.push_back(dist(rng));
1325 auto streamingAdderChild =
1327 if (streamingAdderChild == accel->
getChildren().end())
1328 throw std::runtime_error(
1329 "Streaming add test: no 'streaming_adder' child found");
1331 auto &ports = streamingAdderChild->second->getPorts();
1332 auto addIter = ports.find(
AppID(
"streaming_add"));
1333 if (addIter == ports.end())
1334 throw std::runtime_error(
1335 "Streaming add test: no 'streaming_add' port found");
1347 for (
size_t i = 0; i < inputData.size(); ++i) {
1350 arg.
input = inputData[i];
1351 arg.
last = (i == inputData.size() - 1) ? 1 : 0;
1353 MessageData(
reinterpret_cast<const uint8_t *
>(&arg),
sizeof(arg)));
1354 logger.
debug(
"esitester",
"Sent {add_amt=" + std::to_string(arg.
addAmt) +
1355 ", input=" + std::to_string(arg.
input) +
1356 ", last=" + (arg.
last ?
"true" :
"false") +
1361 std::vector<uint32_t> results;
1362 bool lastSeen =
false;
1365 resultPort.
read(resMsg);
1367 throw std::runtime_error(
1368 "Streaming add test: unexpected result message size");
1372 lastSeen = res->
last != 0;
1373 results.push_back(res->data);
1374 logger.
debug(
"esitester",
"Received result=" + std::to_string(res->data) +
1375 " (last=" + (lastSeen ?
"true" :
"false") +
1380 if (results.size() != inputData.size())
1381 throw std::runtime_error(
1382 "Streaming add test: result size mismatch. Expected " +
1383 std::to_string(inputData.size()) +
", got " +
1384 std::to_string(results.size()));
1387 std::cout <<
"Streaming add test results:" << std::endl;
1388 for (
size_t i = 0; i < inputData.size(); ++i) {
1389 uint32_t expected = inputData[i] + addAmt;
1390 std::cout <<
" input[" << i <<
"]=" << inputData[i] <<
" + " << addAmt
1391 <<
" = " << results[i] <<
" (expected " << expected <<
")";
1392 if (results[i] != expected) {
1393 std::cout <<
" MISMATCH!";
1396 std::cout << std::endl;
1403 throw std::runtime_error(
"Streaming add test failed: result mismatch");
1405 logger.
info(
"esitester",
"Streaming add test passed");
1406 std::cout <<
"Streaming add test passed" << std::endl;
1425#pragma pack(push, 1)
1433 uint32_t *
inputData() {
return reinterpret_cast<uint32_t *
>(
this + 1); }
1435 return reinterpret_cast<const uint32_t *
>(
this + 1);
1454#pragma pack(push, 1)
1460 uint32_t *
data() {
return reinterpret_cast<uint32_t *
>(
this + 1); }
1462 return reinterpret_cast<const uint32_t *
>(
this + 1);
1476 uint32_t numItems) {
1478 logger.
info(
"esitester",
1479 "Starting streaming add test (translated) with add_amt=" +
1480 std::to_string(addAmt) +
1481 ", num_items=" + std::to_string(numItems));
1484 std::mt19937 rng(0xDEADBEEF);
1485 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1486 std::vector<uint32_t> inputData;
1487 inputData.reserve(numItems);
1488 for (uint32_t i = 0; i < numItems; ++i)
1489 inputData.push_back(dist(rng));
1492 auto streamingAdderChild =
1494 if (streamingAdderChild == accel->
getChildren().end())
1495 throw std::runtime_error(
1496 "Streaming add test: no 'streaming_adder' child found");
1498 auto &ports = streamingAdderChild->second->getPorts();
1499 auto addIter = ports.find(
AppID(
"streaming_add"));
1500 if (addIter == ports.end())
1501 throw std::runtime_error(
1502 "Streaming add test: no 'streaming_add' port found");
1517 size_t allocSize = ((argSize + alignment - 1) / alignment) * alignment;
1520 throw std::bad_alloc();
1522 std::unique_ptr<void,
decltype(argDeleter)> argBuffer(argRaw, argDeleter);
1525 arg->addAmt = addAmt;
1526 for (uint32_t i = 0; i < numItems; ++i)
1527 arg->inputData()[i] = inputData[i];
1529 logger.
debug(
"esitester",
1530 "Sending translated argument: " + std::to_string(argSize) +
1531 " bytes, list_length=" + std::to_string(arg->inputLength) +
1532 ", add_amt=" + std::to_string(arg->addAmt));
1535 argPort.
write(
MessageData(
reinterpret_cast<const uint8_t *
>(arg), argSize));
1540 resultPort.
read(resMsg);
1542 logger.
debug(
"esitester",
"Received translated result: " +
1543 std::to_string(resMsg.
getSize()) +
" bytes");
1546 throw std::runtime_error(
1547 "Streaming add test (translated): result too small");
1549 const auto *result =
1554 throw std::runtime_error(
1555 "Streaming add test (translated): result data truncated");
1558 if (result->dataLength != inputData.size())
1559 throw std::runtime_error(
1560 "Streaming add test (translated): result size mismatch. Expected " +
1561 std::to_string(inputData.size()) +
", got " +
1562 std::to_string(result->dataLength));
1565 std::cout <<
"Streaming add test results:" << std::endl;
1566 for (
size_t i = 0; i < inputData.size(); ++i) {
1567 uint32_t expected = inputData[i] + addAmt;
1568 std::cout <<
" input[" << i <<
"]=" << inputData[i] <<
" + " << addAmt
1569 <<
" = " << result->
data()[i] <<
" (expected " << expected <<
")";
1570 if (result->data()[i] != expected) {
1571 std::cout <<
" MISMATCH!";
1574 std::cout << std::endl;
1581 throw std::runtime_error(
1582 "Streaming add test (translated) failed: result mismatch");
1584 logger.
info(
"esitester",
"Streaming add test passed (translated)");
1585 std::cout <<
"Streaming add test passed" << std::endl;
1596#pragma pack(push, 1)
1602static_assert(
sizeof(
Coord) == 8,
"Coord must be 8 bytes packed");
1613#pragma pack(push, 1)
1623 return reinterpret_cast<const Coord *
>(
this + 1);
1640#pragma pack(push, 1)
1648 return reinterpret_cast<const Coord *
>(
this + 1);
1661 uint32_t xTrans, uint32_t yTrans,
1662 uint32_t numCoords) {
1664 logger.
info(
"esitester",
"Starting coord translate test with x_trans=" +
1665 std::to_string(xTrans) +
1666 ", y_trans=" + std::to_string(yTrans) +
1667 ", num_coords=" + std::to_string(numCoords));
1672 std::mt19937 rng(0xDEADBEEF);
1673 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1674 std::vector<Coord> inputCoords;
1675 inputCoords.reserve(numCoords);
1676 for (uint32_t i = 0; i < numCoords; ++i) {
1680 inputCoords.push_back(c);
1684 auto coordTranslatorChild =
1686 if (coordTranslatorChild == accel->
getChildren().end())
1687 throw std::runtime_error(
1688 "Coord translate test: no 'coord_translator' child found");
1690 auto &ports = coordTranslatorChild->second->getPorts();
1691 auto translateIter = ports.find(
AppID(
"translate_coords"));
1692 if (translateIter == ports.end())
1693 throw std::runtime_error(
1694 "Coord translate test: no 'translate_coords' port found");
1700 throw std::runtime_error(
1701 "Coord translate test: 'translate_coords' port not a "
1702 "FuncService::Function");
1703 funcPort->connect();
1709 size_t allocSize = ((argSize + alignment - 1) / alignment) * alignment;
1712 throw std::bad_alloc();
1714 std::unique_ptr<void,
decltype(argDeleter)> argBuffer(argRaw, argDeleter);
1717 arg->xTranslation = xTrans;
1718 arg->yTranslation = yTrans;
1719 for (uint32_t i = 0; i < numCoords; ++i)
1720 arg->coords()[i] = inputCoords[i];
1724 "Sending coord translate argument: " + std::to_string(argSize) +
1725 " bytes, coords_length=" + std::to_string(arg->coordsLength) +
1726 ", x_trans=" + std::to_string(arg->xTranslation) +
1727 ", y_trans=" + std::to_string(arg->yTranslation));
1732 ->call(
MessageData(
reinterpret_cast<const uint8_t *
>(arg), argSize))
1736 logger.
debug(
"esitester",
"Received coord translate result: " +
1737 std::to_string(resMsg.
getSize()) +
" bytes");
1740 throw std::runtime_error(
"Coord translate test: result too small");
1742 const auto *result =
1746 throw std::runtime_error(
"Coord translate test: result data truncated");
1749 if (result->coordsLength != inputCoords.size())
1750 throw std::runtime_error(
1751 "Coord translate test: result size mismatch. Expected " +
1752 std::to_string(inputCoords.size()) +
", got " +
1753 std::to_string(result->coordsLength));
1756 std::cout <<
"Coord translate test results:" << std::endl;
1757 for (
size_t i = 0; i < inputCoords.size(); ++i) {
1758 uint32_t expectedX = inputCoords[i].x + xTrans;
1759 uint32_t expectedY = inputCoords[i].y + yTrans;
1760 std::cout <<
" coord[" << i <<
"]=(" << inputCoords[i].x <<
","
1761 << inputCoords[i].y <<
") + (" << xTrans <<
"," << yTrans
1762 <<
") = (" << result->
coords()[i].
x <<
","
1763 << result->coords()[i].y <<
")";
1764 if (result->coords()[i].x != expectedX ||
1765 result->coords()[i].y != expectedY) {
1766 std::cout <<
" MISMATCH! (expected (" << expectedX <<
"," << expectedY
1770 std::cout << std::endl;
1774 throw std::runtime_error(
"Coord translate test failed: result mismatch");
1776 logger.
info(
"esitester",
"Coord translate test passed");
1777 std::cout <<
"Coord translate test passed" << std::endl;
1784#pragma pack(push, 1)
1802#pragma pack(push, 1)
1820 uint32_t yTrans, uint32_t numCoords,
1821 size_t batchSizeLimit) {
1823 logger.
info(
"esitester",
"Starting serial coord translate test");
1826 std::mt19937 rng(0xDEADBEEF);
1827 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
1828 std::vector<Coord> inputCoords;
1829 inputCoords.reserve(numCoords);
1830 for (uint32_t i = 0; i < numCoords; ++i) {
1831 inputCoords.push_back({dist(rng), dist(rng)});
1836 throw std::runtime_error(
"Serial coord translate test: no "
1837 "'coord_translator_serial' child found");
1839 auto &ports = child->second->getPorts();
1840 auto portIter = ports.find(
AppID(
"translate_coords_serial"));
1841 if (portIter == ports.end())
1842 throw std::runtime_error(
1843 "Serial coord translate test: no 'translate_coords_serial' port found");
1852 while (sent < numCoords) {
1853 size_t batchSize = std::min(batchSizeLimit, numCoords - sent);
1863 sizeof(headerFrame)));
1866 for (
size_t i = 0; i < batchSize; ++i) {
1869 dataFrame.
data.
x = inputCoords[sent + i].x;
1870 dataFrame.
data.
y = inputCoords[sent + i].y;
1872 sizeof(dataFrame)));
1879 argPort.
write(footer);
1884 std::vector<Coord> results;
1888 resultPort.
read(msg);
1890 throw std::runtime_error(
"Unexpected result message size");
1895 if (batchCount == 0)
1899 for (uint16_t i = 0; i < batchCount; ++i) {
1900 resultPort.
read(msg);
1902 throw std::runtime_error(
"Unexpected result message size");
1903 const auto *dFrame =
1905 results.push_back({dFrame->data.y, dFrame->data.x});
1911 std::cout <<
"Serial coord translate test results:" << std::endl;
1912 if (results.size() != inputCoords.size()) {
1913 std::cout <<
"Result size mismatch. Expected " << inputCoords.size()
1914 <<
", got " << results.size() << std::endl;
1917 for (
size_t i = 0; i < std::min(inputCoords.size(), results.size()); ++i) {
1918 uint32_t expX = inputCoords[i].x + xTrans;
1919 uint32_t expY = inputCoords[i].y + yTrans;
1920 std::cout <<
" coord[" << i <<
"]=(" << inputCoords[i].x <<
","
1921 << inputCoords[i].y <<
") + (" << xTrans <<
"," << yTrans
1922 <<
") = (" << results[i].x <<
"," << results[i].y
1923 <<
") (expected (" << expX <<
"," << expY <<
"))";
1924 if (results[i].x != expX || results[i].y != expY) {
1925 std::cout <<
" MISMATCH!";
1928 std::cout << std::endl;
1935 throw std::runtime_error(
"Serial coord translate test failed");
1937 logger.
info(
"esitester",
"Serial coord translate test passed");
1938 std::cout <<
"Serial coord translate 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.
ServiceClass * getService(AppIDPath id={}, std::string implName={}, ServiceImplDetails details={}, HWClientDetails clients={})
Get a typed reference to a particular service type.
virtual void disconnect()
Disconnect from the accelerator cleanly.
Logger & getLogger() const
AcceleratorServiceThread * getServiceThread()
Return a pointer to the accelerator 'service' thread (or threads).
void addPoll(HWModule &module)
Poll this module.
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.
BundlePort * resolvePort(const AppIDPath &path, AppIDPath &lastLookup) const
Attempt to resolve a path to a port.
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 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 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