okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-141-intel' into f-14028f70a52cf

main
1.8 KiB38 linesraw
1// alias_scan: allocate device buffers of assorted sizes, keep them, and run strata::arena_alias_check on each: where does
2// the xe page table alias pages (a write to one 2 MiB page showing at another)?  Prints each buffer's address mod 1 GiB.
3//   alias_scan [n=40] [seed=1] [max_mib=6000]
4#include <sycl/sycl.hpp>
5#include <cstdio>
6#include <cstdlib>
7#include <random>
8#include <vector>
9#include "strata/sycl_queue.hpp"
10
11int main(int argc, char** argv) {
12    const int n = argc > 1 ? std::atoi(argv[1]) : 40;
13    const unsigned seed = argc > 2 ? (unsigned) std::atoi(argv[2]) : 1;
14    const size_t max_mib = argc > 3 ? (size_t) std::atoll(argv[3]) : 6000;
15    sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};
16    std::mt19937_64 rng(seed);
17    std::vector<void*> keep;
18    size_t total = 0;
19    int bad_bufs = 0;
20    for (int i = 0; i < n; ++i) {
21        size_t mib = (rng() % 4 == 0) ? 1 + rng() % 8 : 1 + rng() % max_mib;
22        if (total + mib > 24000) break;
23        const size_t bytes = mib << 20;
24        void* p = sycl::malloc_device(bytes, q);
25        if (!p) { std::printf("alloc %zu MiB failed\n", mib); break; }
26        keep.push_back(p);
27        total += mib;
28        size_t first = 0;
29        const uint64_t bad = strata::arena_alias_check(q, p, bytes, &first);
30        std::printf("#%02d %6zu MiB at %p (mod 1GiB %5zu MiB, mod 2MiB %zu): %s", i, mib, p, (size_t) (((uintptr_t) p & ((1u << 30) - 1)) >> 20),
31                    (size_t) ((uintptr_t) p & ((2u << 20) - 1)), bad ? "ALIAS" : "ok");
32        if (bad) { ++bad_bufs; std::printf(" %llu blocks, first at +%zu MiB", (unsigned long long) bad, first >> 20); }
33        std::printf("\n");
34    }
35    std::printf("%d of %zu buffers aliased\n", bad_bufs, keep.size());
36    for (void* p : keep) sycl::free(p, q);
37    return bad_bufs ? 3 : 0;
38}