Commit 723100d
Zheng Te
feat(cgc): add
Ports the standalone `DXML/python/cgc.py` tool into winml-cli as the first
group-style (two-level) command. It answers two questions that come up on every
new machine and after every driver update: which D3D12 adapters are present, and
what patterns does an adapter's driver declare it can match. Both answers come
from public Windows APIs through ctypes, so nothing has to be built.
The argparse layer is replaced by Click and aligned with the sibling command
modules: `cli_utils.verbosity_options()`, `resolve_verbosity()`,
`configure_logging()`, `@click.pass_context`, a module logger, and `ctx.exit()`.
`winml -v cgc adapter` and `winml cgc adapter -v` behave identically, and a bare
`winml cgc` prints help and exits 0, mirroring the root group.
The engine is a faithful port: the dump it produces is byte-identical to the
original script's (same 127117-byte patterns.mlir and same metadata.txt on driver
32.0.16.3004, 51 patterns / 63 rules).
Redist resolution
-----------------
Rewritten to drop the DXML build-tree and NuGet probing, which searched paths
that do not exist once the file lives here. It now reads: --d3d12-dir,
$WINML_D3D12_DIR, $D3D12_DIR, then a `bin` folder under the venv's parent, the
worktree, the installed package, site-packages and the environment prefix, each
probed as `bin/D3D12` then bare `bin`.
An explicitly named redist -- the flag or either variable -- is the answer
whether or not it works. Pointing $WINML_D3D12_DIR at a directory holding no
usable core reports the rejection and exits 1 rather than falling through and
answering about a different runtime, which is the one thing this command must
never do: which Agility core answered decides what every other line means.
--d3d12-dir is consulted first, so it still overrides the variables.
Every candidate is gated on SDK >= 720. An older core does not fail loudly --
it answers E_INVALIDARG for the MLIR feature, which would report a capable
driver as `no` -- so it is skipped rather than used. Measured: through an SDK
614 core an RTX 5060 reads `no`; through SDK 720 the same driver reads `yes`.
`winml/bin/**/*` is declared as package data so a redist vendored at
`src/winml/bin/D3D12/` is carried into the wheel; without it the directory is
not a Python package and never ships. Both drop locations are gitignored so the
multi-MB D3D12Core.dll cannot be committed by accident.
Known limitation, documented in the source and accepted while this is a proof
of concept: the venv-parent root walks up out of the venv, so a venv placed at
a filesystem root makes that root the highest-priority search base.
Tests
-----
120 tests over the parts that need no GPU: the pattern parser and its five-kind
classifier, the PE export reader and redist acceptance including the SDK floor,
candidate generation and ordering, adapter selection and the rendered table, the
flag rules, the dump layout and the metadata writer.
Expectations are computed from generated inputs rather than transcribed from a
run. MLIR sources are assembled from a chosen number of patterns and `any_of`
branches, so the test states the relationship (rules == sum of branches) rather
than a number someone observed once. Redists are synthesized PE32+ images built
around a chosen `D3D12SDKVersion` and read back, which makes the SDK floor, the
architecture check, the missing-export path and the not-a-PE path testable
anywhere, with no Agility SDK present.
61 of the 66 cases from the tool's original standalone suite are carried over,
including its MLIR fixtures, which are shaped like real driver output: a kernel
there carries its jitFunction *inside* a subgraph_rewrite_desc, so it also
matches the fusion marker, and only marker precedence tells the two apart.
Four of the remaining five read an `nv-patterns/` corpus this repository does
not carry -- one exists specifically to fail rather than skip when it is absent,
so porting it would add a permanently red test; they are worth restoring if the
corpus is ever vendored here. The fifth asserts the absence of an `--out` flag
this command never had.
The DXCore and D3D12 exchange paths still need real hardware. The capability
probe is kept and gated on a resolvable redist; it was verified to run and pass
with one present, so the gate is not hiding a broken test.
Claude-Session: https://claude.ai/code/session_01AUbPTmiBrAd6G1MFudgbknwinml cgc adapter to inspect D3D12 adapters and driver patterns1 parent 0091a66 commit 723100d
7 files changed
Lines changed: 3138 additions & 1 deletion
File tree
- docs/commands
- src/winml/modelkit/commands
- tests/unit/commands
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
0 commit comments