diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index e7a1632d61..50dd51614b 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2816,6 +2816,24 @@ Pipeline creation: A root signature the runtime does not know is hashed by its address, so the key of a pipeline made with one can change from one run to the next. The file is local, like the cache files, and is not meant to be attached to a report: quote the counts. It changes no build, order or cache. + `LEONIDA_PIPELINE_PREWARM_ORDER=` reads such a log at boot and builds, ahead of their first draw, the graphics + and mesh pipelines an earlier run asked for first (RT-PIPELINE-PREWARM-ORDER, phase 2; `runtime/src/pipeline_prewarm.h`). + `1` names `pipeline_order.log` beside the session cache; it is read before this run's own record is appended, so + both variables can be on together. Of the runs recorded on this GPU (vendor and device id), the one with the most + records is read, the newest on a tie. When the title creates a PSO whose key is in it, each recorded variant is + queued on the compile workers as a warm-up at its recorded rank: after every demanded build, one warm-up at a time + and none while a demanded build runs (`PipelineCompiler`; the compile-gate finding in "Compile workers" below is + why), ahead of the compute warm-up's size order and before the cache checkpoint. A variant 0 built at create is + skipped. A console stream kept for its first bind (`LEONIDA_PIPELINE_COMPILE=on-demand`) is otherwise parsed only + there, which would leave the prewarm no lead: when its pipeline is in the plan, the parse is queued as its first + prewarm job instead (at the rank of its first recorded variant, on a compile worker), and its variants follow with + their ranks. A bind that comes first waits for that parse, which it would otherwise have done itself. Records are taken in order until their recorded build times add up to + `LEONIDA_PIPELINE_PREWARM_BUDGET_MS` (default 300000; a record with no build time counts 1000 ms), and at most + `LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES` (default 4096). Compute records are left to the compute warm-up and to + `gta6rt --precompile-pipelines`. A missing or unreadable file, a file with no readable record and a file from + another GPU are ignored with one `[rt] pipeline-prewarm:` line; a damaged line is skipped, as are line types a v1 + reader does not know (`E`). A queued prewarm holds no reference: a PSO released first drops it. One that is already + running when the title submits still holds the compile gate (`LEONIDA_COMPILE_GATE`), as any warm-up does. A queued build holds no reference to its PSO or device (`PipelineCompiler`, `runtime/shims/d3d12_pipeline_compile.h`). A PSO's last release drops its queued builds and returns at once; one already running is left to finish, and the worker deletes the PSO after it (`PipelineState::last_release`). The PSO's device reference goes at the release, so diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 8f7b84a6c4..46ea96aaf7 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -882,15 +882,15 @@ if(BUILD_TESTING) add_executable(pipeline_cache_store_test test/pipeline_cache_store_test.cpp) add_test(NAME pipeline_cache_store COMMAND pipeline_cache_store_test) + add_executable(heavy_pipeline_cache_test test/heavy_pipeline_cache_test.cpp) + add_test(NAME heavy_pipeline_cache COMMAND heavy_pipeline_cache_test) + # RT-PIPELINE-PREWARM-ORDER phase 1: the file format and the recorder of src/pipeline_order.h (pure stdlib, no GPU). add_executable(pipeline_order_test test/pipeline_order_test.cpp) target_link_libraries(pipeline_order_test PRIVATE Threads::Threads) add_test(NAME pipeline_order COMMAND pipeline_order_test) set_tests_properties(pipeline_order PROPERTIES TIMEOUT 120) - add_executable(heavy_pipeline_cache_test test/heavy_pipeline_cache_test.cpp) - add_test(NAME heavy_pipeline_cache COMMAND heavy_pipeline_cache_test) - # The per-pipeline journal files compute pipelines are kept in: naming, header check, atomic replacement. add_executable(pipeline_cache_journal_test test/pipeline_cache_journal_test.cpp) add_test(NAME pipeline_cache_journal COMMAND pipeline_cache_journal_test) @@ -2625,6 +2625,14 @@ if(TARGET Vulkan::Headers) target_compile_options(d3d12_compile_pool_test PRIVATE /W4 /permissive- /utf-8) add_test(NAME d3d12_compile_pool COMMAND d3d12_compile_pool_test) set_tests_properties(d3d12_compile_pool PROPERTIES TIMEOUT 120) + # RT-PIPELINE-PREWARM-ORDER phase 2: the plan read from an order log (src/pipeline_prewarm.h) and its warm-ups on the + # compile workers, with jobs that wait at gates; no device. + add_executable(pipeline_prewarm_test test/pipeline_prewarm_test.cpp) + target_link_libraries(pipeline_prewarm_test PRIVATE gta6rt_d3d12_com) + target_compile_definitions(pipeline_prewarm_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) + target_compile_options(pipeline_prewarm_test PRIVATE /W4 /permissive- /utf-8) + add_test(NAME pipeline_prewarm COMMAND pipeline_prewarm_test) + set_tests_properties(pipeline_prewarm PROPERTIES TIMEOUT 120) add_executable(d3d12_pipeline_workers_test test/d3d12_pipeline_workers_test.cpp) target_link_libraries(d3d12_pipeline_workers_test PRIVATE gta6rt_d3d12_com) target_compile_definitions(d3d12_pipeline_workers_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) diff --git a/runtime/README.md b/runtime/README.md index d33ca91f2c..bd9105ea14 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -331,6 +331,9 @@ ones marked *diagnostic* only add log lines or exist to compare a run with and w | `LEONIDA_ASYNC_MIN_BYTES` | unset | ``, with `LEONIDA_ASYNC_PIPELINES=1`: only a pipeline of n bytes of SPIR-V or more (compute: its module; graphics: all its stages) is built asynchronously, its draws or dispatches skipped until the compile worker has it; a smaller one is built where it is needed, as with asynchronous builds off, so small lighting and post programs are not skipped while the large ray-tracing ones compile. Unset or `0`: every pipeline is asynchronous. Text that is not a decimal number is ignored, with a log line. ([docs/d3d12_vulkan.md](../docs/d3d12_vulkan.md), "Only the large ones asynchronous") | | `LEONIDA_COMPUTE_WARMUP_MAX_BYTES` | `1048576` | The largest SPIR-V module, in bytes, the background warm-up thread (`LEONIDA_COMPUTE_WARMUP`) builds ahead of its first dispatch. Larger modules wait for that dispatch. | | `LEONIDA_PIPELINE_ORDER_LOG` | unset (off) | `1` appends, for each pipeline and variant (the unbound-slot mask of a graphics pipeline) that a dispatch or draw names for the first time, one line to `pipeline_order.log` beside `pipeline_cache.session.bin`: the PSO's description key, the variant, when the title created the PSO and when it first used it (milliseconds since the process started), the build time and whether the handle was ready already. A line of counts is printed at exit (`[rt] pipeline-order: requested N, already ready M, median lead X ms`). The hook never blocks and allocates nothing; it takes only a non-blocking `try_lock`, on the first request of a pipeline and of a variant. Record only: nothing builds, orders or skips differently, and no cache file is touched. At most 8192 lines per run; a file past 8 MiB is set aside as `pipeline_order.log.prev`. The file holds hashes and numbers, no shader or game data, and stays local. See `docs/d3d12_vulkan.md`. | +| `LEONIDA_PIPELINE_PREWARM_ORDER` | unset (off) | ``: an order log written with `LEONIDA_PIPELINE_ORDER_LOG=1` in an earlier run; `1`: `pipeline_order.log` beside the session cache. The graphics and mesh pipelines that run asked for first are queued, when the title creates them, as warm-ups on the compile workers in the recorded order: after every demanded build, one at a time and none while a demanded build runs. The run read is this GPU's with the most records. With `LEONIDA_PIPELINE_COMPILE=on-demand`, a console stream in the plan is parsed by its first prewarm job rather than at its first bind. A missing, garbled or other-GPU file is ignored with one `[rt] pipeline-prewarm:` line. See `docs/d3d12_vulkan.md`. | +| `LEONIDA_PIPELINE_PREWARM_BUDGET_MS` | `300000` | With `LEONIDA_PIPELINE_PREWARM_ORDER`: records are prewarmed in order until their recorded build times add up to this many milliseconds (a record with no build time counts 1000). | +| `LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES` | `4096` | With `LEONIDA_PIPELINE_PREWARM_ORDER`: at most this many pipeline variants are prewarmed. | | `LEONIDA_SERIAL_BIG_COMPILES` | unset | Large pipelines (compute modules over 128 KiB of SPIR-V, graphics pipelines of 1 MiB or more) compile side by side while their estimates, 512 bytes of memory for each byte of SPIR-V, fit a budget (`LEONIDA_BIG_COMPILE_BUDGET_MB`): one always does, what a submission waits for goes before the warm-up, and the warm-up takes a quarter of the budget at most. `1` compiles the compute ones one at a time, and the graphics ones of a submission one after another, as before there was a budget. `0` lets all of them compile side by side, within the compile workers' heavy count (`LEONIDA_COMPILE_HEAVY_MAX`) for the asynchronous builds and the warm-up. | | `LEONIDA_BIG_COMPILE_BUDGET_MB` | unset | The budget, in MiB: a fixed number (`0`: one large pipeline at a time) instead of three quarters of the memory that is free at the moment, which is the smaller of the free RAM and the room under the commit limit, read again for each pipeline. Text that is not a number is ignored. | | `LEONIDA_CONSOLE_FORMATS` | on | Texture descriptions the console accepts and a PC GPU may not (an R9G9B9E5 render target, an sRGB RGBA8 or BGRA8 texture with unordered access) get a host format that can do the job. `0` refuses them, as a PC D3D12 runtime does. | diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 008e1cc1d2..031fa22e12 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -53,6 +53,7 @@ #include "../src/pipeline_cache_store.h" #include "../src/pipeline_cache_journal.h" #include "../src/pipeline_order.h" +#include "../src/pipeline_prewarm.h" #include "../src/large_module_gate.h" #include "../src/dev_status.h" #include "../src/conservative_raster.h" @@ -2726,6 +2727,41 @@ struct DeviceState { // LEONIDA_PIPELINE_ORDER_LOG=1: which pipelines the title asks for first, appended to pipeline_order.log beside the // session cache (pipeline_order.h). Null when off: the pipelines then carry no hook at all. std::unique_ptr order_log; + // LEONIDA_PIPELINE_PREWARM_ORDER= ("1": pipeline_order.log beside the session cache): the graphics pipelines an + // earlier run asked for first, queued as warm-ups in that order when the title creates them (pipeline_prewarm.h). + // Null when off. Read before start_order_log, which appends this run to the same file when both are on. + std::unique_ptr prewarm_plan; + void load_prewarm_plan() { + namespace prewarm = leonida::pipeline_prewarm; + wchar_t value[1024]{}; + const DWORD n = GetEnvironmentVariableW(L"LEONIDA_PIPELINE_PREWARM_ORDER", value, DWORD(std::size(value))); + if (n == 0 || n >= std::size(value) || (n == 1 && value[0] == L'0')) return; + try { + std::filesystem::path path = value; + if (n == 1 && value[0] == L'1') { + path = pipeline_cache_session_path(); + if (path.empty()) { + std::fprintf(stderr, "[rt] pipeline-prewarm: no session cache folder; nothing is prewarmed\n"); + return; + } + path.replace_filename(L"pipeline_order.log"); + } + const auto count = [](const char* name, std::uint64_t fallback) { + char text[32]{}; + const DWORD m = GetEnvironmentVariableA(name, text, sizeof(text)); + return prewarm::parse_count(m > 0 && m < sizeof(text) ? text : nullptr, fallback); + }; + prewarm::Options options; + options.budget_ms = count("LEONIDA_PIPELINE_PREWARM_BUDGET_MS", prewarm::default_budget_ms); + options.max_entries = std::size_t(count("LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES", prewarm::default_max_entries)); + auto plan = prewarm::load_plan(path, pso_identity.vendor, pso_identity.device, options); + std::fprintf(stderr, "%s\n", plan.message.c_str()); + if (plan) prewarm_plan = std::make_unique(std::move(plan)); + } catch (const std::exception& e) { + std::fprintf(stderr, "[rt] pipeline-prewarm: the order log could not be read (%s); nothing is prewarmed\n", + e.what()); + } + } void start_order_log() { char text[8]{}; const DWORD n = GetEnvironmentVariableA("LEONIDA_PIPELINE_ORDER_LOG", text, sizeof(text)); @@ -12513,6 +12549,7 @@ class PipelineState final } registered_ = true; is_graphics_ = true; + prewarm_queue(std::size_t((std::max)(spirv_bytes, std::uint64_t{1}))); return S_OK; } @@ -12778,7 +12815,9 @@ class PipelineState final // handle once built; otherwise a compile-worker job is queued (once) and null answered, so the draw or dispatch is // skipped and a later submission uses the pipeline. `warm_bytes`: a warm-up, queued by module size. `count_skip`: // false for a request made at record time (request_early), which skips nothing. - VkPipeline queue_build(bool compute, std::uint32_t unbound, std::size_t warm_bytes = 0, bool count_skip = true) { + // `priority`: where a warm-up goes among the others (PipelineCompiler); 0: by `warm_bytes`, the module size. + VkPipeline queue_build(bool compute, std::uint32_t unbound, std::size_t warm_bytes = 0, bool count_skip = true, + std::size_t priority = 0) { static std::mutex publication; // ready handles only; no compiler call holds this lock const bool warm = warm_bytes != 0; // After an exit stop (stop_pipeline_compiles) nothing is queued: a warm-up or an early request is skipped, @@ -12797,7 +12836,7 @@ class PipelineState final } bool queued = false; try { - queued = PipelineCompiler::instance().submit(compile_owner(), &device_, warm_bytes, + queued = PipelineCompiler::instance().submit(compile_owner(), &device_, warm && priority ? priority : warm_bytes, [this, compute, warm, unbound, warm_bytes] { // A big warm-up while the title submits is left to the pipeline's first use (warmup_waits_for_quiet). if (warm && warmup_waits_for_quiet(warm_bytes)) return; @@ -12839,7 +12878,42 @@ class PipelineState final return VK_NULL_HANDLE; } + // LEONIDA_PIPELINE_PREWARM_ORDER: the variants an earlier run asked this graphics pipeline for, queued as warm-ups at + // their recorded rank (pipeline_prewarm.h): after every demanded build, one warm-up at a time and none while a + // demanded build runs (PipelineCompiler). A queued one holds no reference: a release first drops it (last_release). + void prewarm_queue(std::size_t bytes) { + const auto* plan = device_.prewarm_plan.get(); + if (!plan) return; + const auto& key = order_key_.empty() ? cache_key_ : order_key_; + const auto* entries = key.empty() ? nullptr : plan->find(key); + if (!entries) return; + for (const auto& entry : *entries) { + if (entry.variant == 0 && graphics_.pipeline) continue; // built at create + queue_build(false, entry.variant, bytes, true, leonida::pipeline_prewarm::priority(entry.rank)); + } + } + public: + // A console stream kept for its first bind (LEONIDA_PIPELINE_COMPILE=on-demand, set_pending_stream) is parsed only + // when it is first resolved, and create_graphics queues the prewarm from there: no lead at all. When the plan has + // the stream's pipeline, the parse is queued here as its first prewarm job instead, at the rank of its first + // recorded variant, on a compile worker rather than the title's thread; create_graphics then queues the variants + // with their ranks as for any other PSO. A bind meanwhile waits for that parse (resolve_type's call_once), which it + // would otherwise have done itself. Like any queued build it holds no reference (last_release drops it). + void prewarm_pending_stream() { + const auto* plan = device_.prewarm_plan.get(); + if (!plan || pending_stream_kind_ != 1) return; + const auto& key = order_key_.empty() ? cache_key_ : order_key_; + const auto* entries = key.empty() ? nullptr : plan->find(key); + if (!entries || entries->empty()) return; + try { + PipelineCompiler::instance().submit(compile_owner(), &device_, + leonida::pipeline_prewarm::priority(entries->front().rank), + [this] { resolve_type(true); }, true); + } catch (...) { + } + } + // Record time (SetPipelineState for compute, a draw for graphics, with the render-target slots it binds and // whether it binds a depth buffer): asynchronous builds start on the compile worker before the list is submitted. // Never waits; nothing to do when the variant is the last one asked for here. @@ -14611,6 +14685,7 @@ class Device final state_.pso_identity.device = props.deviceID; state_.pso_identity.driver = props.driverVersion; std::memcpy(state_.pso_identity.cache_uuid, props.pipelineCacheUUID, VK_UUID_SIZE); + state_.load_prewarm_plan(); // first: the order log may append this run to the same file state_.start_order_log(); if (state_.info.max_push_constants_size == 0) { state_.info.max_push_constants_size = props.limits.maxPushConstantsSize; @@ -15615,9 +15690,10 @@ class Device final auto* pipeline=new PipelineState(state_); pipeline->attach_device(identity()); pipeline->set_cache_key(stream.has_cs?pipeline_key(stream.compute):pipeline_key(stream.graphics)); - if(state_.order_log) pipeline->set_order_key(order_key(stream)); + if(state_.order_log||state_.prewarm_plan) pipeline->set_order_key(order_key(stream)); if(!rt::d3d12_xs::attach_pso_record(pipeline,std::move(record))){pipeline->Release();return E_OUTOFMEMORY;} pipeline->set_pending_stream(stream.has_cs); + pipeline->prewarm_pending_stream(); return hand_out(pipeline,iid,out); } HRESULT shared_native_graphics(const D3D12_GRAPHICS_PIPELINE_STATE_DESC& pc, D3D12_SHADER_BYTECODE mesh, @@ -17853,7 +17929,7 @@ class Device final if (FAILED(parsed)) return finish(parsed); auto* pipeline = new PipelineState(state_); pipeline->attach_device(identity()); - if (state_.order_log) pipeline->set_order_key(order_key(stream)); + if (state_.order_log || state_.prewarm_plan) pipeline->set_order_key(order_key(stream)); const HRESULT hr = stream.has_cs ? pipeline->create_compute(stream.compute) : pipeline->create_graphics(stream.graphics, &stream.ms, &stream.as, stream.back_masks ? &stream.back_stencil : nullptr, stream.depth_bounds); diff --git a/runtime/src/pipeline_prewarm.h b/runtime/src/pipeline_prewarm.h new file mode 100644 index 0000000000..394164aa98 --- /dev/null +++ b/runtime/src/pipeline_prewarm.h @@ -0,0 +1,171 @@ +// RT-PIPELINE-PREWARM-ORDER, phase 2 (in-game): build at boot, ahead of their first draw, the pipelines an earlier run +// asked for first, in the order it asked for them. Off unless LEONIDA_PIPELINE_PREWARM_ORDER names an order log +// (pipeline_order.h, written with LEONIDA_PIPELINE_ORDER_LOG=1); "1" names pipeline_order.log beside the session cache. +// +// The plan is read once, when the device starts. A pipeline the title creates whose description key is in it gets its +// recorded variants queued on the compile workers (d3d12_pipeline_compile.h) as warm-ups, at a priority that keeps the +// recorded order: below every demanded build, and one warm-up at a time, none while a demanded build runs. +// +// Which run: of the sessions recorded on this GPU (vendor and device id), the one with the most records, the newest of +// those on a tie. A file from another GPU, a missing or unreadable file and a file with no usable record are ignored +// with one line on stderr; a damaged line is skipped (pipeline_order::parse), as are line types a v1 reader does not +// know (MoonEyes' `E` lines for the offline precompiler). +// +// Graphics and mesh records only: compute pipelines already have their own warm-up by module size, and the offline +// precompiler takes their recorded order (gta6rt --precompile-pipelines --order-file). +// +// The budget is the build time the earlier run recorded: records are taken in order until their build times add up to +// LEONIDA_PIPELINE_PREWARM_BUDGET_MS (default 300000), and at most LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES (default 4096). +// A record with no build time counts as unknown_build_ms. +#pragma once + +#include "pipeline_order.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace leonida::pipeline_prewarm { + +inline constexpr std::uint64_t default_budget_ms = 300000; +inline constexpr std::size_t default_max_entries = 4096; +inline constexpr std::uint32_t unknown_build_ms = 1000; // what a record with no build time counts against the budget + +struct Options { + std::uint64_t budget_ms = default_budget_ms; + std::size_t max_entries = default_max_entries; +}; + +// One variant of one pipeline to build, and where it came in the recorded order (0 first). +struct Entry { + std::uint32_t rank = 0; + std::uint32_t variant = 0; + char kind = 'g'; +}; + +// The compile-worker priority of a prewarm: after demanded builds (0), in recorded order. Compute warm-ups use their +// module size (some hundred KiB), so prewarms mostly go first; the checkpoint (SIZE_MAX) stays last. +inline std::size_t priority(std::uint32_t rank) { return std::size_t{1} + rank; } + +struct Plan { + std::unordered_map> by_key; // description key -> its variants, in recorded order + std::size_t entries = 0; // variants planned + std::size_t session_records = 0; // records of the session read + std::size_t compute_skipped = 0; // compute records left to the size-ordered warm-up + std::size_t over_budget = 0; // graphics and mesh records past the budget or the entry limit + std::uint64_t budget_used_ms = 0; // recorded build time of the planned ones + std::size_t bad_lines = 0; // damaged or unknown lines skipped + std::string message; // the one line for stderr: what was read, or why nothing is prewarmed + + explicit operator bool() const { return entries != 0; } + const std::vector* find(std::string_view key) const { + const auto it = by_key.find(std::string(key)); + return it == by_key.end() ? nullptr : &it->second; + } +}; + +// Drops the lines a v1 reader does not know but that are not damage: `E` lines (the library entry of a record, for the +// offline precompiler). pipeline_order::parse would count them as bad lines. +inline std::string without_unknown_lines(std::string_view text) { + std::string out; + out.reserve(text.size()); + std::size_t at = 0; + while (at < text.size()) { + std::size_t end = text.find('\n', at); + const bool last = end == std::string_view::npos; + if (last) end = text.size(); + const std::string_view line = text.substr(at, end - at); + if (!(line.size() >= 2 && line[0] == 'E' && line[1] == ' ')) { + out += line; + if (!last) out += '\n'; + } + at = last ? end : end + 1; + } + return out; +} + +// The plan from the text of an order log, for the GPU with this vendor and device id. `source` names the file in the +// message. Never throws on any text. +inline Plan make_plan(std::string_view text, std::uint32_t vendor, std::uint32_t device, const Options& options = {}, + std::string_view source = "the order log") { + Plan plan; + const auto read = pipeline_order::parse(without_unknown_lines(text)); + plan.bad_lines = read.bad_lines; + const pipeline_order::Session* chosen = nullptr; + std::size_t other_gpu = 0; + for (const auto& session : read.sessions) { + if (session.records.empty()) continue; + if (session.vendor != vendor || session.device != device) { + ++other_gpu; + continue; + } + if (!chosen || session.records.size() >= chosen->records.size()) chosen = &session; + } + const std::string head = "[rt] pipeline-prewarm: ", where(source); + if (!chosen) { + plan.message = head + "nothing to prewarm from " + where + ": " + + (other_gpu ? std::to_string(other_gpu) + " recorded run(s), none on this GPU" + : std::string("no readable record")) + + (plan.bad_lines ? " (" + std::to_string(plan.bad_lines) + " damaged line(s) skipped)" : ""); + return plan; + } + plan.session_records = chosen->records.size(); + std::unordered_set seen; // key + variant: a record repeated in a session is planned once + std::uint32_t rank = 0; + for (const auto& record : chosen->records) { + if (record.kind == 'c') { + ++plan.compute_skipped; + continue; + } + if (!seen.insert(record.key + '/' + std::to_string(record.variant)).second) continue; + const std::uint64_t cost = record.build_ms == pipeline_order::unknown_ms ? unknown_build_ms : record.build_ms; + if (plan.entries >= options.max_entries || plan.budget_used_ms + cost > options.budget_ms) { + ++plan.over_budget; + continue; + } + plan.budget_used_ms += cost; + plan.by_key[record.key].push_back({rank++, record.variant, record.kind}); + ++plan.entries; + } + plan.message = head + std::to_string(plan.entries) + " graphics variant(s) of " + + std::to_string(plan.by_key.size()) + " pipeline(s) to prewarm from " + where + " (a run of " + + std::to_string(plan.session_records) + " record(s); " + std::to_string(plan.budget_used_ms) + + " ms recorded build time; " + std::to_string(plan.over_budget) + " over the budget; " + + std::to_string(plan.compute_skipped) + " compute left to the warm-up"; + if (plan.bad_lines) plan.message += "; " + std::to_string(plan.bad_lines) + " damaged line(s) skipped"; + plan.message += ")"; + return plan; +} + +// Reads the file and makes the plan. A file that cannot be read gives an empty plan with the reason. +inline Plan load_plan(const std::filesystem::path& path, std::uint32_t vendor, std::uint32_t device, + const Options& options = {}) { + std::ifstream in(path, std::ios::binary); + if (!in) { + Plan plan; + plan.message = "[rt] pipeline-prewarm: cannot read " + path.string() + "; nothing is prewarmed"; + return plan; + } + std::ostringstream text; + text << in.rdbuf(); + return make_plan(text.str(), vendor, device, options, path.string()); +} + +// A positive whole number, or `fallback` for unset, empty, zero, or anything else. +inline std::uint64_t parse_count(const char* text, std::uint64_t fallback) { + if (!text || !*text) return fallback; + std::uint64_t v = 0; + for (const char* p = text; *p; ++p) { + if (*p < '0' || *p > '9' || v > (UINT64_MAX - 9) / 10) return fallback; + v = v * 10 + std::uint64_t(*p - '0'); + } + return v ? v : fallback; +} + +} // namespace leonida::pipeline_prewarm diff --git a/runtime/test/d3d12_pipeline_workers_test.cpp b/runtime/test/d3d12_pipeline_workers_test.cpp index 8d567e2263..5c8e5556b5 100644 --- a/runtime/test/d3d12_pipeline_workers_test.cpp +++ b/runtime/test/d3d12_pipeline_workers_test.cpp @@ -8,7 +8,10 @@ // - pipeline states released while a submission compiles: the ones it uses live on, and the release of any other waits // until the submission has its pipelines; // - a device whose last references go while its workers compile: the workers have ended before the pipeline cache is -// read for pipeline_cache.session.bin. +// read for pipeline_cache.session.bin; +// - the prewarm from a recorded order (LEONIDA_PIPELINE_PREWARM_ORDER, src/pipeline_prewarm.h) builds its graphics +// pipelines before the first bind for pipeline states made from a console stream (device slot 86), also when the +// stream is kept for its first bind (LEONIDA_PIPELINE_COMPILE=on-demand), and nothing without a plan. // With LEONIDA_LAZY_PIPELINES=0 and LEONIDA_LAZY_COMPUTE=0 the pipelines are compiled when they are created and only the // variants are left to the submission; the cases that need more than that are then left out. // The calls that create pipelines and read the cache are watched, and held back, through the device's vkGetDeviceProcAddr. @@ -17,6 +20,7 @@ #include "d3d12_test_shaders.h" #include "test_temp_dir.h" #include "../shims/d3d12_com.h" +#include "../shims/d3d12_xs_device.h" #include "../src/shader_library.h" #include @@ -28,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -405,7 +410,7 @@ struct Setup { vktest::Device* vk; std::string library; - bool device(const char* threads, Ref& out) const { + bool device(const char* threads, Ref& out, bool prepare_on_bind = false) const { _putenv_s("LEONIDA_PIPELINE_THREADS", threads); rt::d3d12::VulkanDeviceInfo info{}; info.get_instance_proc = instance_proc; @@ -418,13 +423,34 @@ struct Setup { info.subgroup = vk->subgroup; info.features = vk->enabled; info.shader_dir = library; + info.prepare_on_bind = prepare_on_bind; // LEONIDA_PIPELINE_COMPILE=on-demand CHECK(SUCCEEDED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&out.p)))); return true; } }; +// One pipeline state stream subobject as d3dx12.h declares it (CD3DX12_PIPELINE_STATE_STREAM_SUBOBJECT). +template +struct alignas(void*) Subobject { + D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type = Type; + Inner inner; +}; +struct Stream { + std::vector bytes; + template + Stream& add(const Inner& inner) { + const Subobject subobject{Type, inner}; + static_assert(sizeof(subobject) % sizeof(void*) == 0); + const std::size_t at = bytes.size(); + bytes.resize(at + sizeof(subobject)); + std::memcpy(bytes.data() + at, &subobject, sizeof(subobject)); + return *this; + } +}; + struct Pipelines { Ref root; + ID3D12Device* console = nullptr; // set: graphics pipeline states through this console device's slot 86 std::vector states; // kGraphics, then kCompute ~Pipelines() { release(); } void release() { @@ -458,6 +484,44 @@ struct Pipelines { return SUCCEEDED(dev->CreateGraphicsPipelineState(&pd, IID_PPV_ARGS(&out))) ? out : nullptr; } + // The same description as a stream, through the console device's CreatePipelineState (slot 86). + static ID3D12PipelineState* console_graphics(ID3D12Device* dev, ID3D12RootSignature* root, unsigned n) { + const auto vs = d3d12test::shader_container(program(0, 0)), ps = d3d12test::shader_container(program(1, n)); + D3D12_BLEND_DESC blend{}; + for (auto& rt : blend.RenderTarget) { + rt.SrcBlend = rt.SrcBlendAlpha = D3D12_BLEND_ONE; + rt.DestBlend = rt.DestBlendAlpha = D3D12_BLEND_ZERO; + rt.BlendOp = rt.BlendOpAlpha = D3D12_BLEND_OP_ADD; + rt.LogicOp = D3D12_LOGIC_OP_NOOP; + rt.RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; + } + D3D12_RASTERIZER_DESC raster{}; + raster.FillMode = D3D12_FILL_MODE_SOLID; + raster.CullMode = D3D12_CULL_MODE_NONE; + raster.DepthClipEnable = TRUE; + D3D12_DEPTH_STENCIL_DESC depth{}; + depth.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS; + D3D12_RT_FORMAT_ARRAY targets{}; + targets.NumRenderTargets = n < kVariants ? 2 : 1; + for (UINT i = 0; i < targets.NumRenderTargets; ++i) targets.RTFormats[i] = DXGI_FORMAT_R8G8B8A8_UNORM; + Stream stream; + stream.add(root) + .add(D3D12_SHADER_BYTECODE{vs.data(), vs.size()}) + .add(D3D12_SHADER_BYTECODE{ps.data(), ps.size()}) + .add(blend) + .add(UINT(UINT_MAX)) + .add(raster) + .add(depth) + .add(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE) + .add(targets) + .add(DXGI_SAMPLE_DESC{1, 0}); + const D3D12_PIPELINE_STATE_STREAM_DESC desc{stream.bytes.size(), stream.bytes.data()}; + using Create = HRESULT(WINAPI*)(ID3D12Device*, const D3D12_PIPELINE_STATE_STREAM_DESC*, REFIID, void**); + ID3D12PipelineState* out = nullptr; + const auto create = reinterpret_cast(d3d12test::slot(dev, 86)); + return SUCCEEDED(create(dev, &desc, IID_PPV_ARGS(&out))) ? out : nullptr; + } + bool create(ID3D12Device* dev) { D3D12_ROOT_PARAMETER params[2]{}; params[0].ParameterType = D3D12_ROOT_PARAMETER_TYPE_UAV; @@ -469,7 +533,7 @@ struct Pipelines { const auto blob = d3d12test::serialize_root_signature(desc); CHECK(SUCCEEDED(dev->CreateRootSignature(0, blob.data(), blob.size(), IID_PPV_ARGS(&root.p)))); for (unsigned n = 0; n < kGraphics; ++n) { - auto* state = graphics(dev, root.p, n); + auto* state = console ? console_graphics(console, root.p, n) : graphics(dev, root.p, n); CHECK(state); states.push_back(state); } @@ -812,10 +876,69 @@ bool device_destroyed(const Setup& setup) { return true; } +// LEONIDA_PIPELINE_PREWARM_ORDER (src/pipeline_prewarm.h) with graphics pipeline states from console streams. A first +// device records the order (LEONIDA_PIPELINE_ORDER_LOG=1); the next ones read it with an eight-entry cap and wait, before +// recording any command, for the prewarm to build those eight. With the stream kept for its first bind (on-demand) the +// parse is the prewarm's first job, so the eight are built before any bind there too. Without a plan nothing is built +// before the submission. +bool prewarm_from_recorded_order(const Setup& setup) { + const testfiles::ScratchDir dir("leonida_pipeline_prewarm_test"); + const std::string log = (dir.path() / "pipeline_order.log").string(); + _putenv_s("LEONIDA_PIPELINE_CACHE_DIR", dir.path().string().c_str()); + const auto draw = [&](bool on_demand, int before_bind) { + Ref inner, dev; + CHECK(setup.device("4", inner, on_demand)); + // The console device (slot 86 is its CreatePipelineState), as the title sees it. + CHECK(SUCCEEDED(rt::d3d12_xs::create_device_proxy(inner.p, __uuidof(ID3D12Device), + reinterpret_cast(&dev.p)))); + rt::d3d12::set_device_outer(inner.p, dev.p); + ID3D12Device* const pc = inner.p; // the rest is made through the PC device the proxy wraps + inner.p = nullptr; // the proxy owns that reference now + Pipelines pipelines; + pipelines.console = dev.p; + hooks.reset(); + CHECK(pipelines.create(pc)); + if (before_bind) { + std::unique_lock lock(hooks.mutex); + hooks.changed.wait_for(lock, 8s, [&] { return hooks.graphics >= before_bind; }); + } + std::this_thread::sleep_for(200ms); // nothing more comes + { + std::lock_guard lock(hooks.mutex); + if (hooks.graphics != before_bind) + std::fprintf(stderr, "prewarm (%s): %d graphics builds before the first bind, %d expected\n", + on_demand ? "on-demand" : "console stream", hooks.graphics, before_bind); + CHECK(hooks.graphics == before_bind); + } + Frame frame; + CHECK(frame.create(pc, pipelines)); + CHECK(frame.submit() == ReplayResult::success); + CHECK(frame.read() == reference); + CHECK(hooks.graphics == int(kGraphics)); // each built once, prewarmed or not + return true; + }; + _putenv_s("LEONIDA_PIPELINE_ORDER_LOG", "1"); + const bool recorded = draw(false, 0); // no plan yet: nothing before the bind + _putenv_s("LEONIDA_PIPELINE_ORDER_LOG", ""); + CHECK(recorded); + CHECK(std::filesystem::exists(log)); + _putenv_s("LEONIDA_PIPELINE_PREWARM_ORDER", log.c_str()); + _putenv_s("LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES", "8"); + const bool console = draw(false, 8); + const bool on_demand = draw(true, 8); + _putenv_s("LEONIDA_PIPELINE_PREWARM_ORDER", ""); + _putenv_s("LEONIDA_PIPELINE_PREWARM_MAX_ENTRIES", ""); + const bool no_plan = draw(true, 0); + _putenv_s("LEONIDA_PIPELINE_CACHE_DIR", ""); + CHECK(console && on_demand && no_plan); + return true; +} + bool run(const Setup& setup) { if (!same_image(setup)) return false; return !first_use || (refused_graphics(setup) && refused_compute(setup) && two_queues(setup) && - released_while_compiling(setup) && device_destroyed(setup)); + released_while_compiling(setup) && device_destroyed(setup) && + prewarm_from_recorded_order(setup)); } } // namespace diff --git a/runtime/test/pipeline_prewarm_test.cpp b/runtime/test/pipeline_prewarm_test.cpp new file mode 100644 index 0000000000..7c4fe5ebac --- /dev/null +++ b/runtime/test/pipeline_prewarm_test.cpp @@ -0,0 +1,305 @@ +// RT-PIPELINE-PREWARM-ORDER phase 2 (src/pipeline_prewarm.h) without a device: the plan read from an order log, and the +// plan's warm-ups on the compile workers (shims/d3d12_pipeline_compile.h), whose jobs wait at gates the test opens. +// - the recorded order is kept, on the workers too; +// - the budget (recorded build time) and the entry limit are respected; +// - a demanded build overtakes the queued prewarms and starts while one runs; +// - a missing, garbled or other-GPU log gives no plan, with a message; `E` lines are skipped as not damage. +#include "../src/pipeline_prewarm.h" +#include "../shims/d3d12_pipeline_compile.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { +int failures = 0; +#define EXPECT(cond) \ + do { \ + if (!(cond)) { \ + std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \ + ++failures; \ + } \ + } while (0) + +namespace order = leonida::pipeline_order; +namespace prewarm = leonida::pipeline_prewarm; +using rt::d3d12::CompilePool; +using rt::d3d12::PipelineCompiler; +using namespace std::chrono_literals; + +constexpr std::uint32_t vendor = 0x10de, device_id = 0x2783; + +std::string key(int i) { + char text[65]; + std::snprintf(text, sizeof(text), "%064x", i + 1); + return text; +} + +order::Record record(char kind, int i, std::uint32_t variant, std::uint32_t build_ms) { + order::Record r; + r.kind = kind; + r.key = key(i); + r.variant = variant; + r.created_ms = 100; + r.first_ms = 200 + std::uint32_t(i); + r.build_ms = build_ms; + return r; +} + +std::string session(const std::vector& records, std::uint32_t device = device_id) { + std::string text = order::format_session(vendor, device); + for (const auto& r : records) text += order::format_record(r); + return text; +} + +void test_order_is_kept() { + const std::string text = order::format_header() + + session({record('g', 3, 0, 50), record('m', 1, 0, 50), record('c', 7, 0, 50), + record('g', 3, 0x100, 50), record('g', 2, 0, 50), record('g', 3, 0, 50)}); + const auto plan = prewarm::make_plan(text, vendor, device_id); + EXPECT(plan); + EXPECT(plan.entries == 4); // the repeated (key 3, variant 0) once, the compute record left out + EXPECT(plan.compute_skipped == 1); + EXPECT(plan.session_records == 6); + EXPECT(plan.by_key.size() == 3); + const auto* three = plan.find(key(3)); + EXPECT(three && three->size() == 2); + if (three && three->size() == 2) { + EXPECT((*three)[0].rank == 0 && (*three)[0].variant == 0 && (*three)[0].kind == 'g'); + EXPECT((*three)[1].rank == 2 && (*three)[1].variant == 0x100); + } + const auto* one = plan.find(key(1)); + EXPECT(one && one->size() == 1 && (*one)[0].rank == 1 && (*one)[0].kind == 'm'); + const auto* two = plan.find(key(2)); + EXPECT(two && two->size() == 1 && (*two)[0].rank == 3); + EXPECT(!plan.find(key(7))); + EXPECT(prewarm::priority(0) > 0 && prewarm::priority(0) < prewarm::priority(1)); + EXPECT(plan.message.find("4 graphics variant(s) of 3 pipeline(s)") != std::string::npos); +} + +void test_the_largest_run_on_this_gpu_is_read() { + const std::string text = order::format_header() + session({record('g', 1, 0, 1), record('g', 2, 0, 1)}) + + session({record('g', 3, 0, 1), record('g', 4, 0, 1), record('g', 5, 0, 1)}, 0x9999) + + session({record('g', 6, 0, 1)}) + + session({record('g', 7, 0, 1), record('g', 8, 0, 1)}); + const auto plan = prewarm::make_plan(text, vendor, device_id); + EXPECT(plan.entries == 2); + EXPECT(plan.find(key(7)) && plan.find(key(8))); // the newer of the two largest; the other GPU's run is not read + EXPECT(!plan.find(key(3)) && !plan.find(key(1))); +} + +void test_the_budget_is_respected() { + const std::string text = session({record('g', 0, 0, 400), record('g', 1, 0, 400), record('g', 2, 0, 300), + record('g', 3, 0, order::unknown_ms), record('g', 4, 0, 100)}); + prewarm::Options options; + options.budget_ms = 1000; + auto plan = prewarm::make_plan(text, vendor, device_id, options); + // 400 + 400 fit, 300 would make 1100, the unknown one counts 1000, 100 fits: 900. + EXPECT(plan.entries == 3); + EXPECT(plan.find(key(0)) && plan.find(key(1)) && plan.find(key(4))); + EXPECT(!plan.find(key(2)) && !plan.find(key(3))); + EXPECT(plan.budget_used_ms == 900); + EXPECT(plan.over_budget == 2); + if (const auto* four = plan.find(key(4))) EXPECT((*four)[0].rank == 2); // ranks stay consecutive + + options.budget_ms = prewarm::default_budget_ms; + options.max_entries = 2; + plan = prewarm::make_plan(text, vendor, device_id, options); + EXPECT(plan.entries == 2 && plan.over_budget == 3); + + EXPECT(prewarm::parse_count(nullptr, 7) == 7); + EXPECT(prewarm::parse_count("", 7) == 7); + EXPECT(prewarm::parse_count("0", 7) == 7); + EXPECT(prewarm::parse_count("12x", 7) == 7); + EXPECT(prewarm::parse_count("-5", 7) == 7); + EXPECT(prewarm::parse_count("99999999999999999999999", 7) == 7); + EXPECT(prewarm::parse_count("120000", 7) == 120000); +} + +void test_a_missing_or_garbled_log_is_ignored_with_a_message() { + const auto missing = prewarm::load_plan(std::filesystem::temp_directory_path() / "leonida-no-such-order.log", + vendor, device_id); + EXPECT(!missing && missing.message.find("cannot read") != std::string::npos); + + const auto garbled = prewarm::make_plan("\x01\x02 not a log\nP g zz\n\xff\xfe", vendor, device_id); + EXPECT(!garbled && garbled.message.find("no readable record") != std::string::npos); + EXPECT(garbled.bad_lines >= 1); + + std::string damaged = session({record('g', 1, 0, 5), record('g', 2, 0, 5)}); + damaged[damaged.find(key(2)) + 3] ^= 1; // the checksum no longer matches: that line is skipped + const auto partial = prewarm::make_plan(damaged, vendor, device_id); + EXPECT(partial.entries == 1 && partial.find(key(1)) && partial.bad_lines == 1); + EXPECT(partial.message.find("1 damaged line(s) skipped") != std::string::npos); + + const auto other_gpu = prewarm::make_plan(session({record('g', 1, 0, 5)}, 0x1234), vendor, device_id); + EXPECT(!other_gpu && other_gpu.message.find("none on this GPU") != std::string::npos); + + EXPECT(!prewarm::make_plan("", vendor, device_id)); + + // An `E` line (the offline precompiler's) is neither read nor counted as damage. + std::string with_e = order::format_session(vendor, device_id) + order::format_record(record('g', 1, 0, 5)) + + "E " + key(1) + " 0 0123456789abcdef *00000000\n" + order::format_record(record('g', 2, 0, 5)); + const auto e_lines = prewarm::make_plan(with_e, vendor, device_id); + EXPECT(e_lines.entries == 2 && e_lines.bad_lines == 0); + + // A file on disk, read the same way. + const auto path = std::filesystem::temp_directory_path() / "leonida-pipeline-prewarm-test.log"; + { + std::ofstream out(path, std::ios::binary); + out << order::format_header() << session({record('g', 9, 0, 5)}); + } + const auto file = prewarm::load_plan(path, vendor, device_id); + EXPECT(file.entries == 1 && file.find(key(9))); + EXPECT(file.message.find(path.string()) != std::string::npos); + std::error_code ignored; + std::filesystem::remove(path, ignored); +} + +// The plan's warm-ups on the compile workers. +struct Gate { + std::mutex mutex; + std::condition_variable changed; + bool open = false; + void wait() { + std::unique_lock lock(mutex); + changed.wait(lock, [this] { return open; }); + } + void release() { + { + std::lock_guard lock(mutex); + open = true; + } + changed.notify_all(); + } +}; + +struct Log { + std::mutex mutex; + std::condition_variable changed; + std::vector started, finished; + void start(const std::string& name) { + std::lock_guard lock(mutex); + started.push_back(name); + changed.notify_all(); + } + void finish(const std::string& name) { + std::lock_guard lock(mutex); + finished.push_back(name); + changed.notify_all(); + } + bool has_started(const std::string& name) { + std::lock_guard lock(mutex); + return std::find(started.begin(), started.end(), name) != started.end(); + } + bool wait_started(std::size_t count) { + std::unique_lock lock(mutex); + return changed.wait_for(lock, 10s, [&] { return started.size() >= count; }); + } + bool wait_finished(std::size_t count) { + std::unique_lock lock(mutex); + return changed.wait_for(lock, 10s, [&] { return finished.size() >= count; }); + } +}; + +const char device_slot = 0; +const void* const device = &device_slot; + +PipelineCompiler& make_pool(unsigned threads) { + auto* pool = new PipelineCompiler; // never destroyed, as in d3d12_compile_pool_test + CompilePool config; + config.threads = threads; + config.heavy = threads - 1; + EXPECT(pool->configure(config)); + pool->retain(); + return *pool; +} + +void submit(PipelineCompiler& pool, Log& log, Gate* gate, const void* owner, const std::string& name, + std::size_t priority) { + EXPECT(pool.submit(owner, device, priority, [&log, gate, name] { + log.start(name); + if (gate) gate->wait(); + log.finish(name); + }, true)); +} + +// What the device does with a plan: each pipeline the title creates gets its planned variants queued (here, in an +// order unlike the recorded one, as the title may create them). +void queue_plan(PipelineCompiler& pool, Log& log, const prewarm::Plan& plan, const std::vector& created, + Gate* first_gate = nullptr) { + for (const int i : created) + if (const auto* entries = plan.find(key(i))) + for (const auto& e : *entries) + submit(pool, log, e.rank == 0 ? first_gate : nullptr, &plan.by_key.at(key(i)), + key(i).substr(60) + "/" + std::to_string(e.variant), prewarm::priority(e.rank)); +} + +void test_prewarms_build_in_recorded_order() { + const auto plan = prewarm::make_plan( + session({record('g', 3, 0, 5), record('g', 1, 0, 5), record('g', 3, 4, 5), record('g', 2, 0, 5)}), vendor, + device_id); + auto& pool = make_pool(3); + Log log; + Gate busy; + char title_slot = 0; + submit(pool, log, &busy, &title_slot, "demand", 0); // queued while a demanded build runs: none starts yet + EXPECT(log.wait_started(1)); + queue_plan(pool, log, plan, {2, 1, 3}); + std::this_thread::sleep_for(100ms); + EXPECT(!log.has_started("0004/0")); + busy.release(); + EXPECT(log.wait_finished(5)); + std::lock_guard lock(log.mutex); + const std::vector want{"demand", "0004/0", "0002/0", "0004/4", "0003/0"}; + EXPECT(log.started == want); + pool.release(); +} + +void test_a_demanded_build_overtakes_the_prewarms() { + const auto plan = prewarm::make_plan( + session({record('g', 1, 0, 5), record('g', 2, 0, 5), record('g', 3, 0, 5)}), vendor, device_id); + auto& pool = make_pool(2); + Log log; + Gate first, demand; + queue_plan(pool, log, plan, {1, 2, 3}, &first); + EXPECT(log.wait_started(1)); // the first prewarm runs, the others wait (one warm-up at a time) + std::this_thread::sleep_for(50ms); + EXPECT(!log.has_started("0003/0")); + char title_slot = 0; + submit(pool, log, &demand, &title_slot, "demand", 0); + EXPECT(log.wait_started(2)); // on the free worker, while the prewarm runs + EXPECT(log.has_started("demand")); + first.release(); + EXPECT(log.wait_finished(1)); + std::this_thread::sleep_for(100ms); + EXPECT(!log.has_started("0003/0") && !log.has_started("0004/0")); // none while the demanded build runs + demand.release(); + EXPECT(log.wait_finished(4)); + std::lock_guard lock(log.mutex); + const std::vector want{"0002/0", "demand", "0003/0", "0004/0"}; + EXPECT(log.started == want); + pool.release(); +} +} // namespace + +int main() { + test_order_is_kept(); + test_the_largest_run_on_this_gpu_is_read(); + test_the_budget_is_respected(); + test_a_missing_or_garbled_log_is_ignored_with_a_message(); + test_prewarms_build_in_recorded_order(); + test_a_demanded_build_overtakes_the_prewarms(); + if (failures) { + std::fprintf(stderr, "%d failure(s)\n", failures); + return 1; + } + std::puts("pipeline_prewarm_test: ok"); + return 0; +}