okami.mom/strata

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

Niko1221Merge the expert cache fix for a part-way shrink: with --vram-elastic, a refused shrink no longer leaves experts listed in unmapped slots28e8d0e05

main
1.9 KiB39 linesraw
1// The residency entries past what the segmented expert cache still maps (strata/core/residency_trim.hpp): after a shrink, also one
2// the driver refused part way, every entry at or past the live slots becomes not resident and is listed for the next grow.  No GPU.
3#include "strata/core/residency_trim.hpp"
4
5#include <cstdio>
6#include <utility>
7#include <vector>
8
9using namespace strata::core;
10
11namespace {
12int failed = 0;
13#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
14}  // namespace
15
16int main() {
17    // 8 entries: slots 0..5, two not resident; 4 slots stay mapped
18    std::vector<int32_t> res = {0, 5, kNotResident, 3, 4, kNotResident, 1, 2};
19    std::vector<std::pair<int32_t, int32_t>> ev;
20    CHECK(evict_slots_past(res, 4, ev) == 2);
21    CHECK((res == std::vector<int32_t>{0, kNotResident, kNotResident, 3, kNotResident, kNotResident, 1, 2}));
22    CHECK(ev.size() == 2 && ev[0] == std::make_pair(1, 5) && ev[1] == std::make_pair(4, 4));
23    // a second shrink appends after what an earlier one listed, in table order
24    CHECK(evict_slots_past(res, 2, ev) == 2);
25    CHECK(ev.size() == 4 && ev[2] == std::make_pair(3, 3) && ev[3] == std::make_pair(7, 2));
26    CHECK(res[0] == 0 && res[6] == 1 && res[3] == kNotResident && res[7] == kNotResident);
27    // nothing past the live slots (a refusal before anything was given back): nothing changes
28    const std::vector<int32_t> before = res;
29    CHECK(evict_slots_past(res, 2, ev) == 0 && res == before && ev.size() == 4);
30    // no slot left: every resident entry goes
31    CHECK(evict_slots_past(res, 0, ev) == 2 && ev.size() == 6);
32    for (const int32_t s : res) CHECK(s == kNotResident);
33    if (failed) {
34        std::fprintf(stderr, "residency_trim_test: %d failed\n", failed);
35        return 1;
36    }
37    std::puts("residency_trim_test: the entries past the mapped slots are taken, in table order");
38    return 0;
39}