Skip to content

feat(hiptensor): add bf16 and fp32-scalar support to elementwise trinary - #14564

Merged
evedovelli merged 4 commits into
developfrom
users/evedovel/hiptensor/elementwise-trinary-bf16
Oct 29, 2026
Merged

evedovelli merged 4 commits into
developfrom
users/evedovel/hiptensor/elementwise-trinary-bf16

Conversation

@evedovelli

@evedovelli evedovelli commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Elementwise binary accepts six data type combinations: f16, bf16, f32 and f64, with f16 and bf16 also allowed an f32 scalar. Trinary only accepted f16, f32 and f64 with a same-type scalar. Binary's bf16 and f16-with-f32-scalar paths were also accepted by the API but never tested end to end; no test config used them. This PR gives trinary the same support as binary and tests all six combinations for both ops. Stacked on the elementwise-test refactor PR; retarget to develop after it merges.

ISSUE ID : AIHIPTENS-589

Technical Details

Library

  • hiptensor_elementwise_trinary.cpp: the type table adds {16F,16F,16F,32F}, {16BF,16BF,16BF,16BF} and {16BF,16BF,16BF,32F} (typeA, typeB, typeC, typeScalar), matching binary.
  • hiptensorElementwiseTrinaryExecute now returns HIPTENSOR_STATUS_NOT_SUPPORTED when D's data type differs from C's, as binary already does. Previously the mismatch failed later with HIPTENSOR_STATUS_INTERNAL_ERROR.
  • elementwise_trinary_solution_rank{2..6}_half_instances.cpp: register ck::Tuple<bhalf_t, bhalf_t, bhalf_t> alongside half, as the binary half files already do.
    • No new op code: trinary uses the same HiptensorBinaryOp and UnaryCombinedOp that binary bf16 already compiles with.
    • The trinary kernel parameters and fallback hashes are type-generic.
    • The CPU reference already registered bf16 trinary.
  • Trinary scalars are read with readVal<float>, which handles a bf16 compute descriptor since feat(hiptensor): add bf16 support for elementwise permute #14406.

Tests

  • Binary and trinary harnesses: checkDevice accepts bf16 (gated on isF16Supported()). Scalar writes, comparison and printing already go through the type-dispatch helper from the refactor PR.

  • Configs, binary and trinary, ranks 2-6:

    Category Entries added
    validation/quick, emulation/quick [16BF,16BF]
    validation/standard, emulation/full, bench [16F,32F], [16BF,16BF], [16BF,32F]

    validation/comprehensive and validation/full stay empty for these ops, as before.

  • elementwise_cpu_test: three new cases each for binary and trinary: bf16, bf16 with an f32 scalar, and f16 with an f32 scalar. The shared helpers use explicit casts so they compile for hip_bfloat16; f32 and f16 values are unchanged.

  • elementwise_mode_test: TrinaryWithMismatchedOutputTypeReturnsNotSupported. It uses f16 for D so it runs on GPUs without FP64.

Docs

  • api-reference.rst: the old "Element-wise Operations" rows (f16 / f32 / - etc.) are replaced by one "Element-wise (Permutation, binary, trinary)" group. All three ops now support the same six combinations. A new note says that for element-wise ops all tensors share one data type and the compute type is the scalar type.
  • installation.rst: binary and trinary test descriptions include bfloat16.
  • CHANGELOG.md (2.6.0): Added (trinary bf16, and f16 with an f32 scalar); Changed (trinary output-type check).
  • TESTING.md: binary, trinary, CPU-reference and mode-test rows updated; the "binary BF16 untested" known gap removed.

Test Plan

Built with -DGPU_TARGETS=<arch> and run on real hardware:

  • ctest -R 'elementwise|util_test' (21 tests).
  • elementwise_cpu_test and elementwise_mode_test directly.
  • Binary and trinary binaries, ranks 2-6, default (validation/standard) config, counting validated cases per type pair.
  • Rank 3 with the emulation/full and bench configs (bench with validation off).

Test Result

Arch binary + trinary, all type pairs, ranks 2-6 elementwise_cpu_test elementwise_mode_test ctest
gfx942 (MI300A) 6 pairs pass 15/15 13/13 21/21
gfx950 (MI350X) 6 pairs pass 15/15 13/13 21/21
gfx90a (MI210) 6 pairs pass 15/15 13/13 21/21
gfx908 (MI100) 5 pairs pass (no FP64) 14, FP64 skipped 13/13 21/21
gfx1201 5 pairs pass (no FP64) 14, FP64 skipped 13/13 21/21

Submission Checklist

@Ryker0627 Ryker0627 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.

LGTM

@evedovelli
evedovelli added this pull request to stack #14658 October 29, 2026 15:07
Base automatically changed from users/evedovel/hiptensor/refactor-elementwise-tests to develop October 29, 2026 15:11
@evedovelli
evedovelli force-pushed the users/evedovel/hiptensor/elementwise-trinary-bf16 branch from debc3ee to 2a570ad Compare October 29, 2026 15:11
@therock-pr-bot

therock-pr-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@evedovelli
evedovelli force-pushed the users/evedovel/hiptensor/elementwise-trinary-bf16 branch from 2a570ad to 3d5d42e Compare October 29, 2026 15:34
@evedovelli
evedovelli merged commit b0f07f8 into develop Oct 29, 2026
89 checks passed
@evedovelli
evedovelli deleted the users/evedovel/hiptensor/elementwise-trinary-bf16 branch October 29, 2026 21:21
@assistant-librarian

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

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.

2 participants