Skip to content

refactor kernel bind way#2377

Merged
valarLip merged 2 commits intomainfrom
bind_kl_by_new_way
Mar 20, 2026
Merged

refactor kernel bind way#2377
valarLip merged 2 commits intomainfrom
bind_kl_by_new_way

Conversation

@amd-ruitang3
Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

@amd-ruitang3 amd-ruitang3 requested review from a team and Copilot March 20, 2026 06:57
@github-actions
Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:sglang SGLang integration tests
ci:atom ATOM benchmark (DeepSeek-R1 + GPT-OSS)
ci:vllm vLLM benchmark
ci:all All of the above

Add labels via the sidebar or gh pr edit 2377 --add-label <label>

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors device selection in several HIP-based asm kernel entrypoints by replacing manual hipGetDevice/hipSetDevice pairs with an RAII-style guard, aiming to make device switching exception/early-return safe and reduce repeated boilerplate.

Changes:

  • Introduces HipDeviceGuard in aiter_hip_common.h to restore the previous HIP device on scope exit.
  • Updates MLA, LayerNorm, and GEMM asm wrappers to use HipDeviceGuard instead of manual device save/restore code.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
csrc/py_itfs_cu/asm_mla.cu Replaces manual device save/set/restore with HipDeviceGuard in MLA decode/prefill entrypoints.
csrc/py_itfs_cu/asm_layernorm.cu Uses HipDeviceGuard for LayerNorm asm wrappers instead of explicit hipSetDevice calls.
csrc/py_itfs_cu/asm_gemm_a16w16.cu Uses HipDeviceGuard in GEMM asm wrapper to manage HIP device selection.
csrc/include/aiter_hip_common.h Adds HipDeviceGuard RAII helper for HIP device switching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread csrc/include/aiter_hip_common.h Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@amd-ruitang3 amd-ruitang3 changed the title refactor kernel refactor kernel bind way Mar 20, 2026
@valarLip valarLip merged commit e4bdc3f into main Mar 20, 2026
25 checks passed
@valarLip valarLip deleted the bind_kl_by_new_way branch March 20, 2026 15:14
zufayu pushed a commit that referenced this pull request Mar 23, 2026
Address review comment from amd-ruitang3: the pybind->ctypes migration
removed device_guard. Now that PR #2377 has merged, use the new
HipDeviceGuard in all 8 extern "C" fmoe/moe_stage functions.
zufayu pushed a commit that referenced this pull request Mar 23, 2026
Address review comment from amd-ruitang3: the pybind->ctypes migration
removed device_guard. Now that PR #2377 has merged, use the new
HipDeviceGuard in all 8 extern "C" fmoe/moe_stage functions.
zufayu pushed a commit that referenced this pull request Mar 23, 2026
Address review comment from amd-ruitang3: the pybind->ctypes migration
removed device_guard. Now that PR #2377 has merged, use the new
HipDeviceGuard in all 8 extern "C" fmoe/moe_stage functions.
zufayu added a commit that referenced this pull request Mar 23, 2026
* Migrate MoE ASM kernels from pybind to C ABI + ctypes

Convert fmoe, fmoe_int8_g1u0, fmoe_g1u1, fmoe_g1u1_tkw1,
fmoe_int8_g1u0_a16, fmoe_g1u1_a16, fmoe_fp8_blockscale_g1u1,
and moe_stage1_g1u1 from torch::Tensor& (pybind11) to
AiterTensor* + hipStream_t (C ABI called via ctypes).

- asm_fmoe.cu: Remove torch/ATen includes, use AiterTensor*,
  AITER_DTYPE_*, AITER_CHECK; template <int I_elemSize, int O_elemSize>
- asm_moe_2stage.cu: Same conversion for moe_stage1_g1u1
- moe_op.h: Remove fmoe pybind declarations (now extern "C")
- rocm_ops.hpp: Remove fmoe entries from MOE_OP_PYBIND macro
- moe_op.py: Use ffi_type="ctypes" with new module_moe_fmoe_asm
- optCompilerConfig.json: Split ctypes sources into module_moe_fmoe_asm

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add missing #include <memory> for std::unique_ptr/make_unique

After pip install -e . refreshed aiter_meta from csrc/, the indirect
include chain changed and <memory> was no longer transitively included.

* fix: address Copilot review comments

- kernelName: str -> Optional[str] for correct ctypes c_char_p conversion
- Remove extra activation param from fmoe_int8_g1u0_a16 (C ABI has no such param)
- Fix typo "supput" -> "support" in asm_fmoe.cu

* fix: add HipDeviceGuard to all C ABI MoE kernel functions

Address review comment from amd-ruitang3: the pybind->ctypes migration
removed device_guard. Now that PR #2377 has merged, use the new
HipDeviceGuard in all 8 extern "C" fmoe/moe_stage functions.

* fix: restore activation parameter in fmoe_int8_g1u0_a16 C ABI

The activation parameter was dropped during pybind-to-ctypes migration.
The original implementation uses it to select between silu/gelu config
maps. Restore it in C ABI signature, Python ctypes declaration, and
call site.

* fix: remove stale topk_softmax_asm pybind declaration from moe_op.h

This declaration was erroneously re-added during rebase conflict
resolution. PR #2327 already removed it when migrating to ctypes.

---------

Co-authored-by: root <root@hjbog-srdc-39.amd.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants