Repository navigation
[Triton/Gluon] [GFX1250] fused_add_rmsnorm_pad() gluon equivalent function #4146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3cccf6b
added fused_add_rmsnorm_pad() function for GFX1250. Included updates …
amd-jrosas 16a2662
Updated num_warps to be configurable in gluon kernel. Updated API cal…
amd-jrosas 0205eca
Add gluon fused_add_rmsnorm_pad kernel for gfx1250
amd-jrosas 2f641f0
added repr to kernel. Changed num_warps to 8 and reordered kenel for…
amd-jrosas 9a11d98
Add license and copyright notice to fused_add_rmsnorm_pad.py
amd-jrosas 34fb02b
Removed kernel map dictionary. Updated num_warps selection for small …
amd-jrosas eb459f6
Added config and default.json for fused_add_rmsnorm_pad
amd-jrosas b892b90
Updated import path for load_config_json and resolve_config_dir. Upda…
amd-jrosas ed1ee35
Change backend type to allow None value
amd-jrosas 35dc4ec
Added docstring for fused_add_rmsnorm_pad wrapper function.
c8cfba1
Fix typo in docstring for fused_add_rmsnorm_pad
azaidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
aiter/ops/triton/_gluon_kernels/gfx1250/norm/fused_add_rmsnorm_pad.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| # Copyright (C) 2024-2026, Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| import triton | ||
| import triton.language as tl | ||
| from triton.experimental import gluon | ||
| from triton.experimental.gluon import language as gl | ||
|
|
||
| from aiter.ops.triton.utils._triton.kernel_repr import make_kernel_repr | ||
|
Copilot marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| @triton.jit | ||
|
cagrikymk marked this conversation as resolved.
Resolved
|
||
| def _rmsmorm_op(row, weight, n_cols, epsilon): | ||
| row_norm = row * row | ||
| row_norm = tl.sum(row_norm, axis=-1) | ||
| norm_factor = tl.math.rsqrt((row_norm / n_cols) + epsilon) | ||
|
|
||
| rms_norm = row * norm_factor * weight | ||
| return rms_norm | ||
|
amd-jrosas marked this conversation as resolved.
Resolved
amd-jrosas marked this conversation as resolved.
Resolved
|
||
|
|
||
|
|
||
| _gluon_fused_add_rmsnorm_pad_kernel_repr = make_kernel_repr( | ||
| "_gluon_fused_add_rmsnorm_pad_kernel", | ||
| ["BLOCK_SIZE_N", "HAS_RES", "num_warps"], | ||
| ) | ||
|
|
||
|
|
||
| @gluon.jit(repr=_gluon_fused_add_rmsnorm_pad_kernel_repr) | ||
|
cagrikymk marked this conversation as resolved.
Resolved
|
||
| def _gluon_fused_add_rmsnorm_pad_kernel( | ||
| x_ptr, | ||
| res_ptr, | ||
| out_ptr, | ||
| res_out_ptr, | ||
| weight_ptr, | ||
| eps, | ||
| M, | ||
| N, | ||
| N_out, | ||
| x_stride_m, | ||
| x_stride_n, | ||
| res_stride_m, | ||
| res_stride_n, | ||
| out_stride_m, | ||
| out_stride_n, | ||
| res_out_stride_m, | ||
| res_out_stride_n, | ||
| HAS_RES: gl.constexpr, | ||
| BLOCK_SIZE_N: gl.constexpr, | ||
| num_warps: gl.constexpr, | ||
| ): | ||
| start_pid = gl.program_id(0) | ||
| NUM_WARPS: gl.constexpr = gl.num_warps() | ||
| WARP_SIZE: gl.constexpr = 32 | ||
| CTA_NUM_THREADS: gl.constexpr = NUM_WARPS * WARP_SIZE | ||
|
|
||
| # create 1d layout for n_offs | ||
| n_offs_layout: gl.constexpr = gl.BlockedLayout( | ||
| [(BLOCK_SIZE_N + CTA_NUM_THREADS - 1) // CTA_NUM_THREADS], # size per thread | ||
| [WARP_SIZE], # threads per warp | ||
| [NUM_WARPS], # warps per cta | ||
| [0], # order | ||
| ) | ||
|
|
||
| # create shared layouts for x, res, weights, out | ||
| sharedLayout1D: gl.constexpr = gl.SwizzledSharedLayout(1, 1, 1, order=[1, 0]) | ||
|
|
||
| # create tensor descriptors for x, res, weights, out | ||
| x_desc = gl.amd.gfx1250.tdm.make_tensor_descriptor( | ||
| x_ptr, | ||
| [M, N], | ||
| [x_stride_m, x_stride_n], | ||
| [1, BLOCK_SIZE_N], | ||
| sharedLayout1D, | ||
| ) | ||
| weights_desc = gl.amd.gfx1250.tdm.make_tensor_descriptor( | ||
| weight_ptr, | ||
| [1, N], | ||
| [0, 1], | ||
| [1, BLOCK_SIZE_N], | ||
| sharedLayout1D, | ||
| ) | ||
| out_desc = gl.amd.gfx1250.tdm.make_tensor_descriptor( | ||
| out_ptr, | ||
| [M, N_out], | ||
| [out_stride_m, out_stride_n], | ||
| [1, BLOCK_SIZE_N], | ||
| sharedLayout1D, | ||
| ) | ||
|
|
||
| # create tensor descriptors for res, res_out if applicable | ||
| if HAS_RES: | ||
| res_desc = gl.amd.gfx1250.tdm.make_tensor_descriptor( | ||
| res_ptr, | ||
| [M, N], | ||
| [res_stride_m, res_stride_n], | ||
| [1, BLOCK_SIZE_N], | ||
| sharedLayout1D, | ||
| ) | ||
| res_out_desc = gl.amd.gfx1250.tdm.make_tensor_descriptor( | ||
| res_out_ptr, | ||
| [M, N], | ||
| [res_out_stride_m, res_out_stride_n], | ||
| [1, BLOCK_SIZE_N], | ||
| sharedLayout1D, | ||
| ) | ||
|
|
||
| # allocate shared memory for x, weights, out | ||
| smemX = gl.allocate_shared_memory( | ||
| x_ptr.dtype.element_ty, [1, BLOCK_SIZE_N], sharedLayout1D | ||
| ) | ||
| smemWeights = gl.allocate_shared_memory( | ||
| weight_ptr.dtype.element_ty, [1, BLOCK_SIZE_N], sharedLayout1D | ||
| ) | ||
| smemOut = gl.allocate_shared_memory( | ||
| out_ptr.dtype.element_ty, [1, BLOCK_SIZE_N], sharedLayout1D | ||
| ) | ||
|
|
||
| # allocate shared memory for res, res_out if applicable | ||
| if HAS_RES: | ||
| smemRes = gl.allocate_shared_memory( | ||
| res_ptr.dtype.element_ty, [1, BLOCK_SIZE_N], sharedLayout1D | ||
| ) | ||
| smemResOut = gl.allocate_shared_memory( | ||
| res_out_ptr.dtype.element_ty, [1, BLOCK_SIZE_N], sharedLayout1D | ||
| ) | ||
|
|
||
| # load x, res (if applicable), and weights | ||
| gl.amd.gfx1250.tdm.async_load(x_desc, [start_pid, 0], smemX) | ||
| if HAS_RES: | ||
| gl.amd.gfx1250.tdm.async_load(res_desc, [start_pid, 0], smemRes) | ||
| gl.amd.gfx1250.tdm.async_load(weights_desc, [0, 0], smemWeights) | ||
|
|
||
| if HAS_RES: | ||
| gl.amd.gfx1250.tdm.async_wait(2) | ||
| else: | ||
| gl.amd.gfx1250.tdm.async_wait(1) | ||
|
|
||
| smemX_1d = smemX.reshape([BLOCK_SIZE_N]) | ||
| x = smemX_1d.load(n_offs_layout).to(gl.float32) | ||
|
|
||
| # reshape res and add to x if applicable | ||
| if HAS_RES: | ||
| gl.amd.gfx1250.tdm.async_wait(1) | ||
| smemRes_1d = smemRes.reshape([BLOCK_SIZE_N]) | ||
| res = smemRes_1d.load(n_offs_layout).to(gl.float32) | ||
| x = x + res | ||
| smemResOut.store(x.reshape([1, BLOCK_SIZE_N]).to(res_out_ptr.dtype.element_ty)) | ||
| gl.amd.gfx1250.tdm.async_store(res_out_desc, [start_pid, 0], smemResOut) | ||
|
|
||
| if HAS_RES: | ||
| gl.amd.gfx1250.tdm.async_wait(1) | ||
| else: | ||
| gl.amd.gfx1250.tdm.async_wait(0) | ||
|
|
||
| smemWeights_1d = smemWeights.reshape([BLOCK_SIZE_N]) | ||
| w = smemWeights_1d.load(n_offs_layout).to(gl.float32) | ||
| # compute rmsnorm | ||
| out = _rmsmorm_op(x, w, N, eps).to(out_ptr.dtype.element_ty) | ||
| # write out to LDS | ||
| smemOut.store(out.reshape([1, BLOCK_SIZE_N])) | ||
| gl.amd.gfx1250.tdm.async_store(out_desc, [start_pid, 0], smemOut) | ||
|
|
||
| gl.amd.gfx1250.tdm.async_wait(0) | ||
7 changes: 7 additions & 0 deletions
7
aiter/ops/triton/configs/gfx1250/gluon/normalization/fused_add_rmsnorm_pad/DEFAULT.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "N_LEQ_32": { "num_warps": 1 }, | ||
| "N_LEQ_64": { "num_warps": 2 }, | ||
| "N_LEQ_128": { "num_warps": 4 }, | ||
| "N_LEQ_256": { "num_warps": 8 }, | ||
| "any": { "num_warps": 8 } | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.