diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 1e172968..3151df27 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -601,7 +601,8 @@ class Context { probe.runtime_options = o.runtime.c_str(); wgrt::ModelId model = wgrt::ModelId::M; std::string merr; - q.model_k = wgrt::model_from_options(probe, &model, &merr) && model != wgrt::ModelId::M; + // model K only (Model L runs on the D3D12 executor in builds with it: runtime.cpp, native D3D12 backend 3) + q.model_k = wgrt::model_from_options(probe, &model, &merr) && model == wgrt::ModelId::K; q.adapter_known = adapter_info(device_, &q.adapter, &q.vendor_id, &q.software); q.sparkle_guard = o.sparkle_guard > 0.0f; q.capture = !o.capture_dir.empty(); @@ -1377,7 +1378,9 @@ class Context { if (base.empty()) return *err = "LOCALAPPDATA is not set; cannot find the model", false; model_dir_ = base + "\\WrongGPU\\model"; } - // the network model: runtime option model=K (passed on to the runtime) selects model K, else model M + // the network model: runtime option model=K (passed on to the runtime) selects model K, model=L Model L (its + // converted file in \L, model_select.h), else model M + bool model_l = false; { WgRtConfig probe = WgRtConfig(); probe.runtime_options = o.runtime.c_str(); @@ -1387,6 +1390,7 @@ class Context { #ifndef WG_NO_MODEL_K model_k_ = model == wgrt::ModelId::K; #endif + model_l = model == wgrt::ModelId::L; } { // model K's input path: k_input=16 (default: the compact pass where exact) or f32 (the FP32 input pass) const std::string ki = option_value(o.runtime, "k_input"); @@ -1417,7 +1421,7 @@ class Context { return *err = "model K: the network's kernel files are missing in " + kernels_dir_ + " (reinstall WrongGPU)", false; } else if (format == 2) { - model_path_ = model_dir_ + "\\model.wgcm"; + model_path_ = wgrt::model_wgcm_path(model_dir_, model_l ? wgrt::ModelId::L : wgrt::ModelId::M); if (!exists(model_path_)) return *err = "no converted model at " + model_path_ + " (run the WrongGPU installer)", false; if (!wg_file_exists(map_)) return *err = "the converter map " + map_ + " is missing (reinstall WrongGPU)", false; diff --git a/clean/runtime/interop/tests/model_path_check.cpp b/clean/runtime/interop/tests/model_path_check.cpp new file mode 100644 index 00000000..c1ec9848 --- /dev/null +++ b/clean/runtime/interop/tests/model_path_check.cpp @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +// The converted model file each model resolves to (clean/runtime/model_select.h model_wgcm_path, used by every +// executor's create check in interop/backend.cpp): Model M unchanged, Model L in its own folder. CPU only. +// Run by test_model_path.py. WrongGPU's own code. +#include +#include + +#include "../../model_select.h" + +int main() { + int failures = 0; + auto expect = [&](const char* name, const std::string& got, const std::string& want) { + const bool ok = got == want; + std::printf("%s %s: %s\n", ok ? "pass" : "FAIL", name, got.c_str()); + if (!ok) ++failures; + }; + using wgrt::ModelId; + const std::string d = "C:\\Games\\X\\bin\\x64\\WrongGPU\\model"; + expect("model=M", wgrt::model_wgcm_path(d, ModelId::M), d + "\\model.wgcm"); + expect("model=L", wgrt::model_wgcm_path(d, ModelId::L), d + "\\L\\model.wgcm"); + expect("model=K", wgrt::model_wgcm_path(d, ModelId::K), d + "\\K\\model.wgcm"); + expect("model=L, '/'", wgrt::model_wgcm_path("/m", ModelId::L, '/'), "/m/L/model.wgcm"); + // the option the front end passes resolves to the same model + ModelId id = ModelId::M; + std::string bad; + const bool parsed = wgrt::last_model_option("view=upscale;model=L;executor=dx12", &id, &bad); + expect("model=L option", parsed && id == ModelId::L ? "L" : "other", "L"); + id = ModelId::M; + wgrt::last_model_option("view=upscale;executor=dx12", &id, &bad); + expect("no model option", id == ModelId::M ? "M" : "other", "M"); + return failures ? 1 : 0; +} diff --git a/clean/runtime/interop/tests/test_model_path.py b/clean/runtime/interop/tests/test_model_path.py new file mode 100644 index 00000000..3144bbff --- /dev/null +++ b/clean/runtime/interop/tests/test_model_path.py @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +"""The model file each model resolves to on every executor (model_path_check.cpp, model_select.h model_wgcm_path): +model=L -> \\L\\model.wgcm, model=M unchanged (\\model.wgcm). CPU only.""" +import os +import subprocess +import sys +import unittest + +ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))) +sys.path.insert(0, os.path.join(ROOT, "clean", "tests")) +import host_cxx # noqa: E402 + + +class TestModelPath(unittest.TestCase): + def test_paths(self): + exe = host_cxx.build("model_path_check", ["clean/runtime/interop/tests/model_path_check.cpp"]) + r = subprocess.run([exe], capture_output=True, text=True) + self.assertEqual(r.returncode, 0, r.stdout + r.stderr) + self.assertIn("pass model=L: C:\\Games\\X\\bin\\x64\\WrongGPU\\model\\L\\model.wgcm", r.stdout) + self.assertIn("pass model=M: C:\\Games\\X\\bin\\x64\\WrongGPU\\model\\model.wgcm", r.stdout) + + +if __name__ == "__main__": + unittest.main() diff --git a/clean/runtime/model_select.h b/clean/runtime/model_select.h index 96395c10..b789516d 100644 --- a/clean/runtime/model_select.h +++ b/clean/runtime/model_select.h @@ -37,6 +37,13 @@ inline const ModelInfo& model_info(ModelId id) { return kModelTable[0]; } +// The converted model file of model `id` under the model directory: model.wgcm +// (Model M: model.wgcm; Model L: Lmodel.wgcm). Every executor's check uses it. +inline std::string model_wgcm_path(const std::string& model_dir, ModelId id, char sep = '\\') { + const char* sub = model_info(id).model_subdir; + return model_dir + (*sub ? std::string(1, sep) + sub : std::string()) + sep + "model.wgcm"; +} + // A model name in either case ("M", "m", "K", ...). False: no such model. inline bool model_from_name(const std::string& v, ModelId* id) { for (const ModelInfo& m : kModelTable) {