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: 6 additions & 0 deletions clean/rr_f/runtime/src/rr_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3542,6 +3542,12 @@ void release_transient_locked(void* copy) {
ID3D12Resource* r = *it;
rt.transient.erase(it);
defer_release(r, rt.serial);
// issue #8: create, evaluate and destroy run pump() too, but a game that tags its inputs every frame while no
// instance exists (RR available, switched off) calls none of them, and the released copies were never freed.
// pump() frees only resources whose frame marker the GPU has written (the same test as at evaluate), takes no lock
// of its own and calls nothing back. The caller, a_release_transient, holds rt.mu, as every other user of the deferred
// list does.
pump();
}

// ---------------------------------------------------------------------------------------------------- the adapter
Expand Down
21 changes: 19 additions & 2 deletions clean/rr_f/runtime/tests/e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ def write_frame(path, c):


# ------------------------------------------------------------------------------------------------- GPU run
def run_gpu(out, stage, runs, perf_frames, name="e2e", leak=6, head=None, body="Z", inp="exact", front=True, mips=1):
TAGLOOP_LIMIT_MIB = 256 # issue #8: 200 frames grew video memory by about 2.6 GiB before the fix, about 60 MiB after


def run_gpu(out, stage, runs, perf_frames, name="e2e", leak=6, head=None, body="Z", inp="exact", front=True, mips=1,
tagloop=200):
"""runs: [(scenario name, calls)]; every scenario twice (WG_RR_ALIAS=0 and aliased)."""
work = os.path.join(out, name)
if os.path.exists(work):
Expand All @@ -250,6 +254,9 @@ def run_gpu(out, stage, runs, perf_frames, name="e2e", leak=6, head=None, body="
job.append("env WG_RR_TAILPREP 0")
if mips > 1: # 0.6.0 follow-up: the game's inputs with mips (mip 0 is read): the checks
job.append(f"env WG_RR_TEST_MIPS {mips}") # below then prove the same bits as with one mip
if tagloop: # issue #8: inputs copied and released every frame before any instance
job += [f"outdir {os.path.join(work, 'tagloop')}", # exists; video memory may grow by at most TAGLOOP_LIMIT_MIB
f"tagloop {tagloop} 1706 960 {TAGLOOP_LIMIT_MIB}"]
for sname, calls in runs:
sc = SCEN[sname]
for alias in (0, 1):
Expand Down Expand Up @@ -815,6 +822,8 @@ def main(argv=None):
ap.add_argument("--jobs", type=int, default=8)
ap.add_argument("--perf", type=int, default=600)
ap.add_argument("--leak", type=int, default=6)
ap.add_argument("--tagloop", type=int, default=200, help="issue #8: frames of inputs copied and released with no "
"instance, before the scenarios (0: skip)")
ap.add_argument("--body", default="Z", help="WG_RR_BODY for the GPU run (default Z: exact body + exact front-end MLP, "
"checked bit-exact; 'default': the runtime's default step E, which the exact body check flags)")
ap.add_argument("--head", default="exact", help="WG_RR_HEAD for the GPU run (exact / fast / strict; default exact: since "
Expand Down Expand Up @@ -842,7 +851,8 @@ def main(argv=None):
work = os.path.join(a.out, name)
if not a.skip_gpu:
work = run_gpu(a.out, stage, runs, a.perf, name, a.leak, None if a.head == "default" else a.head,
None if a.body == "default" else a.body, None if a.input == "default" else a.input, mips=a.mips)
None if a.body == "default" else a.body, None if a.input == "default" else a.input, mips=a.mips,
tagloop=a.tagloop)
rows, life, inv, al = [], [], [], []
jobs = []
metas = {}
Expand Down Expand Up @@ -875,6 +885,9 @@ def main(argv=None):
p = os.path.join(work, f"run{runs[-1][0]}1", "leak.json")
if os.path.exists(p):
report["leak"] = json.load(open(p))
p = os.path.join(work, "tagloop", "tagloop.json")
if os.path.exists(p):
report["tagloop"] = json.load(open(p))
p = os.path.join(work, f"run{runs[-1][0]}1", "perf.json")
if os.path.exists(p):
report["perf"] = [json.loads(l) for l in open(p) if l.strip()]
Expand All @@ -896,6 +909,10 @@ def main(argv=None):
lines.append(f"| lifecycle (par / fc / reset / rebuild / failed call) | {sum(x['ok'] for x in life)} / {len(life)} |")
lines.append(f"| failed call leaves state unchanged | {sum(x['state_unchanged'] for x in inv)} / {len(inv)} |")
lines.append(f"| aliased run = unaliased run (outputs, state) | {sum(x['ok'] for x in al)} / {len(al)} |")
if "tagloop" in report:
t = report["tagloop"]
lines.append(f"| inputs released with no instance: video memory growth (limit {t['limit_mib']:.0f} MiB) | "
f"{t['growth_mib']:.1f} MiB over {t['frames']} frames |")
with open(os.path.join(work, "report.md"), "w") as fh:
fh.write("\n".join(lines) + "\n")
print("\n".join(lines))
Expand Down
53 changes: 53 additions & 0 deletions clean/rr_f/runtime/tests/rr_test_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
// retag <input file> <role> bug hunt B: <role> copied as a lifetime-0 input and released again before any
// evaluate (the game re-tags it): the copy must stay until the list that recorded it
// has run (a deferred release), and be gone after it (exit 9 otherwise)
// tagloop <frames> <w> <h> [<limit MiB>] issue #8: a lifetime-0 RGBA16F input copied and released every frame with
// no instance and no evaluate (RR available, switched off); video memory may grow
// by at most <limit MiB> (exit 12 otherwise)
// destroy
// leak <cycles> <input file> create / 2 frames / destroy per cycle; live counters and video memory
// perfcap <passes> <file> ... game-setup timing: the frames resident, evaluated <passes> times without waits
Expand Down Expand Up @@ -1008,6 +1011,56 @@ int main(int argc, char** argv) {
for (ID3D12Resource* u : h.uploads) u->Release();
h.uploads.clear();
if (!ok) return 9;
} else if (cmd == "tagloop") {
// issue #8: a game that tags its RR inputs every frame while no RR instance exists (RR available, switched off).
// Each frame one lifetime-0 input is copied (retain_transient_state, as the plugin's tag handler does), the
// previous copy is released (the input tagged again), and the frame's list runs. No instance, no evaluate, no
// test drain or counters (both run the runtime's pump): only the adapter calls a game makes. Video memory is
// measured with QueryVideoMemoryInfo (CurrentUsage); the run stops early at +3 GiB.
int frames = 0;
uint32_t tw = 0, th = 0;
double limit_mib = 0;
s >> frames >> tw >> th >> limit_mib;
if (frames <= 0 || !tw || !th) {
fprintf(stderr, "usage: tagloop <frames> <width> <height> [<limit MiB>]\n");
return 7;
}
Tex t = make_tex(tw, th, DXGI_FORMAT_R16G16B16A16_FLOAT, false, D3D12_RESOURCE_STATE_COMMON);
const uint64_t v0 = vram(), cap = 3ull << 30;
uint64_t peak = v0;
void* prev = nullptr;
int ran = 0;
for (int i = 0; i < frames; ++i) {
void* copy = nullptr;
if (g_rt->retain_transient_state(g_rt->ctx, g_l, t.r, (uint32_t)t.f, (uint32_t)t.state, &copy) != WG_OK || !copy) {
fprintf(stderr, "retain_transient_state failed at frame %d\n", i);
return 8;
}
if (prev) g_rt->release_transient(g_rt->ctx, prev); // the input tagged again: the previous copy goes
prev = copy;
submit_wait(); // the game's frame runs
++ran;
const uint64_t v = vram();
peak = std::max(peak, v);
if (v > v0 + cap) break;
}
const uint64_t v1 = vram();
if (prev) g_rt->release_transient(g_rt->ctx, prev);
t.r->Release();
const double grow = ((double)v1 - (double)v0) / 1048576.0, peak_grow = ((double)peak - (double)v0) / 1048576.0;
const bool ok = limit_mib <= 0 || grow <= limit_mib;
FILE* fo = fopen((h.outdir + "\\tagloop.json").c_str(), "wb");
if (fo) {
fprintf(fo, "{\"frames\":%d,\"width\":%u,\"height\":%u,\"vram_before\":%llu,\"vram_after\":%llu,\"vram_peak\":%llu,"
"\"growth_mib\":%.1f,\"limit_mib\":%.1f}\n", ran, tw, th, (unsigned long long)v0,
(unsigned long long)v1, (unsigned long long)peak, grow, limit_mib);
fclose(fo);
}
printf("tagloop: %d frames of a %ux%u RGBA16F lifetime-0 input, no instance: video memory %llu -> %llu bytes "
"(%+.1f MiB, peak %+.1f MiB; limit %.0f MiB): %s\n", ran, tw, th, (unsigned long long)v0,
(unsigned long long)v1, grow, peak_grow, limit_mib,
ok ? "ok" : "FAIL (released copies are not freed without an evaluate)");
if (!ok) return 12;
} else if (cmd == "destroy") {
destroy(h);
} else if (cmd == "leak") {
Expand Down
Loading