24 template <
typename Op>
25 struct GpuIdOpInterface
26 :
public ValueBoundsOpInterface::ExternalModel<GpuIdOpInterface<Op>, Op> {
29 auto inferrable = cast<InferIntRangeInterface>(op);
31 "inferring for value that isn't the GPU op's result");
34 "GPU ID op inferring values for something that's not its result");
35 cstr.
bound(v) >= range.smin().getSExtValue();
36 cstr.
bound(v) <= range.smax().getSExtValue();
38 assert(inferrable->getNumOperands() == 0 &&
"ID ops have no operands");
39 inferrable.inferResultRanges({}, translateConstraint);
43 struct GpuLaunchOpInterface
44 :
public ValueBoundsOpInterface::ExternalModel<GpuLaunchOpInterface,
48 auto launchOp = cast<LaunchOp>(op);
50 Value sizeArg =
nullptr;
52 KernelDim3 gridSizeArgs = launchOp.getGridSizeOperandValues();
53 KernelDim3 blockSizeArgs = launchOp.getBlockSizeOperandValues();
57 if (value == bodyArgs.
x) {
58 sizeArg = externalArgs.x;
61 if (value == bodyArgs.
y) {
62 sizeArg = externalArgs.y;
65 if (value == bodyArgs.
z) {
66 sizeArg = externalArgs.z;
70 match(launchOp.getThreadIds(), blockSizeArgs,
false);
71 match(launchOp.getBlockSize(), blockSizeArgs,
true);
72 match(launchOp.getBlockIds(), gridSizeArgs,
false);
73 match(launchOp.getGridSize(), gridSizeArgs,
true);
74 if (launchOp.hasClusterSize()) {
75 KernelDim3 clusterSizeArgs = *launchOp.getClusterSizeOperandValues();
76 match(*launchOp.getClusterIds(), clusterSizeArgs,
false);
77 match(*launchOp.getClusterSize(), clusterSizeArgs,
true);
84 cstr.
bound(value) >= 1;
87 cstr.
bound(value) >= 0;
96 #define REGISTER(X) X::attachInterface<GpuIdOpInterface<X>>(*ctx);
112 LaunchOp::attachInterface<GpuLaunchOpInterface>(*ctx);
A set of arbitrary-precision integers representing bounds on a given integer value.
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
A helper class to be used with ValueBoundsOpInterface.
AffineExpr getExpr(Value value, std::optional< int64_t > dim=std::nullopt)
Return an expression that represents the given index-typed value or shaped value dimension.
BoundBuilder bound(Value value)
Add a bound for the given index-typed value or shaped value.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
void registerValueBoundsOpInterfaceExternalModels(DialectRegistry ®istry)
Include the generated interface declarations.
Utility class for the GPU dialect to represent triples of Values accessible through ....