Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][GPU] Add builders to allow passing in integer upper_bounds #114252

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,20 @@ class GPU_IndexOp<string mnemonic, list<Trait> traits = []> :
}]>,
OpBuilder<(ins "::mlir::Type":$resultType, "::mlir::gpu::Dimension":$dimension), [{
build($_builder, $_state, resultType, dimension, /*upperBound=*/nullptr);
}]>,
OpBuilder<(ins "::mlir::gpu::Dimension":$dimension, "std::optional<int64_t>":$upperBound), [{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it optional?

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 that you can explicitly pass in std::nullopt to leave the bound unset

Copy link
Contributor

Choose a reason for hiding this comment

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

I also don't get what convenience does it bring. Why would you demand a nullopt when there can be two builders: with and without the attribute/whatever? Or if we want a single builder - a default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

upper_bound is a fundamentally optional property.

This is designed to make people's lives easier when they're in possession of something like an ArrayRef<int64_t> blockSizes.

I'll note we already have the attribute-less builder.

The advantage to having this be optional is that there's downstream code that either optionally knows the block sizes or optionally wants to forget about them.

::mlir::IntegerAttr upperBoundAttr = nullptr;
if (upperBound.has_value())
upperBoundAttr = $_builder.getIndexAttr(*upperBound);
build($_builder, $_state, dimension, upperBoundAttr);
}]>,
OpBuilder<(ins "::mlir::Type":$resultType, "::mlir::gpu::Dimension":$dimension, "std::optional<int64_t>":$upperBound), [{
::mlir::IntegerAttr upperBoundAttr = nullptr;
if (upperBound.has_value())
upperBoundAttr = $_builder.getIndexAttr(*upperBound);
build($_builder, $_state, resultType, dimension, upperBoundAttr);
}]>

];
}

Expand Down
Loading