Skip to content

Enable fixed-size reductions for expressions - #1245

Merged
cliffburdick merged 1 commit into
mainfrom
cburdick/issue-1242-fixed-size-expression-reductions
Sep 4, 2026
Merged

Enable fixed-size reductions for expressions#1245
cliffburdick merged 1 commit into
mainfrom
cburdick/issue-1242-fixed-size-expression-reductions

Conversation

@cliffburdick

Copy link
Copy Markdown
Collaborator

Fixes #1242

CUB reductions typically get transformed into an iterator for generic types. However, when we know the reduction is a basic pointer-style reduction on an inner dimension we can avoid materializing operators and iterators on input. This improves reductions up to about 170x, depending on size:

image

@copy-pr-bot

copy-pr-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cliffburdick

Copy link
Copy Markdown
Collaborator Author

/build

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Enables CUB fixed-size segmented reductions for compatible random-access expressions, avoiding intermediate materialization.

  • Adds fixed-size input/output reduction adapters and permutation compatibility selection.
  • Applies the optimized path to generic, sum, minimum, and maximum reductions while retaining the offset-based fallback.
  • Skips segmented CUB calls for empty outputs and adds expression-reduction coverage and documentation.

Confidence Score: 5/5

The PR appears safe to merge with no concrete correctness, security, or build failures identified.

The optimized path preserves the fallback path’s collapsed logical iteration and equal segment boundaries, while incompatible top-level permutations continue to use explicit offsets.

Important Files Changed

Filename Overview
include/matx/core/reduce_utils.h Adds compatibility detection and fixed-size adapters that preserve logical iterator ordering and output conversion behavior.
include/matx/transforms/cub.h Selects fixed-size CUB segmented reductions for compatible non-scalar inputs, retains the prior fallback, and avoids calls for empty outputs.
test/00_operators/ReductionTests.cu Adds numerical coverage for fixed-size sum, minimum, maximum, and product reductions over expressions.
docs_input/api/manipulation/selecting/reduce.rst Documents intermediate-free fixed-size reductions for compatible CUDA expressions.
docs_input/api/math/sumprod/sum.rst Documents the optimized fixed-size sum path for compatible CUDA expressions.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Reduction expression] --> B{Output empty?}
  B -->|Yes| C[Return]
  B -->|No| D{Input and output contiguous tensor views?}
  D -->|Yes| E[Direct CUB reduction]
  D -->|No| F{Fixed-size compatible?}
  F -->|Yes| G[Collapse expression]
  G --> H[Fixed-size segmented CUB reduction]
  F -->|No| I[Offset-based segmented CUB reduction]
Loading

Reviews (1): Last reviewed commit: "Enable fixed-size reductions for express..." | Re-trigger Greptile

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 93.4%cburdick/issue-1242-fixed-size-expression-reductions into main. No base build found for main.

@cliffburdick
cliffburdick merged commit 5c4ae00 into main Sep 4, 2026
2 checks passed
@cliffburdick
cliffburdick deleted the cburdick/issue-1242-fixed-size-expression-reductions branch September 4, 2026 19:56
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.

[FEA] Enable fixed-size CUB reductions for elementwise expressions

2 participants