Skip to content

rocm-ck: [AE-1] FmhaMaskType enum on FmhaBwdDQDKDVAlgorithm - #7274

Merged
aosewski merged 3 commits into
users/shumway/ck/exp-kpackfrom
users/chris-tsiaousis-hpc/ck/rocm-ck-ae-1-mask-type-enum
Jun 3, 2026
Merged

aosewski merged 3 commits into
users/shumway/ck/exp-kpackfrom
users/chris-tsiaousis-hpc/ck/rocm-ck-ae-1-mask-type-enum

Conversation

@chris-tsiaousis-hpc

@chris-tsiaousis-hpc chris-tsiaousis-hpc commented May 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Two stacked commits implementing AE-1 from the FMHA BWD project board: replace the boolean has_mask flag on FmhaBwdDQDKDVAlgorithm / FmhaBwdDQDKDVSpec with a FmhaMaskType enum that mirrors ck_tile::GenericAttentionMaskEnum.

The boolean was a 1-of-2 collapse that lost the top-left-vs-bottom-right distinction CK Tile already supports and could not express GENERIC sliding-window masks at all — both block the upcoming _swa / _cmask_br variants tracked by P1-1b / P1-7.

Workplan task: https://github.com/orgs/ROCm/projects/178/views/1?pane=issue&itemId=183664589

Commits

  1. af3d56frocm-ck: [AE-1] Add FmhaMaskType enum to common.hpp
    Vocabulary-only addition. Integer values pinned to ck_tile::GenericAttentionMaskEnum so the device bridge can static_cast straight into the MASK_TYPE kernel scalar without a translation table.

  2. 2a81cf7rocm-ck: [AE-1] Replace has_mask bool with mask_type enum on DqDkDv
    Atomic API rename across spec / dev bridge / registry / runner / kpack TOC (pack.py) / docs / tests, plus a new compile_fail/dqdkdv_invalid_mask_type.cpp for out-of-range enum rejection. findVariant() compares the enum directly so future GENERIC / BOTTOM_RIGHT_CAUSAL requests are not silently aliased onto the top-left variant — same class of bug as the has_bias_grad aliasing fixed in 7abd4.

Test plan

  • cmake configure clean.
  • ninja rocm_ck_tests builds 19 host targets clean.
  • ctest -L rocm_ck: 19/19 pass — including the new MakeSpecMaskTypes (covers all 4 enum values + hasMask() agreement) and Registry_DqDkDv_RejectsUnregisteredMaskType (verifies BOTTOM_RIGHT_CAUSAL / GENERIC requests return nullptr instead of aliasing onto cmask).
  • ctest -L compile_fail: 46/46 pass (45 pre-existing + new dqdkdv_invalid_mask_type).
  • Pre-commit hooks pass: clang-format-18, copyright headers, exec-bit, ck_tile remod.
  • Built & ran on a GPU node (host-only changes; kpack archive build deferred to a downstream PR that adds new mask-flavour variants).

