Skip to content

hrx: claim a standalone f32 PERMUTE whose result owns its storage (TSPECTREE phase (a)) - #136

Closed
bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/dflash-hrx
Closed

bong-water-water-bong wants to merge 1 commit into
1bit/hrx-vulkan-patchedfrom
1bit/dflash-hrx

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

hrx: claim a standalone f32 PERMUTE whose result owns its storage (TSPECTREE phase (a), item 1)

The DFlash2 drafter's encoder and decoder permute activations between head-major and token-major layouts,
and llama.cpp's graph leaves those as GGML_OP_PERMUTE nodes. Our dispatcher has no registration for
PERMUTE at all, so any permuted value not followed by a CONT is placed on the CPU — one graph split per
draft, on the graph we are about to put on the HRX path.

A permute does not move data: the result is a view whose strides travel with the dims. So the materialised
case (the permuted value owns a contiguous destination buffer) is exactly the strided-source copy that
register_copy_dispatch already performs for CONT, and this reuses the same kernel and parameter set.
Because a permute carries each dimension's stride along with the dimension, the destination's nb[i] is
the source stride to read for destination dim i, so no axes have to be recovered from op_params (which
OpParams does not carry for PERMUTE anyway).

Scope, deliberately narrow:

  • claimed: f32 → f32, output contiguous and packed, same element count and byte count as the source, distinct
    storage, element strides representable, ≤ 2^30 elements;
  • not claimed: the view form (source and output share storage). That value has no destination buffer, so
    the materialisation belongs to the following CONT — which is already lowered through the same kernel — and
    claiming it here would need a copy that writes through a permuted destination layout. That is a
    kernel-side variant, written up in ~/briefs/TSPECTREE-STATE.md under "kernel asks" and handed to
    gpu-kernels rather than done here.

So this fires only where the graph already materialises the permute, and declines everything else to the
existing behaviour (CPU). It is the correct hook point for the kernel-side variant later, and it cannot
change the result of any graph that works today.

Untested on device: the lane belongs to the leaderboard, so this has not been compiled or run yet. Build
check and the drafter measurement are the first things after "lane shared" / "leaderboard done".

🤖 Generated with Claude Code

…PECTREE phase (a), item 1)

The DFlash2 drafter's encoder and decoder permute activations between head-major and token-major layouts,
and llama.cpp's graph leaves those as `GGML_OP_PERMUTE` nodes. Our dispatcher has no registration for
`PERMUTE` at all, so any permuted value not followed by a `CONT` is placed on the CPU — one graph split per
draft, on the graph we are about to put on the HRX path.

A permute does not move data: the result is a view whose strides travel with the dims. So the materialised
case (the permuted value owns a contiguous destination buffer) is exactly the strided-source copy that
`register_copy_dispatch` already performs for `CONT`, and this reuses the same kernel and parameter set.
Because a permute carries each dimension's stride along with the dimension, the destination's `nb[i]` *is*
the source stride to read for destination dim `i`, so no axes have to be recovered from `op_params` (which
`OpParams` does not carry for `PERMUTE` anyway).

Scope, deliberately narrow:

- claimed: f32 → f32, output contiguous and packed, same element count and byte count as the source, distinct
  storage, element strides representable, ≤ 2^30 elements;
- **not** claimed: the view form (source and output share storage). That value has no destination buffer, so
  the materialisation belongs to the following `CONT` — which is already lowered through the same kernel — and
  claiming it here would need a copy that writes through a permuted *destination* layout. That is a
  kernel-side variant, written up in `~/briefs/TSPECTREE-STATE.md` under "kernel asks" and handed to
  gpu-kernels rather than done here.

So this fires only where the graph already materialises the permute, and declines everything else to the
existing behaviour (CPU). It is the correct hook point for the kernel-side variant later, and it cannot
change the result of any graph that works today.

**Untested on device**: the lane belongs to the leaderboard, so this has not been compiled or run yet. Build
check and the drafter measurement are the first things after "lane shared" / "leaderboard done".

🤖 Generated with [Claude Code](https://claude.com/claude-code)
@bong-water-water-bong

Copy link
Copy Markdown
Author

Review (orchestrator): right hook point and correctly narrow (materialised f32 permute only, view form declined to the following CONT, nothing today's graphs do changes). Our code in our own files. Stays a draft until it compiles with GGML_HRX=ON on strixhalo at 'lane shared' and hrx-backend-test passes at 'leaderboard done'; the kernel-side permuted-destination variant goes to gpu-kernels from the state file's 'kernel asks'.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Build check, at the pin (f08bd76f, hrx-system 82804197bc, GGML_HRX=ON, -DGGML_HRX_KERNEL_CORPUS_SOURCE_FORMAT=binary, gfx1151):

[19/28] Building CXX object ggml/src/ggml-hrx/CMakeFiles/ggml-hrx.dir/dispatch_registration/common/dispatch-permute.cpp.o
[20/28] Linking CXX shared library bin/libggml-hrx.so.0.18.0
[24/28] Linking CXX executable bin/test-hrx-ops
[25/28] Linking CXX executable bin/hrx-backend-test

Green, and the new translation unit links into libggml-hrx.so alongside dispatch-common.o, so the registration is compiled in rather than merely referenced. Still untested on device: the permute lowering has not executed a graph, which is the next step once the lane opens.

@bong-water-water-bong

Copy link
Copy Markdown
Author

Superseded: the DFlash2 drafter graph now runs with 0 nodes off HRX under strict placement (fork #139 port + #140, private gpu-kernels #34 for the selector ops: TOP_K, FILL, GET_ROWS, I32 CPY/CONT); its PERMUTE nodes are handled on that path, so the standalone f32 PERMUTE registration is no longer needed for the drafter. Closing; reopen if a model surfaces a standalone PERMUTE that still falls to the CPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant