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
40 changes: 40 additions & 0 deletions clean/dx12/kernel_sets.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,46 @@
"k_expo_scalars_direct",
"k_io.co"
],
[
"k_stage2_d0_hidden",
"k_block.co"
],
[
"k_stage2_d0_hp",
"k_block.co"
],
[
"k_stage2_d1",
"k_block.co"
],
[
"k_stage2_e0",
"k_block.co"
],
[
"k_stage2_e1",
"k_block.co"
],
[
"k_stage_d1",
"k_block.co"
],
[
"k_stage_d2",
"k_block.co"
],
[
"k_stage_e0",
"k_block.co"
],
[
"k_stage_e1",
"k_block.co"
],
[
"k_stage_e2",
"k_block.co"
],
[
"k_warm",
"k_block_wide.co"
Expand Down
35 changes: 27 additions & 8 deletions clean/dx12/tests/kernel_replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
// module <code object name> [<tag>] (zero or more)
// buf <id> <bytes> <file | -> [fill] device buffer: the file's bytes (padded with fill when the file is
// shorter), or every byte set to fill (0..255, default 0) with "-"
// step <launch name> <grid> <block> <arg>... a launch; each arg is @<id> (a buffer's pointer), a 32-bit decimal
// step <launch name> <grid> <block> <arg>... a launch; each arg is @<id>[+<bytes>] (a buffer's pointer, optionally
// that many bytes into it), null (a null pointer), a 32-bit decimal
// value, B:<file> (a struct passed by value: the file's bytes) or
// S:<file>[:<offset>=@<id>[,<offset>=@<id>...]] (a struct with pointers
// S:<file>[:<offset>=@<id>[+<bytes>][,...]] (a struct with pointers
// inside, manifest argument kind s<N>:...: the file's bytes with the 8
// bytes at each byte offset replaced by that buffer's device pointer)
// save <id> <file> after the run, the buffer's bytes are written to <file>
Expand Down Expand Up @@ -386,6 +387,14 @@ int run_chain(Device* d, Chain& c, const std::string& base) {
if (b.id == id) return &b;
return nullptr;
};
// "<id>" or "<id>+<byte offset>": a buffer's device pointer, optionally that many bytes into it
auto resolve = [&](const std::string& ref, DevPtr* out) -> bool {
const size_t plus = ref.find('+');
ChainBuf* b = find(ref.substr(0, plus));
if (!b) return false;
*out = b->ptr + (plus == std::string::npos ? 0 : (DevPtr)std::stoull(ref.substr(plus + 1)));
return true;
};
int rc = 0;
for (auto& b : c.bufs) {
std::vector<uint8_t> data(b.bytes, (uint8_t)(b.fill & 0xff));
Expand Down Expand Up @@ -431,10 +440,13 @@ int run_chain(Device* d, Chain& c, const std::string& base) {
const size_t comma = a.find(',', at);
const std::string item = a.substr(at, comma == std::string::npos ? std::string::npos : comma - at);
const size_t eq = item.find("=@");
ChainBuf* b = eq == std::string::npos ? nullptr : find(item.substr(eq + 2));
DevPtr target = 0;
const size_t off = eq == std::string::npos ? 0 : (size_t)std::stoull(item.substr(0, eq));
if (!b || off + 8 > blob.size()) { ok = false; break; }
for (int k = 0; k < 8; ++k) blob[off + k] = (uint8_t)((uint64_t)b->ptr >> (8 * k));
if (eq == std::string::npos || off + 8 > blob.size() || !resolve(item.substr(eq + 2), &target)) {
ok = false;
break;
}
for (int k = 0; k < 8; ++k) blob[off + k] = (uint8_t)((uint64_t)target >> (8 * k));
at = comma == std::string::npos ? std::string::npos : comma + 1;
}
if (!ok) {
Expand All @@ -444,10 +456,17 @@ int run_chain(Device* d, Chain& c, const std::string& base) {
}
blobs[i].push_back(std::move(blob));
argv[i].push_back(blobs[i].back().data());
} else if (a == "null") { // a null pointer
ptrs[i].push_back(0);
argv[i].push_back(&ptrs[i].back());
} else if (!a.empty() && a[0] == '@') {
ChainBuf* b = find(a.substr(1));
if (!b) { std::printf("%s: step %zu: unknown buffer %s\n", c.name.c_str(), i, a.c_str()); rc = 1; break; }
ptrs[i].push_back(b->ptr);
DevPtr target = 0;
if (!resolve(a.substr(1), &target)) {
std::printf("%s: step %zu: unknown buffer %s\n", c.name.c_str(), i, a.c_str());
rc = 1;
break;
}
ptrs[i].push_back(target);
argv[i].push_back(&ptrs[i].back());
} else {
vals[i].push_back((uint32_t)std::stoll(a));
Expand Down
13 changes: 11 additions & 2 deletions clean/k/dx12/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ and starts filled with its run's own sentinel (HIP `0xA5`, D3D12 `0x5A`); the de
slack must keep its sentinel; special values are among the inputs; a negative control (the port given another input
than HIP) must be caught; Model M's `scale_rgb` runs through the same replay as a control. Output: counts and verdicts.

Families: `expo` (`k_expo_scalars`) against `k_io.co`; `warm` (`k_warm`, a cache warm-up with no HIP kernel: checked
against its definition, through the struct argument path).
Families: `narrow` (the narrow network stages of `k_block.co`: `k_stage_e2`, `k_stage_e0`, `k_stage_e1`, `k_stage_d2`,
`k_stage_d1`, `k_stage2_e0`, `k_stage2_e1`, `k_stage2_d1`, `k_stage2_d0_hp`, `k_stage2_d0_hidden`) on random stage weights
and inputs, the stage runner's launch plans run on HIP and replayed on D3D12 (`k_plan_bridge.py`); the inputs of every
third case carry special values (infinity, +-65504, zero, -0, subnormals) and of every third case NaN as well; the
half-grid control launches a stage with half its workgroups. `expo` (`k_expo_scalars`) against `k_io.co`; `warm`
(`k_warm`, a cache warm-up with no HIP kernel: checked against its definition, through the struct argument path).

NaN: IEEE 754 does not define the sign or payload of a NaN, and where a NaN is generated or propagated the two devices
can differ in it (the decoder stages, with NaN in the input). For the cases with NaN in the input the check compares the
raw bytes and, where they differ, reports the elements that are NaN on both sides separately; every other byte must be
identical. Without NaN in the input the raw bytes are identical.

Known limit, shared with Model M's ports: D3D12 flushes FP32 denormals (inputs and results) to zero and HIP keeps them.
`k_expo_scalars` only meets one with a pre-exposure above about 8.5e37, so the check's inputs keep clear of them.
13 changes: 13 additions & 0 deletions clean/k/dx12/hlsl/k_blkparams.hlsli
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
// Model K's stage kernel arguments for the D3D12 ports (WrongGPU's own code): KBlkParams of clean/k/kernels/k_block.hip
// as the manifest token s184:p19.b32 lays it out (clean/runtime/struct_args.h). Include before WG_ARGS_BEGIN and put
// KBLK_PARAMS_DECL inside the argument block; the kernel's other headers (k_block.hlsli, k_common.hlsli) come after
// WG_ARGS_END.
#pragma once

// KBlkParams (clean/k/kernels/k_block.hip, 184 bytes) as the manifest token s184:p19.b32 lays it out: 19 pointers (one
// root constant each: the arena byte offset, 0 = null), then 8 ints. Declare inside WG_ARGS_BEGIN / WG_ARGS_END.
#define KBLK_PARAMS_DECL \
uint P_x, P_skip, P_y, P_merged, P_head, P_g1, P_g2, P_wqkv, P_mix, P_wo, P_bo, P_w1, P_b1, P_w2, P_b2, P_wa, \
P_ba, P_wz, P_bz; \
int P_w, P_h, P_ox, P_oy, P_nwx, P_nwy, P_cw, P_ch;
Loading
Loading