Out of scope

  • No new variants registered yet — _cmask_br / _swa are P1-1b / P1-7 follow-ups that consume this enum.
  • OGradDotO / ConvertDQ specs unchanged (they don't carry a mask field).

Copilot AI 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.

Pull request overview

This PR upgrades the FMHA BWD dQ/dK/dV configuration schema by replacing the lossy has_mask boolean with a FmhaMaskType enum that preserves CK Tile’s distinct mask families (top-left causal, bottom-right causal, and generic sliding-window), enabling upcoming variant work without silent aliasing.

Changes:

  • Introduces FmhaMaskType (value-pinned to ck_tile::GenericAttentionMaskEnum) and replaces has_mask across DqDkDv spec/config/registry/runner/docs/tests.
  • Adds a shared hasMask() predicate and compile-time validation to reject out-of-range enum values (with a new compile-fail test).
  • Updates variant matching to compare mask_type exactly (preventing bottom-right/generic requests from incorrectly matching top-left variants).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/composablekernel/experimental/rocm_ck/include/rocm_ck/ops/fmha_bwd/common.hpp Adds FmhaMaskType enum (pinned integer values) and documentation.
projects/composablekernel/experimental/rocm_ck/include/rocm_ck/ops/fmha_bwd/dqdkdv_spec.hpp Replaces has_mask with mask_type, adds hasMask() helper, validates enum range, updates scalar-slot predicate.
projects/composablekernel/experimental/rocm_ck/include/rocm_ck/ops/fmha_bwd/dqdkdv_dev.hpp Switches device bridge gating from K.has_mask to hasMask(K) and keeps runtime MASK_TYPE wiring.
projects/composablekernel/experimental/rocm_ck/examples/06_rocm_ck_fmha_bwd/rocm_fmha_bwd_registry.hpp Updates registered variants and findVariant() to match mask_type exactly.
projects/composablekernel/experimental/rocm_ck/examples/06_rocm_ck_fmha_bwd/main.cpp Populates MASK_TYPE scalar from variant.spec.mask_type and uses hasMask() for gating.
projects/composablekernel/experimental/rocm_ck/examples/06_rocm_ck_fmha_bwd/pack.py Updates kpack variant metadata to use mask_type instead of has_mask.
projects/composablekernel/experimental/rocm_ck/examples/06_rocm_ck_fmha_bwd/INSIGHTS.md Updates documentation to reflect hasMask(K) gating and mask_type terminology.
projects/composablekernel/experimental/rocm_ck/tests/test_fmha_bwd_dqdkdv.cpp Updates tests for mask_type, adds coverage for all enum values + hasMask() agreement.
projects/composablekernel/experimental/rocm_ck/tests/test_fmha_bwd_compat.cpp Updates frozen baselines and adds negative registry match test for unregistered mask types.
projects/composablekernel/experimental/rocm_ck/tests/compile_fail/dqdkdv_invalid_mask_type.cpp Adds compile-fail coverage for out-of-range mask_type values.

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

@chris-tsiaousis-hpc chris-tsiaousis-hpc linked an issue May 12, 2026 that may be closed by this pull request
@chris-tsiaousis-hpc
chris-tsiaousis-hpc force-pushed the users/chris-tsiaousis-hpc/ck/rocm-ck-ae-1-mask-type-enum branch from 2a81cf7 to 8924eb7 Compare May 12, 2026 07:55
@chris-tsiaousis-hpc
chris-tsiaousis-hpc marked this pull request as ready for review May 15, 2026 14:32
@chris-tsiaousis-hpc
chris-tsiaousis-hpc requested a review from a team as a code owner May 15, 2026 14:32
Comment on lines +15 to +19
using namespace rocm_ck;

constexpr auto bad = makeSpec(FmhaBwdDQDKDVConfig{
.signature = {.dtype = DataType::FP16, .hdim_q = 128, .hdim_v = 128, .mode = FmhaMode::BATCH},
.algorithm = {.mask_type = static_cast<FmhaMaskType>(99), .pad_hdim_q = 8, .pad_hdim_v = 8}});

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.

Nice one! Since the enum has to maintained parallel to the CK Tile one, it is nice to have a test to see what happens if one's enum value is different from the "approved" ones.

// This is the same class of predicate bug fixed for `has_bias_grad` in 7abd4.
TEST(FmhaBwdCompat, Registry_DqDkDv_DisambiguatesMaskType)
{
const auto* v_tl = findVariant(FmhaBwdDQDKDVConfig{

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.

makeSpec tests for valid arguments, but this findVariant function does not. It seems like it doesnt check for mask type anywhere, just selects an implementation based on other signature and algorithm fields. Does it make sense to do these tests then? Should the algorithm and signature be validated before calling this function?

@chris-tsiaousis-hpc
chris-tsiaousis-hpc force-pushed the users/chris-tsiaousis-hpc/ck/rocm-ck-ae-1-mask-type-enum branch from 8924eb7 to 5ad8d70 Compare May 28, 2026 07:53
@chris-tsiaousis-hpc
chris-tsiaousis-hpc requested a review from a team as a code owner May 28, 2026 07:53
Add a four-valued enum that names every attention-mask family CK Tile's
GenericAttentionMaskEnum exposes (NO_MASK, TOP_LEFT_CAUSAL,
BOTTOM_RIGHT_CAUSAL, GENERIC). Integer values are pinned to match
ck_tile::GenericAttentionMaskEnum so the device bridge can forward the
spec-time enum to the MASK_TYPE kernel scalar via a static_cast without
a translation table.

This is the vocabulary commit; no spec, registry, or runner change
yet -- those are in the follow-up that replaces FmhaBwdDQDKDVAlgorithm's
boolean has_mask field with this enum.

Workplan task: AE-1 (https://github.com/orgs/ROCm/projects/178).

Test plan
- Header-only addition; existing 65 host + compile-fail tests continue
  to pass (build is unchanged).

Signed-off-by: Chris Tsiaousis <chris.tsiaousis@streamhpc.com>
Migrate FmhaBwdDQDKDVAlgorithm and FmhaBwdDQDKDVSpec from a single
boolean has_mask flag to the FmhaMaskType enum added in the previous
commit. The boolean was a 1-of-2 collapse that lost the
top-left-vs-bottom-right distinction CK Tile already supports and could
not express GENERIC sliding-window masks at all -- both blocked the
upcoming _swa / _cmask_br variants (P1-1b / P1-7).

Workplan task: AE-1 (https://github.com/orgs/ROCm/projects/178).

Signed-off-by: Chris Tsiaousis <chris.tsiaousis@streamhpc.com>
@chris-tsiaousis-hpc
chris-tsiaousis-hpc force-pushed the users/chris-tsiaousis-hpc/ck/rocm-ck-ae-1-mask-type-enum branch from 57dcc70 to 220a6bb Compare June 2, 2026 13:03
… sites

The AE-1 has_mask->mask_type rename was rebased onto a base that later
gained new has_mask call sites (group-mode tests from #7534, the consteval
suite from #7504, a group_cmask registry entry, and the group_cmask kpack
TOC entry). Those sites still referenced the removed has_mask field, so the
host test TUs no longer compiled.

Convert them with the PR's established idiom:
  * .has_mask = true              -> .mask_type = FmhaMaskType::TOP_LEFT_CAUSAL
  * EXPECT_FALSE(k.has_mask)      -> EXPECT_EQ(k.mask_type, NO_MASK)
  * EXPECT_TRUE(k.has_mask)       -> family-specific EXPECT_EQ (TL / BR / GENERIC)
  * cross-variant has_mask compare-> hasMask() equality + EXPECT_NE(mask_type)
  * pack.py "has_mask": True      -> "mask_type": "top_left_causal"

Also refresh two consteval comments that still described the pre-AE-1
findVariant() aliasing behaviour (mask_type now disambiguates the family).

Verified host compile-time gate with standalone clang++ -std=c++20:
test_fmha_bwd_{compat,consteval,dqdkdv,common,validate_args,convert_dq,
ograd_dot_o} all compile clean; compile_fail/dqdkdv_invalid_mask_type
still correctly rejects the out-of-range enum.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aosewski
aosewski merged commit cd41900 into users/shumway/ck/exp-kpack Jun 3, 2026
5 of 11 checks passed
@aosewski
aosewski deleted the users/chris-tsiaousis-hpc/ck/rocm-ck-ae-1-mask-type-enum branch June 3, 2026 10:30
chris-tsiaousis-hpc added a commit that referenced this pull request Jun 4, 2026
Signed-off-by: Chris Tsiaousis <chris.tsiaousis@streamhpc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AE-1] mask_type enum field in FmhaBwdDQDKDVAlgorithm

4 participants