okami.mom/strata

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

Niko1221Merge f-142b-amd into f-142bb930bc8b

main
3.3 KiB78 linesraw
1// The batch window's row layout (include/strata/core/batch_rows.hpp): plain one-row slots, a slot's contiguous group of
2// proposed rows (--batch-mtp), and the hand-off capacity of a layer split's stages.  Header-only, CPU.
3#include "strata/core/batch_rows.hpp"
4
5#include <cstdio>
6#include <cstdlib>
7#include <cstring>
8
9namespace {
10int failures = 0;
11void check(bool ok, const char* what) {
12    if (!ok) {
13        std::fprintf(stderr, "FAIL: %s\n", what);
14        ++failures;
15    }
16}
17const char* run(const int* rows, const long long* p, int S, int n_slots, int max_t, int hbase, bool handoff) {
18    int64_t pos[8];
19    for (int t = 0; t < S; ++t) pos[t] = p[t];
20    return strata::core::batch_rows_error(rows, S, pos, n_slots, max_t, hbase, handoff, 8);
21}
22}  // namespace
23
24int main() {
25    using strata::core::batch_rows_error;
26    // plain batch: one row per slot, any positions
27    {
28        const int rows[] = {0, 1, 2};
29        const long long pos[] = {10, 500, 3};
30        check(run(rows, pos, 3, 3, 8, 0, false) == nullptr, "one row per slot");
31        check(run(rows, pos, 3, 3, 8, 0, true) == nullptr, "one row per slot through the hand-off");
32    }
33    // --batch-mtp: a slot's two rows at consecutive positions; also on a layer split (S > slots)
34    {
35        const int rows[] = {1, 1, 0, 0};
36        const long long pos[] = {40, 41, 7, 8};
37        check(run(rows, pos, 4, 2, 8, 0, false) == nullptr, "two rows per slot, one stage");
38        check(run(rows, pos, 4, 2, 8, 0, true) == nullptr, "two rows per slot across a layer split (S > slots)");
39    }
40    // eight rows = four slots of two: the whole hand-off
41    {
42        const int rows[] = {0, 0, 1, 1, 2, 2, 3, 3};
43        const long long pos[] = {1, 2, 5, 6, 9, 10, 20, 21};
44        check(run(rows, pos, 8, 4, 8, 0, true) == nullptr, "eight rows fill the hand-off");
45        check(run(rows, pos, 8, 4, 8, 1, true) != nullptr, "a group past the hand-off's end");
46        check(run(rows, pos, 8, 4, 8, 1, false) == nullptr, "no hand-off: the base does not bound the rows");
47    }
48    // refused layouts
49    {
50        const int rows[] = {0, 1, 0};
51        const long long pos[] = {5, 9, 6};
52        check(run(rows, pos, 3, 2, 8, 0, false) != nullptr, "a slot's rows must be contiguous");
53    }
54    {
55        const int rows[] = {0, 0};
56        const long long pos[] = {5, 7};
57        check(run(rows, pos, 2, 1, 8, 0, false) != nullptr, "a slot's rows need consecutive positions");
58    }
59    {
60        const int rows[] = {0, 2};
61        const long long pos[] = {5, 7};
62        check(run(rows, pos, 2, 2, 8, 0, false) != nullptr, "a slot past the slots held");
63        const int neg[] = {-1};
64        const long long p1[] = {1};
65        check(run(neg, p1, 1, 2, 8, 0, false) != nullptr, "a negative slot");
66    }
67    {
68        const int rows[] = {0, 0, 0};
69        const long long pos[] = {1, 2, 3};
70        check(run(rows, pos, 3, 1, 2, 0, false) != nullptr, "more rows than the window holds");
71        check(run(rows, pos, 0, 1, 8, 0, false) != nullptr, "an empty window");
72        check(run(rows, pos, 3, 1, 8, -1, false) != nullptr, "a negative hand-off base");
73        check(run(rows, pos, 3, 1, 8, 0, false) == nullptr, "three rows of one slot are a group");
74    }
75    if (failures != 0) return EXIT_FAILURE;
76    std::printf("batch_rows_test: ok\n");
77    return EXIT_SUCCESS;
78}