Skip to content

vulkan : added the PAD_REFLECT_1D operation - #26586

Merged
jeffbolznv merged 2 commits into
ggml-org:masterfrom
safiullah3915:vulkan/pad-reflect-1d
Aug 22, 2026
Merged

vulkan : added the PAD_REFLECT_1D operation#26586
jeffbolznv merged 2 commits into
ggml-org:masterfrom
safiullah3915:vulkan/pad-reflect-1d

Conversation

@safiullah3915

@safiullah3915 safiullah3915 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

###Overview

In this PR, I have implemented the missing GGML_OP_PAD_REFLECT_1D operation for the Vulkan backend (Issue #14909).

The operation implemented applies 1D reflected padding along dimension 0 of tensor.

###Key Changes:

  • Added GLSL compute shader named as pad_reflect_1d.comp under the vulkan-shaders folder by implementing the reflection arithmetic
  • Registered shader in vulkan-shaders-gen.cpp for SPIR-V compilation
  • Integrated pipeline, creation supports_op, dispatch logic and debug validation in code file of ggml-vulkan.cpp

###Test Results

I have tested this on Intel Iris Xe Graphics (TGL GT2) running Vulkan 1.4 / Mesa 25.2.8.

###Correctness (executed this command of test-backend-ops -o PAD_REFLECT_1D):

  • PAD_REFLECT_1D(type=f32,ne_a=[512,34,2,1],pad_0=10,pad_1=9) = OK
  • PAD_REFLECT_1D(type=f32,ne_a=[3000,384,4,1],pad_0=10,pad_1=9) = OK
  • all tests are passed

###Performance (executed this command of test-backend-ops perf -o PAD_REFLECT_1D):
[512,34,2,1] = 9.54 us/run (13.85 GB/s)
[3000,80,1,1] = 52.79 us/run (33.98 GB/s)
[3000,384,4,1] = 286.20 us/run (30.09 GB/s)

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - I have used AI for understanding the code and also the flow of data from initial stage to last stage where data is given to GPU. Then I have also understood the syntax like how to write shaders by studying the pad shader. Rest I write the logic myself and fully understand all code submitted and can explain this all without any help of AI.

###Changes After Review (requested by jeffbolznv)

- I have replaced custom push_constant block with generic_unary_head.glsl 
so this shader shares the standard unary push constants layout

- I have replaced plain integer division with fastdiv for computing tensor 
coordinates from the flat thread index

- I have added destination stride support (nb10..nb13) so noncontiguous 
destination tensors are handled correctly

@safiullah3915
safiullah3915 requested a review from a team as a code owner August 4, 2026 15:38
@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Aug 4, 2026
Comment thread ggml/src/ggml-vulkan/vulkan-shaders/pad_reflect_1d.comp Outdated
Comment thread ggml/src/ggml-vulkan/vulkan-shaders/pad_reflect_1d.comp Outdated
Comment thread ggml/src/ggml-vulkan/vulkan-shaders/pad_reflect_1d.comp Outdated

@jeffbolznv jeffbolznv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally looks good, just a couple whitespace cleanups needed.

Comment thread ggml/src/ggml-vulkan/ggml-vulkan.cpp Outdated
Comment thread ggml/src/ggml-vulkan/vulkan-shaders/pad_reflect_1d.comp
Comment thread ggml/src/ggml-vulkan/ggml-vulkan.cpp Outdated
@safiullah3915

Copy link
Copy Markdown
Contributor Author

Hi @0cc4m, would you be able to take a look at this PR when you have a chance? The changes are related to the Vulkan backend and I’d really appreciate a second review from someone familiar with that area. Thank you !!!

@0cc4m 0cc4m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Sorry about the delay, I was on vacation.

@0cc4m

0cc4m commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Please fix the editorconfig issue. After that this can be merged.

Implemented the GGML_OP_PAD_REFLECT_1D operation for the Vulkan backend

Changes:
- pad_reflect_1d.comp: implemented the GLSL compute shader with reflection logic
- vulkan-shaders-gen.cpp: register the shader for SPIR-V compilation
- ggml-vulkan.cpp: pushed constants struct, pipeline creation,
  supports_op, dispatch function, compute switch and debug validation

Tested the PAD_REFLECT_1D on Intel Iris Xe (Vulkan 1.4, Mesa 25.2.8):

Correctness:
  PAD_REFLECT_1D(type=f32,ne_a=[512,34,2,1],pad_0=10,pad_1=9) = Pass
  PAD_REFLECT_1D(type=f32,ne_a=[3000,384,4,1],pad_0=10,pad_1=9) = Pass
  2/2 tests passed
 - All test are passed

Performance:
  ne_a=[512,34,2,1] -> 5.38 us/run, 24.55 GB/s
  ne_a=[3000,80,1,1] -> 30.09 us/run, 59.62 GB/s
  ne_a=[3000,384,4,1] -> 158.31 us/run, 54.39 GB/s
@safiullah3915
safiullah3915 force-pushed the vulkan/pad-reflect-1d branch from 4b8a44d to acf6d1d Compare August 19, 2026 17:09
@safiullah3915

Copy link
Copy Markdown
Contributor Author

Please fix the editorconfig issue. After that this can be merged.

Fixed the editorconfig issue. There was trailing whitespace on blank line inside pad_reflect_1d.comp. Removed it and pushed the update.

@safiullah3915

Copy link
Copy Markdown
Contributor Author

Hi @0cc4m and @jeffbolznv

All items and feedback on this PR have been fully resolved. Could you please review and merge this when you have a moment? Thank you!!


// copy the computed value to the destination tensor
data_d[get_doffset() + d_idx] = D_TYPE(data_a[get_aoffset() + src_idx]);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
@jeffbolznv
jeffbolznv merged commit 3f545be into ggml-org:master Aug 22, 2026
27 of 29 checks passed
@nikwen

nikwen commented Aug 23, 2026

Copy link
Copy Markdown
Member

It seems like this PR broke something. Would you be able to take a look? #27576

@jeffbolznv

Copy link
Copy Markdown
Contributor

It seems very unlikely that this change could break something that's not using pad_reflect_1d.

@nikwen

nikwen commented Aug 23, 2026

Copy link
Copy Markdown
Member

Good point. Let's narrow down the commit range further: #27576 (comment)

@nikwen

nikwen commented Aug 24, 2026

Copy link
Copy Markdown
Member

Seems like it was unrelated to this PR. The user reports that it works now. Thanks for taking a look!

fewtarius added a commit to fewtarius/CachyLLama that referenced this pull request Aug 24, 2026
Brings 218 upstream commits into CachyLLama without losing any of our
features. Key carried-over changes from upstream:
- llama.cpp v0.2.0 / ggml v0.21.0 version bumps
- Vulkan FA MMQ fp32 scaling (ggml-org#27413), PAD_REFLECT_1D (ggml-org#26586), tiled
  transpose (ggml-org#26585), null checks in queue command pools cleanup (ggml-org#27353)
- ggml: rope_set_offset on multiple backends, recurrent state rollback
- Vulkan coopmat1 SHMEM_STRIDE_PAD/APPLY_SLM_A_RESHAPE for Intel Xe
- server: LLAMA_SERVER_SLOTS_N_DIFF (ggml-org#27600), /metrics during llama_decode
  (ggml-org#27041), index.html no-cache (ggml-org#27006), make-release workflow
- model: MiniMax-M1/Text01 (ggml-org#27018), Kimi-K3 (ggml-org#26185), BailingMoE3 (ggml-org#26608),
  GraniteSWA (ggml-org#25505), GLM-4.5-Air MTP, DSV4 tensor split (-sm tensor)
- ui: Chat Conversation Tabbed navigation, settings refactor
- common: --models-dir loading MTP assistant models (ggml-org#24431),
  --load-mode replacing --mmap (ggml-org#26934), json.h abstraction (ggml-org#27511)
- vendor: cpp-httplib 0.53.1, BoringSSL 0.20260813.0, vendor/hash

CachyLLama features preserved through conflict resolution:
- Persistent SSD-backed KV cache (3-tier hot/warm/cold + system prompt cache)
- Per-user isolation (user_id, per-user concurrency cap, slot affinity)
- MoE expert residency + co-activation tracking
- CachyLLama Vulkan Lightning Indexer (108/108 on Strix Halo) + DSV4
  hyper-connection fused ops + DSV4 sparse FA + coopmat shaders
- FA quant-KV dequant-once + f16 contiguize (with host-RAM safety gate)
- DFlash framework + Laguna-S-2.1 model support
- DFlash d2t reduced-vocab draft support (upstream merge)
- Context checkpoint ring buffer + SWA skip + memory budget scaling
- Stable-prefix LCP gate + prompt_stable_prefix_tokens param
- conv_hash conversation-boundary detection
- All CachyLLama Vulkan shaders (concat_transpose, lightning_indexer,
  mmid_row_lists, flash_attn_top_k, dequant_f16_transpose)
- common::host_available_ram() utility
- llama-moe-residency + llama-moe-coact modules

Manual conflict resolution touches: src/models/dflash.cpp (DFlash d2t +
aux_norm), src/llama-kv-cache-dsv4.cpp (state snapshot fix), src/llama-
memory-recurrent.cpp (rs_idx bounds check), src/llama-model-saver.cpp
(DSV4 compress_ratios + swiglu_clamp sizing), ggml/src/ggml-vulkan/
{ggml-vulkan.cpp,vulkan-shaders-gen.cpp,vulkan-shaders/dequant_q8_0.
comp,vulkan-shaders/flash_attn.comp,vulkan-shaders/copy_transpose_02.
comp} (CachyLLama shader registration + FA scratch gate), ggml/src/
ggml-cuda/mmvq.cu (RDNA3_5 + GB10 enum), gguf-py/gguf/constants.py
(DFlash ENC_AUX_NORM + D2T tensors), tests/{CMakeLists.txt,test-backend-
ops.cpp,test-llama-archs.cpp,test-recurrent-state-rollback.cpp}
(test additions), tools/{CMakeLists.txt,server/*} (server_batch embd
support + spec_is_replay + user_id routing + MCP servers + CORS), and
docs/{AGENTS.md,README.md} (kept CachyLLama branding).

Verified: full build succeeds, test-backend-ops Vulkan LIGHTNING_INDEXER +
FLASH_ATTN pass on Strix Halo.

Based on a re-merge from the 20260824 (pristine pre-merge) branch after
a previous agent's merge attempt produced an unbuildable state from
-X ours that wiped shader float-typing and broke the dequant_q8_0 +
flash_attn shaders with redefinition errors.
therealkenc pushed a commit to therealkenc/llama.cpp that referenced this pull request Aug 24, 2026
* vulkan : added PAD_REFLECT_1D operation

Implemented the GGML_OP_PAD_REFLECT_1D operation for the Vulkan backend

Changes:
- pad_reflect_1d.comp: implemented the GLSL compute shader with reflection logic
- vulkan-shaders-gen.cpp: register the shader for SPIR-V compilation
- ggml-vulkan.cpp: pushed constants struct, pipeline creation,
  supports_op, dispatch function, compute switch and debug validation

Tested the PAD_REFLECT_1D on Intel Iris Xe (Vulkan 1.4, Mesa 25.2.8):

Correctness:
  PAD_REFLECT_1D(type=f32,ne_a=[512,34,2,1],pad_0=10,pad_1=9) = Pass
  PAD_REFLECT_1D(type=f32,ne_a=[3000,384,4,1],pad_0=10,pad_1=9) = Pass
  2/2 tests passed
 - All test are passed

Performance:
  ne_a=[512,34,2,1] -> 5.38 us/run, 24.55 GB/s
  ne_a=[3000,80,1,1] -> 30.09 us/run, 59.62 GB/s
  ne_a=[3000,384,4,1] -> 158.31 us/run, 54.39 GB/s

* Update ggml/src/ggml-vulkan/vulkan-shaders/pad_reflect_1d.comp

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>

---------

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
safiullah3915 added a commit to safiullah3915/safiullah3915.github.io that referenced this pull request Aug 26, 2026
- Added 'Open Source Contributions' section after About, visible near top
- Styled dark contribution card with Merged/Vulkan/C++ badges
- Links to merged PR: ggml-org/llama.cpp#26586 (PAD_REFLECT_1D Vulkan op)
- Added 'Open Source' nav link to sticky navigation bar
ravel7524 pushed a commit to ravel7524/llama.cpp that referenced this pull request Aug 30, 2026
* vulkan : added PAD_REFLECT_1D operation

Implemented the GGML_OP_PAD_REFLECT_1D operation for the Vulkan backend

Changes:
- pad_reflect_1d.comp: implemented the GLSL compute shader with reflection logic
- vulkan-shaders-gen.cpp: register the shader for SPIR-V compilation
- ggml-vulkan.cpp: pushed constants struct, pipeline creation,
  supports_op, dispatch function, compute switch and debug validation

Tested the PAD_REFLECT_1D on Intel Iris Xe (Vulkan 1.4, Mesa 25.2.8):

Correctness:
  PAD_REFLECT_1D(type=f32,ne_a=[512,34,2,1],pad_0=10,pad_1=9) = Pass
  PAD_REFLECT_1D(type=f32,ne_a=[3000,384,4,1],pad_0=10,pad_1=9) = Pass
  2/2 tests passed
 - All test are passed

Performance:
  ne_a=[512,34,2,1] -> 5.38 us/run, 24.55 GB/s
  ne_a=[3000,80,1,1] -> 30.09 us/run, 59.62 GB/s
  ne_a=[3000,384,4,1] -> 158.31 us/run, 54.39 GB/s

* Update ggml/src/ggml-vulkan/vulkan-shaders/pad_reflect_1d.comp

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>

---------

Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants