okami.mom/strata

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

Niko1221Merge f-0211-hybrid into f-0211-int07e150889

main
3.8 KiB63 linesraw
1// src/core/pcie_share_rule_test.cpp - the decode miss share's rule, its ceiling and the 0.2.10.1 defaults (no GPU needed).
2#include "strata/core/pcie_share_rule.hpp"
3
4#include <cmath>
5#include <cstdio>
6
7static int fails = 0;
8#define CHECK(c) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0)
9static bool near(double a, double b) { return std::fabs(a - b) < 1e-9; }
10
11int main() {
12    using namespace strata;
13    // k: the shipped 1.85 from 30 GB/s up and whenever the rule is off; 0.8 at 12 and below; linear between
14    CHECK(near(pcie_pool_k(30.0, true), 1.85));
15    CHECK(near(pcie_pool_k(65.0, true), 1.85));
16    CHECK(near(pcie_pool_k(10.3, true), 0.8));
17    CHECK(near(pcie_pool_k(12.0, true), 0.8));
18    CHECK(near(pcie_pool_k(21.0, true), 0.8 + 9.0 / 18.0 * 1.05));
19    CHECK(near(pcie_pool_k(5.0, false), 1.85));
20    // measured on the RTX PRO 6000 box (link 56 GB/s): a strong pool settles at 0.35 with either rule
21    CHECK(near(pcie_share_for(56.1, 61.2, kPcieCeilingShipped, false), 0.35));
22    CHECK(near(pcie_share_for(56.1, 61.2, kPcieCeilingFollow, true), 0.35));
23    // a strong pool is bit-for-bit the old share over every link up to PCIe 5 x16 and every rate from 30 GB/s
24    for (double link = 4.0; link <= 64.0; link += 0.5)
25        for (double r = 30.0; r <= 120.0; r += 0.5)
26            CHECK(near(pcie_share_for(link, r, kPcieCeilingShipped, false), pcie_share_for(link, r, kPcieCeilingFollow, true)));
27    // a weak pool: 4 workers (R about 10.3-13 GB/s) 0.60 -> 0.85, 2 workers (R about 8) -> 0.90 and more
28    CHECK(near(pcie_share_for(56.3, 10.3, kPcieCeilingShipped, false), 0.60));
29    CHECK(near(pcie_share_for(56.3, 10.3, kPcieCeilingFollow, true), 0.85));
30    CHECK(near(pcie_share_for(56.2, 8.0, kPcieCeilingFollow, true), 0.90));
31    CHECK(near(pcie_share_for(56.0, 22.3, kPcieCeilingFollow, true), 0.65));   // 8 workers: 0.60 -> 0.65
32    // the ceiling holds and the floor holds
33    CHECK(near(pcie_share_for(56.0, 0.5, kPcieCeilingFollow, true), 0.95));
34    CHECK(near(pcie_share_for(1.0, 200.0, kPcieCeilingFollow, true), 0.10));
35    // never above the ceiling, never below 0.10, steps of 0.05
36    for (double r = 1.0; r <= 100.0; r += 1.0) {
37        const double s = pcie_share_for(50.0, r, kPcieCeilingFollow, true);
38        CHECK(s >= 0.10 - 1e-9 && s <= 0.95 + 1e-9 && near(std::round(s * 20.0) / 20.0, s));
39    }
40    // defaults: a discrete card follows the pool, an integrated GPU and the master switch keep the shipped rule, an explicit value wins
41    CHECK(near(pcie_share_ceiling(true, false, nullptr), 0.95));
42    CHECK(near(pcie_share_ceiling(false, false, nullptr), 0.60));
43    CHECK(near(pcie_share_ceiling(true, true, nullptr), 0.60));
44    CHECK(near(pcie_share_ceiling(false, false, "0.8"), 0.8));
45    CHECK(near(pcie_share_ceiling(true, false, "2"), 1.0));
46    CHECK(near(pcie_share_ceiling(true, false, "0.6"), 0.6));
47    CHECK(pcie_k_rule_default(true, false, nullptr));
48    CHECK(!pcie_k_rule_default(false, false, nullptr));
49    CHECK(!pcie_k_rule_default(true, true, nullptr));
50    CHECK(!pcie_k_rule_default(true, false, "0"));
51    CHECK(pcie_k_rule_default(false, false, "1"));
52    // the layer split: on for a discrete CUDA card, off for HIP (opt-in), for an integrated GPU and under 026; =0 / =1 win
53    CHECK(pcie_auto_split_default(false, true, false, nullptr));
54    CHECK(!pcie_auto_split_default(true, true, false, nullptr));
55    CHECK(!pcie_auto_split_default(false, false, false, nullptr));
56    CHECK(!pcie_auto_split_default(false, true, true, nullptr));
57    CHECK(!pcie_auto_split_default(false, true, false, "0"));
58    CHECK(pcie_auto_split_default(true, true, false, "1"));
59    CHECK(pcie_auto_split_default(false, false, false, "1"));
60    CHECK(pcie_auto_split_default(false, true, false, ""));   // empty = unset
61    if (fails == 0) std::printf("pcie_share_rule_test: ok\n");
62    return fails == 0 ? 0 : 1;
63}