Skip to content

[hipDNN] Add reduction operation support to frontend#5489

Open
rsuderman wants to merge 8 commits intoROCm:developfrom
rsuderman:reduction_op
Open

[hipDNN] Add reduction operation support to frontend#5489
rsuderman wants to merge 8 commits intoROCm:developfrom
rsuderman:reduction_op

Conversation

@rsuderman
Copy link
Contributor

Motivation

hipDNN lacked support for reduction operations, which are needed for building composite ops (e.g., softmax, SDPA) and to match the cudnn-frontend API surface for portability.

Technical Details

  • Add reduction_attributes.fbs schema with ReductionMode enum (ADD, MUL, MIN_OP, MAX_OP, AMAX, AVG, NORM1, NORM2, MUL_NO_ZEROS); MIN and MAX are renamed to MIN_OP/MAX_OP to avoid flatc name collisions with reserved identifiers, matching the PointwiseMode convention used elsewhere in the schema
  • Generate reduction_attributes_generated.h for both FlatBuffers versions (v24_12_23 and v25_9_23) and regenerate graph_generated.h to add ReductionAttributes as union member 17
  • Add ReductionAttributes frontend class with set_mode()/get_mode() and X/Y tensor accessors; class and typedef names match cudnn-frontend's Reduction_attributes / ReductionMode_t
  • Add ReductionNode, Graph::reduction() method, JSON utilities, and deserialization case in Graph::deserializeFromFlatBuffer()
  • Wire ReductionAttributes into NodeWrapper, JSON Graph.hpp, and TestJson / TestGraphSerialization round-trip tests

Test Plan

  • Run ninja unit-check and verify TestJson and TestGraphSerializationRoundTrip.ReductionNode pass
  • Confirm JSON and binary round-trip for a reduction graph

Test Result

  • hipdnn test suite run and passed

Submission Checklist

## Motivation
hipDNN lacked support for reduction operations, which are needed for
building composite ops (e.g., softmax, SDPA) and to match the
cudnn-frontend API surface for portability.

## Technical Details
- Add `reduction_attributes.fbs` schema with `ReductionMode` enum
  (ADD, MUL, MIN_OP, MAX_OP, AMAX, AVG, NORM1, NORM2, MUL_NO_ZEROS);
  MIN and MAX are renamed to MIN_OP/MAX_OP to avoid flatc name
  collisions with reserved identifiers, matching the PointwiseMode
  convention used elsewhere in the schema
- Generate `reduction_attributes_generated.h` for both FlatBuffers
  versions (v24_12_23 and v25_9_23) and regenerate `graph_generated.h`
  to add `ReductionAttributes` as union member 17
- Add `ReductionAttributes` frontend class with `set_mode()`/`get_mode()`
  and `X`/`Y` tensor accessors; class and typedef names match
  cudnn-frontend's `Reduction_attributes` / `ReductionMode_t`
- Add `ReductionNode`, `Graph::reduction()` method, JSON utilities,
  and deserialization case in `Graph::deserializeFromFlatBuffer()`
- Wire `ReductionAttributes` into `NodeWrapper`, JSON `Graph.hpp`,
  and `TestJson` / `TestGraphSerialization` round-trip tests

## Test Plan
- Run `ninja unit-check` and verify `TestJson` and
  `TestGraphSerializationRoundTrip.ReductionNode` pass
- Confirm JSON and binary round-trip for a reduction graph

Test Result
- Not yet run (no GPU / build environment available at commit time)

Signed-off-by: Rob Suderman <rob.suderman@gmail.com>
@BrianHarrisonAMD
Copy link
Contributor

Heads up when #5356 goes in there will be a slight change you will need to include.
The nodes now have an enum that gets passed into the base node to allow us to remove RTTI.

@codecov-commenter
Copy link

codecov-commenter commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 93.09091% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../hipdnn/frontend/include/hipdnn_frontend/Graph.hpp 60.00% 9 Missing and 5 partials ⚠️
...d/include/hipdnn_frontend/detail/GraphUnpacker.hpp 84.62% 1 Missing and 1 partial ⚠️
...end/include/hipdnn_frontend/node/ReductionNode.hpp 97.22% 0 Missing and 2 partials ⚠️
...hipdnn_frontend/attributes/ReductionAttributes.hpp 98.00% 0 Missing and 1 partial ⚠️

