25struct GpuIdOpInterface
26 :
public ValueBoundsOpInterface::ExternalModel<GpuIdOpInterface<Op>, Op> {
27 void populateBoundsForIndexValue(Operation *op, Value value,
28 ValueBoundsConstraintSet &cstr)
const {
29 auto inferrable = cast<InferIntRangeInterface>(op);
31 "inferring for value that isn't the GPU op's result");
32 auto translateConstraint = [&](Value v,
const ConstantIntRanges &range) {
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);
43struct GpuLaunchOpInterface
44 :
public ValueBoundsOpInterface::ExternalModel<GpuLaunchOpInterface,
46 void populateBoundsForIndexValue(Operation *op, Value value,
47 ValueBoundsConstraintSet &cstr)
const {
48 auto launchOp = cast<LaunchOp>(op);
50 Value sizeArg =
nullptr;
52 KernelDim3 gridSizeArgs = launchOp.getGridSizeOperandValues();
53 KernelDim3 blockSizeArgs = launchOp.getBlockSizeOperandValues();
55 auto match = [&](KernelDim3 bodyArgs, KernelDim3 externalArgs,
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);
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.
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
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.
void registerValueBoundsOpInterfaceExternalModels(DialectRegistry ®istry)
Include the generated interface declarations.