[Hardware][Power]Add Power VSX Attention Backend and fix l2 Cache Crash - #40451
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces VSX (PowerPC) support for the CPU attention backend, including a dedicated VSX implementation for attention kernels and updates to the dispatch and architecture detection logic. Critical issues were identified in the new VSX implementation, including a vector merging bug on little-endian systems and incorrect pointer arithmetic when handling 16-bit types. Furthermore, there are opportunities to optimize performance by vectorizing the half-precision loading logic and to improve the robustness of the L2 cache size detection globally to prevent potential crashes.
| if constexpr (is_bf16) { | ||
| __vector float v0, v1; | ||
| load_row8_B_as_f32<scalar_t>(curr_src + d, v0, v1); | ||
|
|
||
| v0 = vec_mul(v0, scale_vec); | ||
| v1 = vec_mul(v1, scale_vec); | ||
|
|
||
| vec_xst(v0, 0, curr_dst + d); | ||
| vec_xst(v1, 0, curr_dst + d + 4); | ||
| } else { | ||
| __vector float v0 = vec_xl(0, (float*)curr_src + d); | ||
| __vector float v1 = vec_xl(0, (float*)curr_src + d + 4); | ||
|
|
||
| v0 = vec_mul(v0, scale_vec); | ||
| v1 = vec_mul(v1, scale_vec); | ||
|
|
||
| vec_xst(v0, 0, curr_dst + d); | ||
| vec_xst(v1, 0, curr_dst + d + 4); | ||
| } |
There was a problem hiding this comment.
The else block in copy_q_heads_tile contains a critical bug when scalar_t is c10::Half. The pointer arithmetic (float*)curr_src + d incorrectly increments the address by d * sizeof(float) instead of d * sizeof(scalar_t). Additionally, it loads data using vec_xl and treats it as float without proper conversion, which is invalid for 16-bit types. Since load_row8_B_as_f32 is already specialized to handle float, BFloat16, and Half correctly, it should be used here to fix the bug and simplify the implementation.
__vector float v0, v1;
load_row8_B_as_f32<scalar_t>(curr_src + d, v0, v1);
v0 = vec_mul(v0, scale_vec);
v1 = vec_mul(v1, scale_vec);
vec_xst(v0, 0, curr_dst + d);
vec_xst(v1, 0, curr_dst + d + 4);| FORCE_INLINE void load_row8_B_as_f32<c10::Half>(const c10::Half* p, | ||
| __vector float& b0, | ||
| __vector float& b1) { | ||
| alignas(16) float tmp[8]; | ||
|
|
||
| tmp[0] = static_cast<float>(p[0]); | ||
| tmp[1] = static_cast<float>(p[1]); | ||
| tmp[2] = static_cast<float>(p[2]); | ||
| tmp[3] = static_cast<float>(p[3]); | ||
| tmp[4] = static_cast<float>(p[4]); | ||
| tmp[5] = static_cast<float>(p[5]); | ||
| tmp[6] = static_cast<float>(p[6]); | ||
| tmp[7] = static_cast<float>(p[7]); | ||
|
|
||
| b0 = vec_xl(0, (float*)tmp); | ||
| b1 = vec_xl(0, (float*)(tmp + 4)); | ||
| } |
There was a problem hiding this comment.
The load_row8_B_as_f32 specialization for c10::Half uses a scalar loop for half-to-float conversion. This function is called within the inner loop of the attention micro-kernel (gemm_micro_ppc64le_Mx8_Ku4), making this a significant performance bottleneck for FP16 models. For Power9 and newer architectures, you should use the xvcvhpsp intrinsic for vectorized conversion. Even for older architectures, bitwise vector operations can be used to perform this conversion more efficiently than the current scalar fallback.
|
Hi @bigPYJ1151 , can you please take a look at the changes ? |
|
Hi @bigPYJ1151 , Can you please take a look at the changes made in this PR ? |
|
Hi @bigPYJ1151 , Any update on this PR on when this can be reviewed ? |
|
Hi @Akashcodes732 Please reslove the conflicts. |
Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com>
Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com>
Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com>
Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com>
Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com>
02051c0 to
397a9e7
Compare
|
Hi @Akashcodes732, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, Tip Is
|
Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com>
|
Hi @Akashcodes732, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, Tip Is
|
Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com>
Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com>
|
Hi @bigPYJ1151 , the failures look unrelated |
|
Hi @bigPYJ1151 , can we merge this ? |
|
Hi @DarkLight1337 @mgoin , The changes are approved and the failures look unrelated. Can we merge this PR ? |
|
Done |
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com> Co-authored-by: hongbolv <33214277+hongbolv@users.noreply.github.com>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com> Signed-off-by: Ifta Khairul Alam Adil <ikaadil007@gmail.com>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com> Signed-off-by: Libin Tang <libin.tang@intel.com>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com> Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Cherry-pick 12 runner/worker/compilation PRs from upstream vllm-project/vllm main. Applied (12): vllm-project#40451 [Hardware][Power] Add Power VSX Attention Backend vllm-project#35520 [Model Runner V2] support qwen35 / mamba hybrid model vllm-project#41882 Add NVFP4 all-gather GEMM fusion for AsyncTP vllm-project#40392 [Performance][DSR1]: Fused RoPE+KVCache+q_concat for MLA vllm-project#40082 Integrate flashinfer b12x MoE and FP4 GEMM kernels for SM120 vllm-project#43746 [Model Refactoring] Remove torch compile dependency in DSv4 vllm-project#41714 [MM][CG] Profile encoder CUDA graph pool memory vllm-project#40470 [Attention] Extract KV-cache update from CPU attention backend vllm-project#45163 [Model] Add DiffusionGemma Support (partial, vllm-hust compat) vllm-project#45473 [Kernel] Support DS Mamba tail copy for MTP align mode vllm-project#45868 [ModelRunnerV2] Various model/config compatibility fixes vllm-project#44635 Speed up docs build Skipped (4, ROCm/XPU/hardware-specific): vllm-project#41972 [ROCm] Fix AITER AR+RMSNorm vllm-project#41771 [XPU] keep generator state vllm-project#43016 [ROCm][CI] Stabilize 400 error vllm-project#42604 DeepSeekV4-Pro ROCm sparse Test: scheduler 107/107 passed Co-authored-by: GitHub Copilot Signed-off-by: MingqiWang-coder <mingqiwang@hust.edu.cn>
…sh (vllm-project#40451) Signed-off-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Signed-off-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Signed-off-by: Akash kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Akash Kaothalkar <akashkaothalkar@akashs-mbp.bl1-in.ibm.com> Co-authored-by: Akash Kaothalkar <akash.kaothalkar@ibm.com> Co-authored-by: Li, Jiang <jiang1.li@intel.com>
Purpose
This PR adds native PowerPC (ppc64le) VSX support for the vLLM CPU backend and resolves a initialization crash caused by
IndexError: unordered_map::at.Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.