Skip to content

convert extract and shuffle to mlir#793

Merged
ftynse merged 1 commit intomainfrom
users/ftynse/connect-extract
Feb 2, 2026
Merged

convert extract and shuffle to mlir#793
ftynse merged 1 commit intomainfrom
users/ftynse/connect-extract

Conversation

@ftynse
Copy link
Contributor

@ftynse ftynse commented Jan 30, 2026

Both require special-casing to convert attributes.

We cannot yet lower this further because extract and shuffle don't have index sequences, neither they need to after lowering, but we can't detect that due to

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds MLIR conversion support for extract and shuffle operations in the Wave compiler. The changes enable these operations to be properly converted to the Wave MLIR dialect by handling their specific attribute requirements.

Changes:

  • Added MLIR conversion logic for Extract and Shuffle operations with special attribute handling
  • Added imports for Extract and ShuffleOp operations
  • Added a new test case demonstrating the conversion of a sum kernel that uses extract and shuffle operations

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
wave_lang/kernel/wave/mlir_converter/water_emitter.py Adds Extract and Shuffle operation imports, registers ShuffleOp in the operation mapping, and implements custom MLIR conversion logic for both operations
lit_tests/kernel/wave/mlir_converter.py Adds a new test case mlir_converter_sum that verifies correct MLIR generation for a kernel using extract and shuffle operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

result_type, *mlir_operands, offset, size, stride
)
elif isinstance(node, Extract):
assert len(node.offset) == 1
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The assertion lacks a descriptive message explaining why the offset length must be 1. Consider adding a message like 'Extract operation requires exactly one offset value' to help with debugging.

Suggested change
assert len(node.offset) == 1
assert len(node.offset) == 1, "Extract operation requires exactly one offset value"

Copilot uses AI. Check for mistakes.
Comment on lines +667 to +676
offset = ir.IntegerAttr.get(
ir.IntegerType.get_signless(32), node.offset
)
width = ir.IntegerAttr.get(
ir.IntegerType.get_signless(32), node.width
)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The integer type creation ir.IntegerType.get_signless(32) is duplicated. Consider extracting it to a variable like i32_type to improve maintainability and reduce redundancy.

Suggested change
offset = ir.IntegerAttr.get(
ir.IntegerType.get_signless(32), node.offset
)
width = ir.IntegerAttr.get(
ir.IntegerType.get_signless(32), node.width
)
i32_type = ir.IntegerType.get_signless(32)
offset = ir.IntegerAttr.get(i32_type, node.offset)
width = ir.IntegerAttr.get(i32_type, node.width)

Copilot uses AI. Check for mistakes.
@ftynse ftynse force-pushed the users/ftynse/cleanup-extract-2 branch from 77495e8 to bf87e73 Compare February 2, 2026 08:28
Base automatically changed from users/ftynse/cleanup-extract-2 to main February 2, 2026 09:05
Both require special-casing to convert attributes.

We cannot yet lower this further because extract and shuffle don't have index
sequences, neither they need to after lowering, but we can't detect that due to

Signed-off-by: Alex Zinenko <git@ozinenko.com>
@ftynse ftynse force-pushed the users/ftynse/connect-extract branch from 3f695fb to a2fc873 Compare February 2, 2026 09:39
@ftynse ftynse merged commit 97b6d87 into main Feb 2, 2026
15 checks passed
@ftynse ftynse deleted the users/ftynse/connect-extract branch February 2, 2026 10:09
harsh-nod pushed a commit that referenced this pull request Feb 3, 2026
Both require special-casing to convert attributes.

We cannot yet lower this further because extract and shuffle don't have
index sequences, neither they need to after lowering, but we can't
detect that due to

Signed-off-by: Alex Zinenko <git@ozinenko.com>
Signed-off-by: Harsh Menon <harsh.menon@amd.com>
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