Files

45 lines
2.3 KiB
C++

// Host DRAM read bandwidth by thread count and placement (AVX-512 streaming reads, like the CPU expert kernels).
// mb_dram [--gib 4] [--secs 0.6]
// RESULT dram mode=stream|blob2MB place=spread|ccd0|ccd1 threads=N gbps=...
#include "mb_common.h"
#include "mb_dram_kernels.h"
#include <sys/mman.h>
int main(int argc, char** argv) {
double gib = 4, secs = 0.6;
for (int i = 1; i < argc; ++i) {
if (!std::strcmp(argv[i], "--gib") && i + 1 < argc) gib = std::atof(argv[++i]);
else if (!std::strcmp(argv[i], "--secs") && i + 1 < argc) secs = std::atof(argv[++i]);
}
const size_t bytes = (size_t)(gib * (1ull << 30));
if (!host_alloc_allowed(bytes)) return 3;
uint8_t* buf = (uint8_t*)mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf == MAP_FAILED) { std::perror("mmap"); return 2; }
madvise(buf, bytes, MADV_HUGEPAGE);
for (size_t i = 0; i < bytes; i += 4096) buf[i] = (uint8_t)(i >> 12);
Topo topo = read_topo();
std::printf("# cpus=%d l3_groups=%d avx512=%d buffer=%.1f GiB\n", (int)std::thread::hardware_concurrency(), topo.groups(),
(int)(__builtin_cpu_supports("avx512f") != 0), gib);
const int counts[] = {1, 2, 3, 4, 6, 8, 10, 12, 14, 16, 20, 24, 32};
for (int mode = 0; mode < 2; ++mode)
for (const char* place : {"spread", "ccd0", "ccd1"}) {
if (!std::strcmp(place, "ccd1") && topo.groups() < 2) continue;
for (int n : counts) {
std::vector<int> cpus = placement(topo, place, n);
if ((int)cpus.size() != n) continue;
std::vector<double> r;
for (int rep = 0; rep < 3; ++rep) {
ReaderPool pool;
pool.start(buf, bytes, cpus, mode, 2046400);
std::this_thread::sleep_for(std::chrono::duration<double>(secs));
r.push_back(pool.finish());
}
std::printf("RESULT dram mode=%s place=%s threads=%d gbps=%.1f min=%.1f max=%.1f\n", mode ? "blob2MB" : "stream", place, n,
median(r), *std::min_element(r.begin(), r.end()), *std::max_element(r.begin(), r.end()));
std::fflush(stdout);
}
}
munmap(buf, bytes);
return 0;
}