Skip to content

Add AMAX, AVG, NORM1, NORM2, MUL, MUL_NO_ZEROS reduction modes#325

Merged
rsuderman merged 11 commits into
iree-org:mainfrom
rsuderman:reduction_rest
May 7, 2026
Merged

Add AMAX, AVG, NORM1, NORM2, MUL, MUL_NO_ZEROS reduction modes#325
rsuderman merged 11 commits into
iree-org:mainfrom
rsuderman:reduction_rest

Conversation

@rsuderman
Copy link
Copy Markdown
Contributor

Enable the remaining cuDNN reduction modes in ReductionAttr and add the corresponding MLIR schemas to the asm emitter:

  • NORM1 lowers to abs + sum.dim_IntList.
  • AMAX lowers to abs + amax.
  • AVG lowers to mean.dim (float dtypes only — torch.aten.mean.dim is not defined on integer tensors, so the sample skips int32 for AVG).
  • NORM2 lowers to mul + sum.dim_IntList + sqrt.
  • MUL lowers directly to torch.prims.prod.
  • MUL_NO_ZEROS uses aten.ne.Scalar to build an i1 mask, then aten.where.ScalarOther to substitute 1 for zero entries before feeding the result to torch.prims.prod, so zero inputs are excluded from the product.

Extend samples/reduction/reduction_ops.cpp to exercise every new mode. Input data is built by a per-mode generateReductionInputData helper so MUL/MUL_NO_ZEROS get a non-trivial pattern (mostly 1s with a 2 and a 3, plus injected zeros for MUL_NO_ZEROS) that stays in range for fp16/int32, and the expected value is computed by the existing reference reduction loop rather than hardcoded.

Add lit tests for each new mode under tests/lit/ and register them in tests/CMakeLists.txt.

Copy link
Copy Markdown
Member

@sjain-stanford sjain-stanford left a comment

Choose a reason for hiding this comment

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

Might need rebase / CI seems unclean.

Comment thread include/fusilli/attributes/reduction_attributes.h
Comment thread include/fusilli/support/asm_emitter.h Outdated
Comment thread include/fusilli/support/asm_emitter.h
rsuderman and others added 4 commits May 1, 2026 12:00
Enable the remaining cuDNN reduction modes in ReductionAttr and add
the corresponding MLIR schemas to the asm emitter:

- NORM1 lowers to abs + sum.dim_IntList.
- AMAX lowers to abs + amax.
- AVG lowers to mean.dim (float dtypes only — torch.aten.mean.dim is
  not defined on integer tensors, so the sample skips int32 for AVG).
- NORM2 lowers to mul + sum.dim_IntList + sqrt.
- MUL lowers directly to torch.prims.prod.
- MUL_NO_ZEROS uses aten.ne.Scalar to build an i1 mask, then
  aten.where.ScalarOther to substitute 1 for zero entries before
  feeding the result to torch.prims.prod, so zero inputs are
  excluded from the product.

Extend samples/reduction/reduction_ops.cpp to exercise every new
mode. Input data is built by a per-mode generateReductionInputData
helper so MUL/MUL_NO_ZEROS get a non-trivial pattern (mostly 1s with
a 2 and a 3, plus injected zeros for MUL_NO_ZEROS) that stays in
range for fp16/int32, and the expected value is computed by the
existing reference reduction loop rather than hardcoded.

Add lit tests for each new mode under tests/lit/ and register them
in tests/CMakeLists.txt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Rob Suderman <rob.suderman@gmail.com>
Signed-off-by: Rob Suderman <rob.suderman@gmail.com>
@rsuderman rsuderman requested a review from sjain-stanford May 1, 2026 19:42
Comment thread include/fusilli/attributes/reduction_attributes.h Outdated
Comment thread include/fusilli/support/asm_emitter.h
Comment thread include/fusilli/support/asm_emitter.h Outdated
Comment thread samples/reduction/reduction_ops.cpp
Comment thread samples/reduction/reduction_ops.cpp
Comment thread include/fusilli/support/asm_emitter.h
Comment thread tests/CMakeLists.txt Outdated
Comment thread samples/reduction/reduction_ops.cpp Outdated
@rsuderman rsuderman requested a review from sjain-stanford May 7, 2026 19:05
Copy link
Copy Markdown
Member

@sjain-stanford sjain-stanford left a comment

Choose a reason for hiding this comment

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

LGTM modulo two more comments.

Comment thread include/fusilli/attributes/reduction_attributes.h Outdated
Comment thread samples/reduction/reduction_ops.cpp
Comment thread include/fusilli/support/asm_emitter.h
@rsuderman rsuderman merged commit 90053d0 into iree-org:main May 7, 2026
10 checks passed
sjain-stanford added a commit that referenced this pull request May 8, 2026
I usually grep for `TODO` to quickly scan open items so adding this
here. Nit cleanup from #325.

Signed-off-by: Sambhav Jain <sambhav@alumni.stanford.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants