Skip to content

Conversation

@dchigarev
Copy link
Contributor

Fixes #393

The new pass goes through each memref.alloc() inside of a gpu.launch block {} and sets shared mem-space attribute (int value of 3) to the resulted memref (it ignores all memrefs that already have explicitly specified mem-space).

Signed-off-by: dchigarev <dmitry.chigarev@intel.com>
Signed-off-by: dchigarev <dmitry.chigarev@intel.com>
@dchigarev dchigarev marked this pull request as ready for review October 28, 2024 12:39
Comment on lines 37 to 44
while (parentOp) {
// Check if the current parent is a gpu.launch operation
if (llvm::isa<mlir::gpu::LaunchOp>(parentOp)) {
return true;
}
// Move to the parent operation
parentOp = parentOp->getParentOp();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You're probably looking for getParentOfType here. Another option would be to just target the pass at gpu module instead. The latter is probably also useful if you want to check for the total allocated memory size without additional analysis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option would be to just target the pass at gpu module instead

Targeting the pass to a gpu module would be nice, however it won't work with the existing pipeline. There are some passes that must be run after allocs-to-slm but before conversion to the gpu module (linalg-to-xegpu, linalg-to-loops, insert-gpu-allocs).

Some of the passes (linalg-to-xegpu and linalg-to-loops) might be adjusted by retargeting them from funcOp to gpuFuncOp, but insert-gpu-allocs won't work that way, as its logic expects to be applied to a func.func containing a gpu.launch block (and not a GPU module).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So only replaced the while-loop with getParentOfType for now

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I was thinking about something else while typing. I meant the launch gpu op, not gpu module. Anyway, the change is trivial.

Signed-off-by: dchigarev <dmitry.chigarev@intel.com>
Signed-off-by: dchigarev <dmitry.chigarev@intel.com>
@dchigarev dchigarev merged commit 33c3e5f into intel:main Oct 29, 2024
6 checks passed
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.

Add a pass that adds shared mem space attribute to allocs in a GPU kernel

3 participants