Skip to content
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

xe: ocl: sdpa: pull grouped scales out of gemm where possible #2409

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

petercad
Copy link
Contributor

Hoists the K scaling out of the GEMM microkernel where possible. Here, "where possible" means no zp and group size >= head size (so effectively per-token scaling).

@petercad petercad requested a review from a team as a code owner January 15, 2025 00:22
@github-actions github-actions bot added the platform:gpu-intel Codeowner: @oneapi-src/onednn-gpu-intel label Jan 15, 2025
Comment on lines +113 to +124
#if VAL_SCALES == QUANTIZE_1D
DECLARE_2D_TILE(v_scales_tile_type, KEY_ATTR_SCALES_DATA_T, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE(v_scales_tile_type_float, float, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE_BLOCK_OPS(v_scales_tile_type, KEY_ATTR_SCALES_DATA_T,
SUBGROUP_SIZE, ugemm_kq_sg_tile_m, 1, 1, 1)

DECLARE_2D_TILE_HREDUCE(s_tile_type, SUBGROUP_SIZE, ugemm_kq_c_type_block0,
ugemm_kq_c_type_block1, ugemm_kq_c_type_nblock0,
ugemm_kq_c_type_nblock1, v_scales_tile_type_float, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#if VAL_SCALES == QUANTIZE_1D
DECLARE_2D_TILE(v_scales_tile_type, KEY_ATTR_SCALES_DATA_T, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE(v_scales_tile_type_float, float, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE_BLOCK_OPS(v_scales_tile_type, KEY_ATTR_SCALES_DATA_T,
SUBGROUP_SIZE, ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE_HREDUCE(s_tile_type, SUBGROUP_SIZE, ugemm_kq_c_type_block0,
ugemm_kq_c_type_block1, ugemm_kq_c_type_nblock0,
ugemm_kq_c_type_nblock1, v_scales_tile_type_float, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
#if VAL_SCALES == QUANTIZE_1D
DECLARE_2D_TILE(v_scales_tile_type, VAL_ATTR_SCALES_DATA_T, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE(v_scales_tile_type_float, float, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE_BLOCK_OPS(v_scales_tile_type, VAL_ATTR_SCALES_DATA_T,
SUBGROUP_SIZE, ugemm_kq_sg_tile_m, 1, 1, 1)
DECLARE_2D_TILE_HREDUCE(s_tile_type, SUBGROUP_SIZE, ugemm_kq_c_type_block0,
ugemm_kq_c_type_block1, ugemm_kq_c_type_nblock0,
ugemm_kq_c_type_nblock1, v_scales_tile_type_float, SUBGROUP_SIZE,
ugemm_kq_sg_tile_m, 1, 1, 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks.

@@ -21,11 +21,14 @@
#include "gemm_kq.h"
#include "gemm_vs.h"

/* The quantization parameter may be unique for each token/element */
Copy link
Contributor

Choose a reason for hiding this comment

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

Random spot: do we have test cases covering new per-token scaling optimized path and the old path?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:gpu-intel Codeowner: @oneapi-src/onednn-gpu-intel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants