okami.mom/strata

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

Niko1221Merge f-amd-vision (d5fda4d2f) into f-split-int: GPU picture reader for AMD (strata-vision-hip) with automatic CPU fallback; pictures on by default on AMD; packaging for Linux and Windowsd6aa6504e

main
1.6 KiB33 linesraw
1// tools/vision/gpu_arch.h - which GPU the HIP picture reader (strata-vision-hip) was compiled for, and whether the GPU it
2// found is one of them.  ggml-hip prints "  Device 0: AMD Radeon RX 9070 XT, gfx1201:sramecc-:xnack- (0x1201), ..." when it
3// starts; a card whose architecture is not in the build would fail at its first kernel ("no kernel image", an abort), so
4// the reader reads that line and refuses before any kernel runs.  The server then starts the CPU reader (see
5// serve/server.py, Vision._start).  Header only, so gpu_arch_test.cpp can check it without a GPU.
6#pragma once
7
8#include <cctype>
9#include <string>
10#include <vector>
11
12// "gfx1201" out of ggml's device line (or a gcnArchName: "gfx1201:sramecc-:xnack-"); "" when there is none
13inline std::string strata_gfx_in(const std::string& text) {
14    for (size_t at = text.find("gfx"); at != std::string::npos; at = text.find("gfx", at + 1)) {
15        size_t end = at + 3;
16        while (end < text.size() && std::isxdigit((unsigned char) text[end])) ++end;
17        if (end > at + 3) return text.substr(at, end - at);
18    }
19    return "";
20}
21
22// "gfx1200,gfx1201" (the build's list; ',' or ';' between) holds `arch`
23inline bool strata_arch_listed(const std::string& list, const std::string& arch) {
24    if (arch.empty()) return false;
25    size_t start = 0;
26    while (start <= list.size()) {
27        size_t end = list.find_first_of(",; ", start);
28        if (end == std::string::npos) end = list.size();
29        if (list.compare(start, end - start, arch) == 0 && end - start == arch.size()) return true;
30        start = end + 1;
31    }
32    return false;
33}