okami.mom/strata

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

Niko1221Merge f-gfx11-tq (64e95049a): the fused trellis prompt kernels on Windows gfx1151, default onb1abdcf9b

main
4.5 KiB70 linesraw
1// the HIP rule of the fused trellis (Gyro) prompt kernels (include/strata/prefill/fused_tq_hip.hpp): gfx12 with STRATA_PF_FUSED_TQ=1 as before; gfx1151 by STRATA_PF_TQ_G1151
2// (1 on, other values off, unset = the Windows default unless STRATA_GFX1151_DEFAULTS=0); every other device off.  Every input combination is checked.  No GPU, no model.
3#include <cstdio>
4
5#include "strata/prefill/fused_tq_hip.hpp"
6
7using strata::prefill::fused_tq_hip::device_on;
8using strata::prefill::fused_tq_hip::kG1151DefaultOn;
9using strata::prefill::fused_tq_hip::pair_on;
10using strata::prefill::fused_tq_hip::parse_switch;
11
12static int failed = 0;
13#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
14
15// the expected answer, written out apart from the header's form
16static bool want_device(bool w12, bool g1151, bool win, bool tq, int sw, bool doff, bool def) {
17    if (!tq) return false;                          // no STRATA_PF_FUSED_TQ=1 (a build with MMQ, nothing set): never
18    if (w12) return true;                           // gfx12: unchanged, the switch and the gfx1151 rules do not apply
19    if (!g1151) return false;                       // gfx1100-1103, gfx1150, gfx9: never
20    if (sw == 1) return true;                       // gfx1151, the switch at 1: on (Linux too)
21    if (sw == 0) return false;                      // gfx1151, the switch at another value: off
22    return def && win && !doff;                     // unset: the Windows default
23}
24
25int main() {
26    // the variable's three readings
27    CHECK(parse_switch(nullptr) == -1 && parse_switch("") == -1);
28    CHECK(parse_switch("1") == 1 && parse_switch("1x") == 1);
29    CHECK(parse_switch("0") == 0 && parse_switch("2") == 0 && parse_switch("off") == 0);
30
31    // the shipped default for Windows gfx1151
32    CHECK(kG1151DefaultOn == true);
33    // with the shipped default: Windows gfx1151 on when unset; Linux, STRATA_GFX1151_DEFAULTS=0, the switch at 0 and a build without STRATA_PF_FUSED_TQ off
34    CHECK(strata::prefill::fused_tq_hip::device_on(false, true, true, true, -1, false, kG1151DefaultOn));
35    CHECK(!strata::prefill::fused_tq_hip::device_on(false, true, false, true, -1, false, kG1151DefaultOn));
36    CHECK(!strata::prefill::fused_tq_hip::device_on(false, true, true, true, -1, true, kG1151DefaultOn));
37    CHECK(!strata::prefill::fused_tq_hip::device_on(false, true, true, true, 0, false, kG1151DefaultOn));
38    CHECK(!strata::prefill::fused_tq_hip::device_on(false, true, true, false, -1, false, kG1151DefaultOn));
39
40    const int sws[] = {-1, 0, 1};
41    for (int m = 0; m < 64; ++m) {
42        const bool w12 = m & 1, g1151 = m & 2, win = m & 4, tq = m & 8, doff = m & 16, def = m & 32;
43        if (w12 && g1151) continue;   // (one device is never both)
44        for (int sw : sws) {
45            const bool dv = device_on(w12, g1151, win, tq, sw, doff, def);
46            CHECK(dv == want_device(w12, g1151, win, tq, sw, doff, def));
47            // Gyro-S's pair follows the device rule
48            CHECK(pair_on(w12, g1151, win, tq, sw, doff, def, true, false) == dv);
49            // Gyro-M's pair: gfx12 as before; gfx1151 only with the switch at 1
50            CHECK(pair_on(w12, g1151, win, tq, sw, doff, def, false, true) == (dv && (w12 || sw == 1)));
51            // anything that is neither pair: never
52            CHECK(!pair_on(w12, g1151, win, tq, sw, doff, def, false, false));
53        }
54    }
55
56    // spelled out: gfx12 under a build without MMQ keeps both pairs whatever the gfx1151 switch says
57    CHECK(device_on(true, false, true, true, 0, true, false) && pair_on(true, false, false, true, -1, false, false, false, true));
58    // a build with MMQ (STRATA_PF_FUSED_TQ unset): gfx1151 stays off even with the switch at 1
59    CHECK(!device_on(false, true, true, false, 1, false, true));
60    // gfx1100 (a 7900 XTX) and gfx1150: off with every switch
61    CHECK(!device_on(false, false, true, true, 1, false, true) && !device_on(false, false, false, true, -1, false, true));
62    // Linux gfx1151 with the default on: off unless the switch is 1
63    CHECK(!device_on(false, true, false, true, -1, false, true) && device_on(false, true, false, true, 1, false, true));
64    // Windows gfx1151 with the default on: STRATA_GFX1151_DEFAULTS=0 or the switch at 0 turns it off
65    CHECK(device_on(false, true, true, true, -1, false, true) && !device_on(false, true, true, true, -1, true, true) && !device_on(false, true, true, true, 0, false, true));
66
67    if (failed) { std::fprintf(stderr, "fused_tq_hip_test: %d failed\n", failed); return 1; }
68    std::printf("fused_tq_hip_test: ok\n");
69    return 0;
70}