okami.mom/strata

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

Niko1221Trial2 merge f-0291-pr-amd (82eaeb422): verify.cpp head keeps both: pr-nv2's chunked head (h0/HT, up to 8 columns a launch) and pr-amd's fused q8_1 image (q8_head, image at the chunk's own xq_ offset)62db0bf10

main
5.3 KiB113 linesraw
1// src/core/amd_community_test.cpp - STRATA_AMD_COMMUNITY_TUNING turns each community-made AMD change off (no GPU needed).
2//
3// Built twice by CMake: once as the default build (EXPECT_DOT_BUILT=1) and once with STRATA_AMD_COMMUNITY_DOT_OFF defined
4// (EXPECT_DOT_BUILT=0), which is what cmake -DSTRATA_AMD_COMMUNITY_TUNING=OFF does.  Run from the source directory.
5#include "strata/core/amd_community.hpp"
6#include "../prefill/rocblas_tuning.hpp"
7
8#include <cstdio>
9#include <cstdlib>
10#include <fstream>
11#include <sstream>
12#include <string>
13
14static int fails = 0;
15#define CHECK(c) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0)
16
17static void unset(const char* k) {
18#if defined(_WIN32)
19    _putenv_s(k, "");
20#else
21    unsetenv(k);
22#endif
23}
24static void put(const char* k, const char* v) {
25#if defined(_WIN32)
26    _putenv_s(k, v);
27#else
28    setenv(k, v, 1);
29#endif
30}
31
32int main() {
33    namespace ac = strata::amd_community;
34    const char* kSwitch = "STRATA_AMD_COMMUNITY_TUNING";
35
36    // the switch: on by default, off for 0 / off / false / no, on for anything else
37    unset(kSwitch);
38    CHECK(ac::tuning_on());
39    put(kSwitch, "1");
40    CHECK(ac::tuning_on());
41    for (const char* off : {"0", "off", "false", "no"}) {
42        put(kSwitch, off);
43        CHECK(!ac::tuning_on());
44    }
45
46    // which tables are the community's: exactly the two named, only for gfx1030 (feature suffix allowed)
47    CHECK(ac::is_community_rocblas_table("gfx1030", "5.4.0.ad84daa81c"));
48    CHECK(ac::is_community_rocblas_table("gfx1030:xnack-", "5.2.0.dabb6df2b98-dirty"));
49    CHECK(!ac::is_community_rocblas_table("gfx1030", "5.6.0.8d1ae90e"));      // shipped before, not under the switch
50    CHECK(!ac::is_community_rocblas_table("gfx1031", "5.4.0.ad84daa81c"));    // another card
51    CHECK(!ac::is_community_rocblas_table("gfx1030", "5.2.0.dabb6df2b9"));    // AMD's Ubuntu build: not this table
52    CHECK(!ac::is_community_rocblas_table("gfx1201", "5.4.0.ad84daa81c"));
53
54    // rocBLAS tables: the switch off refuses every community table and nothing else
55    unset(kSwitch);
56    for (const auto& t : ac::kRocblasTables) CHECK(ac::rocblas_table_allowed(t.arch, t.version));
57    put(kSwitch, "0");
58    for (const auto& t : ac::kRocblasTables) CHECK(!ac::rocblas_table_allowed(t.arch, t.version));
59    CHECK(ac::rocblas_table_allowed("gfx1030", "5.6.0.8d1ae90e"));
60    CHECK(ac::rocblas_table_allowed("gfx1201", "anything"));
61
62    // the shipped files are well-formed, name the arch and version of the list, and the loader takes each only for that pair
63    for (const auto& t : ac::kRocblasTables) {
64        std::string tag(t.version);
65        while (!tag.empty() && tag.back() == '.') tag.pop_back();
66        const std::string path = std::string("tools/hip/") + t.arch + "-rocblas-" + tag + ".txt";
67        std::string err;
68        strata::prefill::rocblas_tuning::Table ok;
69        CHECK(ok.load(path, t.arch, t.version, err));
70        CHECK(ok.rows().size() == 112);
71        strata::prefill::rocblas_tuning::Table other_version, other_arch;
72        CHECK(!other_version.load(path, t.arch, "5.6.0.8d1ae90e", err));   // a non-matching rocBLAS build just does not load
73        CHECK(!other_arch.load(path, "gfx1031", t.version, err));
74    }
75
76    // the dot product (device code): the build option decides; the intrinsics header carries the guard
77    CHECK(ac::dot4_gfx1010_built() == (EXPECT_DOT_BUILT != 0));
78    {
79        std::ifstream in("include/strata/hip_compat/intrinsics.hpp");
80        std::stringstream ss;
81        ss << in.rdbuf();
82        const std::string text = ss.str();
83        CHECK(text.find("defined(__gfx1010__) && !defined(STRATA_AMD_COMMUNITY_DOT_OFF)") != std::string::npos);
84        CHECK(text.find("!defined(STRATA_GFX1012_PORTABLE_DOT)") != std::string::npos);
85    }
86
87    // #3073: the simt2 selector is the default of gfx103x only, and only with the switch on
88    unset(kSwitch);
89    CHECK(ac::select_simt2_default("gfx1030") && ac::select_simt2_default("gfx1031:xnack-") && ac::select_simt2_default("gfx1032"));
90    CHECK(!ac::select_simt2_default("gfx1201") && !ac::select_simt2_default("gfx1100") && !ac::select_simt2_default("gfx906") &&
91          !ac::select_simt2_default("gfx1010") && !ac::select_simt2_default("") && !ac::select_simt2_default(nullptr));
92    put(kSwitch, "0");
93    CHECK(!ac::select_simt2_default("gfx1030"));
94    unset(kSwitch);
95
96    // the log line: only gfx1010 / gfx103x, and it says what the switch does
97    unset(kSwitch);
98    CHECK(ac::startup_line("gfx1201").empty());
99    CHECK(ac::startup_line("gfx1100").empty());
100    CHECK(ac::startup_line("gfx1012").empty());
101    CHECK(ac::startup_line("gfx1031").find("simt2") != std::string::npos);   // gfx1031: the selector default only
102    CHECK(ac::startup_line("gfx1030").find("simt2") != std::string::npos);
103    CHECK(ac::startup_line("").empty());
104    CHECK(ac::startup_line(nullptr).empty());
105    CHECK(ac::startup_line("gfx1030:xnack-").find("on:") != std::string::npos);
106    CHECK(ac::startup_line("gfx1010").find("STRATA_AMD_COMMUNITY_TUNING=0") != std::string::npos);
107    put(kSwitch, "0");
108    CHECK(ac::startup_line("gfx1030").find("off:") != std::string::npos);
109    CHECK(ac::startup_line("gfx1010").find("rebuild") != std::string::npos || !ac::dot4_gfx1010_built());
110
111    if (fails == 0) std::printf("amd_community_test: OK\n");
112    return fails == 0 ? 0 : 1;
113}