Repository navigation
Conversation
Assisted-by: Codex
Contributor
Author
|
@lhez, could you take a look at the changes when you have a chance? |
Contributor
Author
|
@max-krasnyansky, could you take a look at the changes when you have a chance? |
This was referenced Sep 13, 2026
lhez
reviewed
Sep 21, 2026
|
|
||
| int subgraph_uses = 0; | ||
| for (int j = i + 1; j < count; ++j) { | ||
| for (int j = i; j < count; ++j) { |
Contributor
There was a problem hiding this comment.
Could you add a comment why this is necessary?
Comment on lines
+8101
to
+8106
| if (out->op != GGML_OP_RESHAPE || out->src[0]->op != GGML_OP_ADD || out->ne[0] % 2 != 0) { return nullptr; } | ||
| const auto * add = out->src[0]; | ||
| const int64_t d = out->ne[0], l = out->ne[1], heads = out->ne[2] * out->ne[3]; | ||
| const int64_t rotated_shape[] = {2, d / 2, l, heads}, pe_shape[] = {2, 2, d / 2, l}; | ||
| const int32_t split_axes[] = {3, 0, 1, 2}, head_axes[] = {0, 2, 1, 3}; | ||
| if (memcmp(add->ne, rotated_shape, sizeof(rotated_shape)) != 0) { return nullptr; } |
Contributor
There was a problem hiding this comment.
These are bit difficult to read for human. Can you put each decl in its own line and don't use one liners for if?
|
|
||
| static void ggml_opencl_op_qkv_preprocess(ggml_backend_t backend, const ggml_opencl_qkv_preprocess & match); | ||
|
|
||
| static const ggml_tensor * ggml_opencl_match_qkv_rope(const ggml_tensor * out, const ggml_tensor * & pe, |
Contributor
There was a problem hiding this comment.
Since this fusion is for DiT, maybe we should call these functions and kernel ggml_opencl_match_dit_qkv_rope, ggml_opencl_op_dit_qkv_preprocess, kernel_fused_dit_qknorm_rope_f32?
Contributor
|
@happyyzy the commit in the PR says |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fuses Q/K RMSNorm + RoPE, K/V scaling, and V materialization in OpenCL. Also fixes CAST self-reference counting in the shared fusion checker.
Tested on Adreno 830; stable-diffusion.cpp
e31a86ce9110b11a98bd5990c329093244c2d1e3.Performance
Profiling was OFF for the first three baselines, ON for Z-Image 1024 and all after-runs; the first three rows are not profiling-controlled comparisons. Kernel times exclude readback; sampling times exclude VAE decode.
Kernel Bandwidth
D=128, batch 1. Effective bandwidth = useful tensor bytes / mean GPU event time; utilization is relative to Snapdragon 8 Elite's 84.8 GB/s RAM peak.Images
Z-Image 1K images above use
GGML_OPENCL_PROFILING=ON; OFF produced corrupted output. This unexpected issue remains unresolved. And the klein baseline image also shows the same corrupt mode, where the sum of weights and activations is near to 8GB. This commit does not enable profiling or change its default.Commands
Build with
GGML_OPENCL_USE_ADRENO_KERNELS=ON.Klein 512
./sd-cli --diffusion-model models/flux-2-klein-4b-Q4_0.gguf --llm models/qwen_3_4b-Q4_0.gguf --vae models/flux2-vae.safetensors -p 'a lovely cat' --cfg-scale 1 --guidance 3.5 --steps 4 --seed 42 -W 512 -H 512 --diffusion-fa --vae-conv-direct -t 4 -v -o klein_512.pngKlein 1024
./sd-cli --diffusion-model models/flux-2-klein-4b-Q4_0.gguf --llm models/qwen_3_4b-Q4_0.gguf --vae models/flux2-vae.safetensors -p 'a lovely cat' --cfg-scale 1 --guidance 3.5 --steps 4 --seed 42 -W 1024 -H 1024 --diffusion-fa --vae-conv-direct -t 4 -v -o klein_1024.pngZ-Image 512
./sd-cli --diffusion-model models/z_image_turbo-Q4_0-nobf16.gguf --llm models/qwen_3_4b-Q4_0.gguf --vae models/ae_old.safetensors -p 'a lovely cat wearing black sunglasses, studio photo' --cfg-scale 1 --guidance 3.5 --steps 8 --seed 42 -W 512 -H 512 --diffusion-fa --vae-conv-direct -t 4 -v -o zimage_512.pngZ-Image 1024
./sd-cli --diffusion-model models/z_image_turbo-Q4_0-nobf16.gguf --llm models/qwen_3_4b-Q4_0.gguf --vae models/ae_old.safetensors -p 'a lovely cat wearing black sunglasses, studio photo' --cfg-scale 1 --guidance 3.5 --steps 8 --seed 42 -W 1024 -H 1024 --diffusion-fa --vae-conv-direct -t 4 -v -o zimage_1024.pngAfter this PR,adreno 830 runs DITs like z-image and flux klein with throughout about 2Tflops, which means an amazing MFU about 1/3 on a phone! A perfetto timeline for one transformer block of z-image is as follows:

Requirements