Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clean/k/runtime/runtime_k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ bool KRuntime::create(const WgRtConfig& c, Device* dev, AllocFn alloc_fn, bool e
if (approx_a2_ && !compact_head_) return fail("model K: k_approx=a2 needs the compact head (k_head=compact, the default)");
approx_note_ = std::string("model K: close approximation k_approx=") + (approx_a1_ ? "a1" : "") +
(approx_a1_ && approx_a2_ ? "," : "") + (approx_a2_ ? "a2" : "") +
" (opt-in, not bit-exact; the default path is exact)" +
" (opt-in faster approximation; the default is the standard path)" +
(approx_a1_ ? std::string("; a1 applies to the tiled input stage, frames on the legacy input path "
"run the exact input stage")
"run the standard input stage")
: std::string());
}
const std::string krule = option(c, "k_expo_rule");
Expand Down Expand Up @@ -1247,7 +1247,7 @@ bool KRuntime::frame(const WgRtFrame& fr, const FrameIo* io) {
// log, the first time in this context (take_frame_note)
if (approx_a1_ && !use_tiled && !a1_legacy_noted_) {
a1_legacy_noted_ = true;
frame_note_ = "model K: k_approx=a1 applies to the tiled input stage only; this context's frames on the legacy input path (a render size above 0.68 x the output, a jitter outside [-0.5, 0.5], or input_tiled=0) run the exact input stage (this line once per context)";
frame_note_ = "model K: k_approx=a1 applies to the tiled input stage only; this context's frames on the legacy input path (a render size above 0.68 x the output, a jitter outside [-0.5, 0.5], or input_tiled=0) run the standard input stage (this line once per context)";
}
// k_in_exact: the output colour taps by k_out_color (KFrame's exact plan), not by the tiled input kernel
const bool use_tiled_color = use_tiled && !in_exact_ && !reset && 4LL * Bw_ >= W_ && 4LL * Bh_ >= H_;
Expand Down
8 changes: 4 additions & 4 deletions clean/k/tests/test_k_approx_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
k_approx=a2 output form; the executor runs the direct one) runs
test_interop_d3d12.exe's `matrix` case at 1080p (every usual upscaler-mode ratio, HDR and LDR, both declared maximum
sizes): with nothing set every context is taken by the D3D12 executor and its frame runs (the executor's warm-up does not
compile the unselected form) and its mode line names the exact path; with k_approx=a2 every context is refused, naming
compile the unselected form) and its mode line names the standard path; with k_approx=a2 every context is refused, naming
the shader. The unchanged build passes with k_approx=a2 (control: the refusal comes from the changed byte) and its mode
line names k_approx=a2 and an approximation.

Expand Down Expand Up @@ -84,17 +84,17 @@ def test_selected_form_runs(self):
self.assertTrue(out.rstrip().endswith("PASS"), out)
modes = mode_lines(out)
self.assertEqual(len(modes), 20, modes)
self.assertTrue(all(";k_approx=a2;" in m and "an approximation (not bit-exact)" in m for m in modes), modes)
self.assertTrue(all(";k_approx=a2;" in m and "an approximation (opt-in)" in m for m in modes), modes)

def test_unselected_form_is_not_prepared(self):
"""The changed shader, nothing set: every context runs on the exact path (the warm-up skips the form)."""
"""The changed shader, nothing set: every context runs on the standard path (the warm-up skips the form)."""
rc, out = self.run_case(True, [])
self.assertEqual(rc, 0, out)
self.assertTrue(out.rstrip().endswith("PASS"), out)
self.assertNotIn("integrity mismatch", out)
modes = mode_lines(out)
self.assertEqual(len(modes), 20, modes)
self.assertTrue(all("k_approx" not in m and "the exact path" in m for m in modes), modes)
self.assertTrue(all("k_approx" not in m and "the standard path" in m for m in modes), modes)

