Skip to content

[GPU][Codegen] Distribute to single subgroup for large parallel dimension in reduction - #2

Closed
efric wants to merge 4 commits into
kuhar:reduction-bitwidthfrom
efric:reduction-appendix-3
Closed

efric wants to merge 4 commits into
kuhar:reduction-bitwidthfrom
efric:reduction-appendix-3

Conversation

@efric

@efric efric commented Jul 25, 2025 •

Copy link
Copy Markdown

Prioritize distributing to just a single subgroup along the reduction dimension when the problem size is large enough for us to saturate all CUs. Default to prior behavior when parallel dimensions are small (I use 2 * number of CUs here conservatively which aligned with Prashant's comment, but not sure if this is correct). This avoids needing to write/read to shared memory for a cross-group reduction. More details to come with examples and performance differences.

When only an architecture is specified and not a specific device, default to using the most conservative number of CUs within that generation.

// also within hardware limitations.
const int64_t maxWorkgroupSize = 1024;
ArrayRef<int32_t> maxWgSizes = wgp.getMaxWorkgroupSizes();
int64_t maxWorkgroupSize = *std::max_element(maxWgSizes.begin(), maxWgSizes.end());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think there's an llvm:: wrapper for this in STLExtras.h

Comment on lines +878 to +879
IREE::GPU::TargetChipAttr chip = target.getChip();
int numComputeUnits = chip ? chip.getWgpCount() : 256;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This should probably be a helper function that we put in some utils header

Comment on lines +881 to +883
// If there is enough work to saturate all CUs * 2, use single subgroup per workgroup
if (parallelSize && *parallelSize > numComputeUnits * 2)
maxWorkgroupSize = target.getPreferredSubgroupSize();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We may need an additional target device field for simds_per_cu

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