Skip to content

[Codegen][ROCDL] Drop nominal support for dynamic shared mem - #20805

Merged
qedawkins merged 2 commits into
iree-org:mainfrom
qedawkins:no_dynamic_shared_mem_amd
May 16, 2025
Merged

qedawkins merged 2 commits into
iree-org:mainfrom
qedawkins:no_dynamic_shared_mem_amd

Conversation

@qedawkins

@qedawkins qedawkins commented May 14, 2025 •

Copy link
Copy Markdown
Contributor

This was introduced for CUDA to work around static allocation limits (see #8317) and then subsequently cloned for ROCM. There is no such allocation limit on the AMD side and we don't actually support dynamic shared memory, so we can drop it.

Immediately this fixes issues where multiple exported functions will request the sum of the memory required across all functions because the dynamic symbol obfuscates the actual required amount.

To avoid regressions, this matches the current behavior of forcing all shared memory allocations to be aligned by 16. Runtime
support for dynamic shared is dropped and the block_shared_memory_size field in the flatbuffer is marked as deprecated. To
retain load time checking of shared memory resource constraints, we now query exported functions directly using hipFuncGetAttribute(..., HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES).

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

I am wondering if you also need to (should) remove the runtime aspects of #8405 like removing it from rocm schema and not relying on it at runtime?

@qedawkins

Copy link
Copy Markdown
Contributor Author

We definitely don't want to remove it for CUDA (since that's still needed for the WaR). I don't see the harm in keeping it for hip though since we'd need it if we actually did support dynamic shared memory. Maybe @AWoloszyn or @benvanik have thoughts.

@benvanik

Copy link
Copy Markdown
Collaborator

if we actually do use dynamic memory it won't be using this mechanism at all - it'll likely be a new dynamic dispatch parameter we don't currently have that needs to be exposed all the way through the HAL (iree_hal_command_buffer_dispatch will need to grow an attrs field or something silly)

@qedawkins

Copy link
Copy Markdown
Contributor Author

I see, ok we can drop the runtime changes too, but IIUC we might want to pick a tactical time to update the schema (compiler changes can happen whenever).

@benvanik

Copy link
Copy Markdown
Collaborator

you can remove the runtime handling and update the schema to have block_shared_memory_size:uint32 (deprecated); - that'll reserve the spot to avoid breaking compatibility but remove the generated accessors so it can't be used

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah, this makes sense!

@qedawkins

Copy link
Copy Markdown
Contributor Author

Ugh, regressions look real. I have a guess but will convert to draft for now.

@qedawkins
qedawkins marked this pull request as draft May 14, 2025 19:10
nirvedhmeshram
nirvedhmeshram previously approved these changes May 14, 2025
@krzysz00

Copy link
Copy Markdown
Contributor

Re regressions - I notice this PR doesn't actually remove us asking for dynamic shared memory at runtime

Thas means you're probably requesting double the LDS you actually need, which could be causing regressions

@qedawkins

Copy link
Copy Markdown
Contributor Author

Re regressions - I notice this PR doesn't actually remove us asking for dynamic shared memory at runtime

Thas means you're probably requesting double the LDS you actually need, which could be causing regressions

It's not double requesting because then I would be hitting launch failures with >= half the maximum shared memory and I'm not. Looking at the ISA I'm seeing a big spike in register usage (e.g. 149 -> 250) but it's not clear to me where those extra registers are going. I suspect it has to do with not flattening our allocations (which this dynamic thing does along the way).

@qedawkins

Copy link
Copy Markdown
Contributor Author

@krzysz00 looks like your hunch about alignment was right though. Comparing the optimized llvm IR with and without this change reveals that the only difference is alignment of accesses: https://gist.github.com/qedawkins/1fbda1133f3a6cc162969360b2f65cad

@qedawkins

Copy link
Copy Markdown
Contributor Author

Lol, it's this:

/*alignment=*/16, /*addr_space=*/3);

Hard coded alignment fixup.

This was introduced for CUDA to work around static allocation limits
(see iree-org#8317) and then subsequently cloned for ROCM. There is no such
allocation limit on the AMD side and we don't actually support dynamic
shared memory, so we can drop it.

Immediately this fixes issues where multiple exported functions will
request the sum of the memory required across all functions because the
dynamic symbol obfuscates the actual required amount.
@qedawkins
qedawkins force-pushed the no_dynamic_shared_mem_amd branch from 9bf5b30 to 9bdefa2 Compare May 15, 2025 20:53
@qedawkins
qedawkins marked this pull request as ready for review May 15, 2025 20:53
@qedawkins
qedawkins dismissed stale reviews from nirvedhmeshram and MaheshRavishankar May 15, 2025 21:02

Code has changed non-trivially since the review

@nirvedhmeshram nirvedhmeshram 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 % few minor comments/questions that you can address however.

@qedawkins

Copy link
Copy Markdown
Contributor Author

I'll send a follow up to move alignment annotations earlier on. I didn't want to do that in this PR because I have to go through any alloc adjusting patterns and make sure they retain the alignment. Too much for this change, and the hack to keep the same (16) alignment is basically NFC since it's what we already do.

@qedawkins
qedawkins merged commit d7bb36b into iree-org:main May 16, 2025
@qedawkins
qedawkins deleted the no_dynamic_shared_mem_amd branch May 16, 2025 22:42
pravg-amd pushed a commit to praveen-g-ctt/iree that referenced this pull request Jun 5, 2025
qedawkins pushed a commit that referenced this pull request Jun 5, 2025
MaheshRavishankar added a commit to MaheshRavishankar/iree that referenced this pull request Jun 16, 2025
MaheshRavishankar added a commit to MaheshRavishankar/iree that referenced this pull request Jun 16, 2025
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
This was introduced for CUDA to work around static allocation limits
(see #8317) and then subsequently cloned for ROCM. There is no such
allocation limit on the AMD side and we don't actually support dynamic
shared memory, so we can drop it.

Immediately this fixes issues where multiple exported functions will
request the sum of the memory required across all functions because the
dynamic symbol obfuscates the actual required amount.

To avoid regressions, this matches the current behavior of forcing all
shared memory allocations to be aligned by 16. Runtime
support for dynamic shared is dropped and the `block_shared_memory_size`
field in the flatbuffer is marked as deprecated. To
retain load time checking of shared memory resource constraints, we now
query exported functions directly using `hipFuncGetAttribute(...,
HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES)`.
AWoloszyn pushed a commit that referenced this pull request Dec 1, 2025
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.

5 participants