Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

strata-device --list-devices, and HIP's numbering for AMD cards on Windows (#325)

Niko122151fdc43c80b2
diff --git a/include/strata/core/device.hpp b/include/strata/core/device.hpp
index 2c180263d..091dff1c3 100644
--- a/include/strata/core/device.hpp
+++ b/include/strata/core/device.hpp
@@ -38,6 +38,16 @@ std::string gpu_arch_problem(int ordinal);
// The GPU architectures this binary was compiled for ("gfx1100,gfx1201"); "" on CUDA builds.
const char* compiled_gpu_archs();
+// How many devices the runtime enumerates, numbered as HIP_VISIBLE_DEVICES / CUDA_VISIBLE_DEVICES number them; 0 when
+// there is none (or no usable runtime). `device_info` throws on a card this binary cannot run, so a caller that LISTS
+// every card - the ones it has no code for included (`strata-device --list-devices`) - counts them with this first.
+int device_count();
+
+// One line per device for `strata-device --list-devices`, without the arch check that `device_info` applies:
+// "arch gfx1201, 15.9 GiB" (HIP) or "compute capability 12.0, 11.9 GiB" (CUDA), plus the device's name. false when
+// the runtime cannot describe it.
+bool device_summary(int ordinal, std::string& name, std::string& detail);
+
// Throws when there is no CUDA device. The engine targets sm_120 specifically and must say so rather than
// run slowly on something else: `CMakeLists.txt` already refuses to COMPILE for another architecture, and
// this is the matching check at run time (a binary can be carried to a different machine).
diff --git a/serve/server.py b/serve/server.py
index f13cf0399..d87ba8f1b 100644
--- a/serve/server.py
+++ b/serve/server.py
@@ -629,12 +629,28 @@ def engine_args(cfg: dict) -> list[str]:
return args
+def hip_visible(cfg: dict) -> list[int]:
+ """AMD: the devices the engine should see, as the HIP runtime numbers them (HIP_VISIBLE_DEVICES).
+
+ On Linux setup's KFD order is HIP's order, so the config's "gpu" is it. On Windows setup finds the cards in the
+ display-adapter order, and an integrated Radeon that HIP also enumerates takes ordinal 0 and pushes the discrete
+ card to 1 (#325): setup records the ordinal `strata-device --list-devices` gave the card as "hip_ordinal", which
+ wins for a one-card config. Without it (a config from before), the config's "gpu"."""
+ ordinal = cfg.get("hip_ordinal")
+ if ordinal is not None and str(ordinal).strip() != "" and len(gpu_list(cfg)) <= 1:
+ try:
+ return [int(str(ordinal).strip())]
+ except ValueError:
+ pass
+ return gpu_list(cfg)
+
+
def child_env(cfg: dict) -> dict:
"""The engine's environment: the CUDA libraries setup installed (pip's nvidia packages, or the toolkit that
compiled it) first on the library search path."""
env = dict(os.environ)
- if gpu_list(cfg) and cfg.get("backend") == "hip": # AMD: numbered as HIP numbers them (setup's KFD order)
- env["HIP_VISIBLE_DEVICES"] = ",".join(str(i) for i in gpu_list(cfg))
+ if hip_visible(cfg) and cfg.get("backend") == "hip": # AMD: numbered as HIP numbers them (hip_visible)
+ env["HIP_VISIBLE_DEVICES"] = ",".join(str(i) for i in hip_visible(cfg))
elif gpu_list(cfg): # issue #51: the GPU(s) to run on, numbered as nvidia-smi does; CUDA's
env["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" # own default order (fastest first) can number the cards otherwise
env["CUDA_VISIBLE_DEVICES"] = ",".join(str(i) for i in gpu_list(cfg))
diff --git a/serve/test_server.py b/serve/test_server.py
index 90781f7a6..9daf3d31b 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -503,6 +503,18 @@ class GpuChoice(unittest.TestCase):
self.assertEqual(plain.get("CUDA_VISIBLE_DEVICES"), os.environ.get("CUDA_VISIBLE_DEVICES"))
self.assertEqual(plain.get("CUDA_DEVICE_ORDER"), os.environ.get("CUDA_DEVICE_ORDER"))
+ def test_hip_ordinal(self):
+ """#325: on Windows the HIP ordinal setup resolved wins over the config's "gpu" (an iGPU takes HIP's 0)."""
+ from serve.server import child_env
+ self.assertEqual(child_env({"backend": "hip", "gpu": 1})["HIP_VISIBLE_DEVICES"], "1") # Linux: KFD order
+ self.assertEqual(child_env({"backend": "hip", "hip_ordinal": 1})["HIP_VISIBLE_DEVICES"], "1")
+ self.assertEqual(child_env({"backend": "hip", "gpu": 0, "hip_ordinal": 1})["HIP_VISIBLE_DEVICES"], "1")
+ self.assertEqual(child_env({"backend": "hip", "gpu": [1, 0], "hip_ordinal": 2})["HIP_VISIBLE_DEVICES"],
+ "1,0") # a layer split keeps its list
+ self.assertEqual(child_env({"backend": "hip", "gpu": 0, "hip_ordinal": "x"})["HIP_VISIBLE_DEVICES"], "0")
+ plain = child_env({"backend": "hip"})
+ self.assertEqual(plain.get("HIP_VISIBLE_DEVICES"), os.environ.get("HIP_VISIBLE_DEVICES"))
+
class RecordingPrompt(MockEngine):
def generate(self, ids, max_new, sampling, cancel, embeddings=None):
diff --git a/src/core/device.cu b/src/core/device.cu
index 814635a61..721028c9b 100644
--- a/src/core/device.cu
+++ b/src/core/device.cu
@@ -73,6 +73,34 @@ const char* compiled_gpu_archs() {
#endif
}
+int device_count() {
+ int count = 0;
+ if (cudaGetDeviceCount(&count) != cudaSuccess) { // HIP without a usable device reports an error, not 0
+ cudaGetLastError();
+ return 0;
+ }
+ return count < 0 ? 0 : count;
+}
+
+bool device_summary(int ordinal, std::string& name, std::string& detail) {
+ cudaDeviceProp p{};
+ if (ordinal < 0 || ordinal >= device_count() || cudaGetDeviceProperties(&p, ordinal) != cudaSuccess) {
+ cudaGetLastError();
+ return false;
+ }
+ char buf[160];
+#if defined(STRATA_USE_HIP)
+ std::snprintf(buf, sizeof(buf), "arch %s, %.1f GiB, wave%d", base_arch(p.gcnArchName).c_str(),
+ (double) p.totalGlobalMem / (1024.0 * 1024 * 1024), p.warpSize);
+#else
+ std::snprintf(buf, sizeof(buf), "compute capability %d.%d, %.1f GiB", p.major, p.minor,
+ (double) p.totalGlobalMem / (1024.0 * 1024 * 1024));
+#endif
+ name = p.name;
+ detail = buf;
+ return true;
+}
+
std::string gpu_arch_problem(int ordinal) {
#if defined(STRATA_USE_HIP)
int count = 0;
diff --git a/src/core/device_main.cpp b/src/core/device_main.cpp
index 524e7b182..ff5adf519 100644
--- a/src/core/device_main.cpp
+++ b/src/core/device_main.cpp
@@ -19,10 +19,14 @@ static std::string human(uint64_t b) {
int main(int argc, char** argv) {
bool selftest = false;
+ bool list_devices = false;
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "--selftest") == 0) selftest = true;
+ else if (std::strcmp(argv[i], "--list-devices") == 0) list_devices = true;
else if (std::strcmp(argv[i], "--help") == 0 || std::strcmp(argv[i], "-h") == 0) {
- std::printf("usage: strata-device [--selftest]\n");
+ std::printf("usage: strata-device [--selftest] [--list-devices]\n"
+ " --list-devices every GPU the runtime enumerates, numbered as HIP_VISIBLE_DEVICES /\n"
+ " CUDA_VISIBLE_DEVICES number them, and whether this binary can run it\n");
return 0;
} else {
std::fprintf(stderr, "unknown argument: %s\n", argv[i]);
@@ -30,6 +34,28 @@ int main(int argc, char** argv) {
}
}
+ // The runtime's numbering, which setup needs on Windows: there an integrated Radeon is HIP device 0 and pushes the
+ // discrete card to 1, while setup finds the cards in the display-adapter order (#325). No arch check here - the
+ // cards this binary has no code for are part of the answer. Format (setup.py's hip_devices parses it):
+ // device N: <name>
+ // arch gfx1201, 15.9 GiB, wave32 (CUDA: compute capability 12.0, 11.9 GiB)
+ // cannot run: <why> (only for a card this binary cannot run)
+ if (list_devices) {
+ const int count = strata::core::device_count();
+ if (count == 0) std::printf("(no GPU device)\n");
+ for (int ordinal = 0; ordinal < count; ++ordinal) {
+ std::string name, detail;
+ if (!strata::core::device_summary(ordinal, name, detail)) {
+ std::printf("device %d: (the runtime cannot describe it)\n", ordinal);
+ continue;
+ }
+ std::printf("device %d: %s\n %s\n", ordinal, name.c_str(), detail.c_str());
+ if (const std::string why = strata::core::gpu_arch_problem(ordinal); !why.empty())
+ std::printf(" cannot run: %s\n", why.c_str());
+ }
+ return 0;
+ }
+
try {
const strata::core::DeviceInfo d = strata::core::device_info(0);
std::printf("device %d: %s\n", d.ordinal, d.name.c_str());