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
4 changes: 4 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ python -m unittest discover -s clean\rr_f\proxy\tests -t clean\rr_f\proxy\tests
python -m unittest discover -s clean\rr_f\proxy\tests -t clean\rr_f\proxy\tests -p test_gen_forwarding.py
```

`clean\runtime\tests\test_wmma_probe.cpp` checks Model M's driver-channel probe (`clean\runtime\wmma_probe.h`) on
any host: build it with any C++17 compiler (`clang++ -std=c++17 test_wmma_probe.cpp`) and run it; exit status 0 when
it passes. `clean\dx12\tests\native_probe_test.cpp` runs the same probe on the GPU (see 7).

`clean\wgshared\tests\*.py` are scripts that the wgshared ctest runs. The Ray Reconstruction plugin's CPU tests are
executables that `clean\rr_f\proxy\tools\build.py --no-tests` builds; run them as that script does:
`out\rr-proxy\core\test_proxy_core.exe`, `test_probe_core.exe`, `test_setupapi_identity.exe`,
Expand Down
14 changes: 10 additions & 4 deletions clean/dx12/kernels/native_game_helpers.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
WG_ARGS_BEGIN
uint dst;
WG_ARGS_END
// D = A x B + C with FP16 and with FP8 operands. The host (clean/runtime/wmma_probe.h) writes A, B and C in fragment
// layout with distinct values per lane and element and checks every result, so a different fragment layout fails.
// Buffer byte offsets: wmma_probe.h kOutF16 0, kOutFp8 1024, kInC 2048, kInAF16 3072, kInBF16 3584, kInAFp8 4096,
// kInBFp8 4352. All loads come before the first matrix call (wg_ags.hlsli rules).
WG_KERNEL(native_driver_probe) {
WG_SETUP();
uint lane=wg_lane_id();
v8f c=wg_splat((float)lane);
v8f h=wg_wmma_f16(uint4(0x3c003c00u,0x3c003c00u,0x3c003c00u,0x3c003c00u),
uint4(0x40004000u,0x40004000u,0x40004000u,0x40004000u),c);
v8f q=wg_wmma_fp8(uint2(0x38383838u,0x38383838u),uint2(0x40404040u,0x40404040u),c);
uint4 a16=wg_ld128(dst,3072u+lane*16u),b16=wg_ld128(dst,3584u+lane*16u);
uint2 a8=wg_ld64(dst,4096u+lane*8u),b8=wg_ld64(dst,4352u+lane*8u);
v8f c;
[unroll] for(uint i=0;i<8u;++i) c.v[i]=wg_ldf(dst,2048u+(i*32u+lane)*4u);
v8f h=wg_wmma_f16(a16,b16,c);
v8f q=wg_wmma_fp8(a8,b8,c);
[unroll] for(uint k=0;k<8u;++k) {
wg_stf(dst,(k*32u+lane)*4u,h.v[k]);
wg_stf(dst,1024u+(k*32u+lane)*4u,q.v[k]);
Expand Down
84 changes: 84 additions & 0 deletions clean/dx12/tests/native_probe_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: MIT
// The driver-channel probe (runtime/wmma_probe.h) on the GPU, through the runtime's own borrowed-device path: creates a
// D3D12 device and DIRECT queue on the first supported RX 9070 / 9060 adapter and hands them to
// wgrt::make_d3d12_device_on, which runs native_driver_probe at create. WrongGPU's own code. No HIP runtime, no model.
// native_probe_test.exe <build dir holding dx12\manifest.json with native_driver_probe>
// Build (the HIP SDK's clang++ as a host compiler only, as native_direct_build.py does):
// clang++ -std=c++17 -O2 -D_CRT_SECURE_NO_WARNINGS -DWG_NO_MODEL_K -fms-runtime-lib=static native_probe_test.cpp
// ../../runtime/{device,device_dx12,device_d3d12,embedded,model,no_model_k,runtime}.cpp
// ../../runtime/interop/{convert,native_candidate}.cpp ../../converter/src/{json,sha256}.cpp -o native_probe_test.exe
// With WG_TEST_DRIVER_PROBE_FAIL=1 the create must fail with "probe mismatch at float 7". Exit status 0 on PASS.
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <d3d12.h>
#include <dxgi1_4.h>

#include <cstdio>
#include <string>

#include "../../runtime/device_d3d12.h"
#include "../../runtime/rdna4.h"

int main(int argc, char** argv) {
if (argc != 2) {
std::fprintf(stderr, "usage: native_probe_test.exe <build dir>\n");
return 2;
}
HMODULE dxgi = LoadLibraryExW(L"dxgi.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
HMODULE d3d12 = LoadLibraryExW(L"d3d12.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (!dxgi || !d3d12) { std::printf("FAIL system DXGI / D3D12 unavailable\n"); return 1; }
using Factory = HRESULT(WINAPI*)(REFIID, void**);
using Create = HRESULT(WINAPI*)(IUnknown*, D3D_FEATURE_LEVEL, REFIID, void**);
auto factory_fn = reinterpret_cast<Factory>(GetProcAddress(dxgi, "CreateDXGIFactory1"));
auto create = reinterpret_cast<Create>(GetProcAddress(d3d12, "D3D12CreateDevice"));
IDXGIFactory4* factory = nullptr;
if (!factory_fn || !create || FAILED(factory_fn(__uuidof(IDXGIFactory4), reinterpret_cast<void**>(&factory)))) {
std::printf("FAIL DXGI factory\n");
return 1;
}
IDXGIAdapter1* adapter = nullptr;
std::string name;
for (UINT i = 0;; ++i) {
IDXGIAdapter1* a = nullptr;
if (factory->EnumAdapters1(i, &a) == DXGI_ERROR_NOT_FOUND) break;
DXGI_ADAPTER_DESC1 desc{};
char n[256] = {};
if (SUCCEEDED(a->GetDesc1(&desc))) WideCharToMultiByte(CP_UTF8, 0, desc.Description, -1, n, sizeof n - 1, nullptr, nullptr);
if (wgrt::rdna4_adapter(desc.VendorId, (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0, n)) {
adapter = a;
name = n;
break;
}
a->Release();
}
factory->Release();
if (!adapter) { std::printf("SKIP no Radeon RX 9070 / 9060 adapter\n"); return 1; }
ID3D12Device* device = nullptr;
ID3D12CommandQueue* queue = nullptr;
HRESULT h = create(adapter, D3D_FEATURE_LEVEL_12_0, __uuidof(ID3D12Device), reinterpret_cast<void**>(&device));
adapter->Release();
if (FAILED(h)) { std::printf("FAIL D3D12CreateDevice on %s\n", name.c_str()); return 1; }
D3D12_COMMAND_QUEUE_DESC qd{};
qd.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
if (FAILED(device->CreateCommandQueue(&qd, __uuidof(ID3D12CommandQueue), reinterpret_cast<void**>(&queue)))) {
std::printf("FAIL CreateCommandQueue\n");
device->Release();
return 1;
}
std::printf("adapter %s\n", name.c_str());
std::string err;
int status = 1;
{
auto dev = wgrt::make_d3d12_device_on(device, queue, argv[1], &err, 64ull << 20);
if (dev) {
std::printf("PASS borrowed device created, driver-channel probe passed: %s\n", dev->name().c_str());
status = 0;
} else {
std::printf("FAIL %s\n", err.c_str());
}
}
queue->Release();
device->Release();
return status;
}
17 changes: 9 additions & 8 deletions clean/runtime/device_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "native_direct_pi.h"
#include "embedded.h"
#include "rdna4.h"
#include "wmma_probe.h"

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -1337,20 +1338,20 @@ class NativeD3D12Device final : public Device, public NativeD3D12Ext {
probe->second.block != 32 || probe->second.wave != 32 || probe->second.dwords != 1 ||
probe->second.args.size() != 1 || probe->second.args[0].kind != 'p')
return fail("native D3D12 borrowed device requires native_driver_probe (co=-, buffer, block/wave=32, args=p)");
// Operands with distinct values per lane and element, expected results computed on the CPU (wmma_probe.h).
DevPtr output = 0;
if (!alloc(&output, 512 * sizeof(float))) return false;
float values[512] = {};
if (!alloc(&output, wmma_probe::kBytes)) return false;
uint8_t buffer[wmma_probe::kBytes];
wmma_probe::fill(buffer);
float values[wmma_probe::kResults] = {};
void* args[] = {&output};
bool ok = upload(output, values, sizeof values) && launch("native_driver_probe", 1, 32, args) &&
bool ok = upload(output, buffer, sizeof buffer) && launch("native_driver_probe", 1, 32, args) &&
download(values, output, sizeof values);
// tests of the fallback (interop test, WG_TEST_DRIVER_PROBE_FAIL=1): the probe reports a mismatch
const char* fail_test = std::getenv("WG_TEST_DRIVER_PROBE_FAIL");
if (ok && fail_test && fail_test[0] == '1') values[7] = -1.0f;
if (ok) for (unsigned i = 0; i < 512; ++i) {
if (values[i] != static_cast<float>(32 + (i % 32))) {
ok = fail("native D3D12 borrowed driver-channel probe mismatch at float " + std::to_string(i)); break;
}
}
const int bad = ok ? wmma_probe::first_mismatch(values) : -1;
if (bad >= 0) ok = fail("native D3D12 borrowed driver-channel probe mismatch at float " + std::to_string(bad));
const std::string error = err_;
free(output);
if (!ok) err_ = error;
Expand Down
Loading
Loading