❌ Your project status has failed because the head coverage (77.21%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5489      +/-   ##
===========================================
+ Coverage    67.27%   67.29%   +0.02%     
===========================================
  Files         1844     1847       +3     
  Lines       284014   284289     +275     
  Branches     39839    39880      +41     
===========================================
+ Hits        191044   191300     +256     
- Misses       76512    76522      +10     
- Partials     16458    16467       +9     
Flag Coverage Δ *Carryforward flag
hipBLAS 90.67% <ø> (ø) Carriedforward from 02f625e
hipBLASLt 43.49% <ø> (ø) Carriedforward from 02f625e
hipCUB 82.21% <ø> (ø) Carriedforward from 02f625e
hipDNN 85.19% <93.09%> (+0.07%) ⬆️
hipFFT 55.59% <ø> (ø) Carriedforward from 02f625e
hipRAND 76.12% <ø> (ø) Carriedforward from 02f625e
hipSOLVER 68.81% <ø> (ø) Carriedforward from 02f625e
hipSPARSE 84.70% <ø> (ø) Carriedforward from 02f625e
rocBLAS 47.97% <ø> (ø) Carriedforward from 02f625e
rocFFT 53.24% <ø> (ø) Carriedforward from 02f625e
rocRAND 57.07% <ø> (ø) Carriedforward from 02f625e
rocSOLVER 77.21% <ø> (ø) Carriedforward from 02f625e
rocSPARSE 71.48% <ø> (ø) Carriedforward from 02f625e

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...k/include/hipdnn_data_sdk/utilities/json/Graph.hpp 94.63% <100.00%> (+0.19%) ⬆️
...nn_data_sdk/utilities/json/ReductionAttributes.hpp 100.00% <100.00%> (ø)
.../hipdnn/frontend/include/hipdnn_frontend/Types.hpp 69.46% <100.00%> (+2.04%) ⬆️
...nn_test_sdk/utilities/FlatbufferGraphTestUtils.hpp 51.74% <100.00%> (+1.04%) ⬆️
...hipdnn_frontend/attributes/ReductionAttributes.hpp 98.00% <98.00%> (ø)
...d/include/hipdnn_frontend/detail/GraphUnpacker.hpp 71.56% <84.62%> (+0.53%) ⬆️
...end/include/hipdnn_frontend/node/ReductionNode.hpp 97.22% <97.22%> (ø)
.../hipdnn/frontend/include/hipdnn_frontend/Graph.hpp 85.20% <60.00%> (-0.71%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… is_deterministic

## Motivation
Address PR ROCm#5489 review comments to improve correctness, API parity with
cudnn-frontend, and test coverage for the reduction operation stack.

## Technical Details
- Add TestReductionAttributes.cpp and TestReductionNode.cpp covering mode
  getters/setters, tensor accessors, pack/fromFlatBuffer round-trips,
  pre_validate_node error cases, and dim validation
- Add output-dimension validation to ReductionNode::pre_validate_node():
  X and Y must have the same rank, each reduced Y dim must equal exactly 1,
  and at least one dim must be reduced
- Add Graph::reduction(x, y, attrs) three-param overload for explicit
  partial-reduction output tensors
- Add is_deterministic bool field to ReductionAttributes matching
  cudnn-frontend API (get_is_deterministic / set_is_deterministic);
  update schema, both generated headers (v24/v25), JSON utilities, and
  pack_attributes/fromFlatBuffer
- Change JSON ReductionMode enum names to lowercase to match convention

## Test Plan
- ninja unit-check (hipdnn_frontend_tests, hipdnn_data_sdk_tests)
- Run TestReductionAttributes.* and TestReductionNode.* with --gtest_filter

Test Result
- Not yet run; changes are build-only at this stage

Signed-off-by: Rob Suderman <rob.suderman@gmail.com>
@BrianHarrisonAMD
Copy link
Contributor

Heads up, the no-rtti changes landed, and graph changes are landing as well shortly that will require a couple updates.
Sorry about the conflicts!


namespace hipdnn_frontend::graph
{
class ReductionNode : public BaseNode<ReductionNode>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should set enum overload, and an enum added here.

Could wait until we add the lowering / lifting path I suppose, but also small to add now.

Copy link
Contributor

@BrianHarrisonAMD BrianHarrisonAMD left a comment

Choose a reason for hiding this comment

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

LGTM.

Make sure to update before merging since a fix for clang-tidy came in that was suppressing some checks, and it can break without flagging as a merge conflict.

EXPECT_TRUE(restored.get_is_deterministic());
}

TEST(TestReductionAttributes, Reduction_attributesTypedefExists)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is flagging the test name checker in the codecov tool:

TestReductionAttributes.Reduction_attributesTypedefExists [FAIL]    
  ��� Test name 'TestReductionAttributes.Reduction_attributesTypedefExists' does not match expected PascalCase format 'TestSuite.TestCase' or 'Instance/TestSuite.TestCase' without special characters such as "_;:<>[]," etc..

- Add REDUCTION = 17 to NodeType enum with trailing comma on CUSTOM_OP
- Pass NodeType::REDUCTION as template arg to BaseNode in ReductionNode
- Rename test case Reduction_attributesTypedefExists to ReductionAttributesTypedefExists

Signed-off-by: Rob Suderman <rob.suderman@gmail.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.

3 participants