def test_a1_legacy_line_once_per_context(self):
"""The a1 contract through the executor: the matrix's DLAA contexts (render size = output: the legacy input path)
Expand Down
49 changes: 49 additions & 0 deletions clean/k/tests/test_k_option_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: MIT
"""Model K's player-visible option text (host check, no GPU).

The create note of the opt-in k_approx option (clean/k/runtime/runtime_k.cpp, approx_note_), its a1 legacy-input line
and the front end's K mode line (clean/runtime/interop/backend.cpp) reach the player's log. They name the option as a
faster approximation and the default as the standard path (input stage); they make no claim of exactness (the project's
wording rule). The note itself is checked on a device by
clean/k/tests/test_k_runtime_d3d12.py test_k_approx_each_tag.

Run: python -m unittest clean.k.tests.test_k_option_text
"""
import os
import re
import unittest

ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))


class TestKOptionText(unittest.TestCase):
def test_k_approx_note_wording(self):
with open(os.path.join(ROOT, "clean", "k", "runtime", "runtime_k.cpp"), encoding="utf-8") as f:
src = f.read()
m = re.search(r"approx_note_ = std::string\(\"model K: close approximation k_approx=\"\)(.*?);\n", src, re.S)
self.assertIsNotNone(m, "approx_note_ assignment not found")
stmt = m.group(1)
fixed = stmt.split("(approx_a1_ ? std::string(")[0] # the part every k_approx note carries
self.assertIn('" (opt-in faster approximation; the default is the standard path)"', fixed)
self.assertNotIn("exact", fixed)
self.assertNotIn("default path is exact", src)
a1 = stmt.split("(approx_a1_ ? std::string(")[1] # the a1 part of the note
self.assertIn("run the standard input stage", a1)
self.assertNotIn("exact", a1)
m = re.search(r'frame_note_ = "(model K: k_approx=a1 [^"]*)";', src)
self.assertIsNotNone(m, "the a1 legacy-input line not found")
self.assertIn("run the standard input stage", m.group(1))
self.assertNotIn("exact", m.group(1))

def test_k_mode_line_wording(self):
"""The front end's K mode line (clean/runtime/interop/backend.cpp) names the default as the standard path and an
opt-in mode as an approximation, with no claim of exactness."""
with open(os.path.join(ROOT, "clean", "runtime", "interop", "backend.cpp"), encoding="utf-8") as f:
src = f.read()
m = re.search(r'network model K mode: network=.*?\(exact \? "([^"]*)" : "([^"]*)"\)', src, re.S)
self.assertIsNotNone(m, "the K mode line not found")
self.assertEqual(m.groups(), (", the standard path", ", an approximation (opt-in)"))


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions clean/k/tests/test_k_runtime_d3d12.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ def test_k_approx_each_tag(self):
self.assertEqual(got["k_approx"], tags)
self.assertEqual(len(got["notes"]), 1, got)
self.assertIn("close approximation k_approx=" + tags, got["notes"][0])
self.assertIn("(opt-in faster approximation; the default is the standard path)", got["notes"][0])
self.assertNotIn("default path is exact", got["notes"][0])
self.need_dev_build()
fb = self.leg("k_approx=a1,a2;k_smx_test=mix_fail")
self.assertTrue(fb["ok"], fb)
Expand Down
2 changes: 1 addition & 1 deletion clean/runtime/interop/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ class Context {
say(WG_LOG_INFO, std::string("network model K mode: network=") + (net.empty() ? "fused" : net) + ";k_fast=" +
(fast.empty() ? "0" : fast) + (approx.empty() ? std::string() : ";k_approx=" + approx) +
";handover=" + (staged_out_ ? "staged" : "fence") +
(exact ? ", the exact path" : ", an approximation (not bit-exact)") +
(exact ? ", the standard path" : ", an approximation (opt-in)") +
(k_default_ ? " (the default mode; network=fused8;k_fast=1;handover=staged selects the "
"fastest mode)"
: " (from the options)"));
Expand Down
Loading