20static constexpr uint64_t
kMaxDim = std::numeric_limits<uint32_t>::max();
27 unsigned width = IndexType::kInternalStorageBitWidth;
32static uint64_t
zext(uint32_t arg) {
return static_cast<uint64_t
>(arg); }
43 llvm_unreachable(
"All dimension enum cases handled above");
46static std::optional<uint32_t>
50 case DimensionKind::Other:
52 case DimensionKind::Block:
53 bounds =
func.getKnownBlockSizeAttr();
55 case DimensionKind::Grid:
56 bounds =
func.getKnownGridSizeAttr();
58 case DimensionKind::Cluster:
59 bounds =
func.getKnownClusterSizeAttr();
64 if (bounds.size() <=
static_cast<uint32_t
>(dim))
66 return bounds[
static_cast<uint32_t
>(dim)];
77 if (bounds.size() <=
static_cast<uint32_t
>(dim))
79 return bounds[
static_cast<uint32_t
>(dim)];
82std::optional<uint32_t>
88 case DimensionKind::Other:
90 case DimensionKind::Block:
91 bounds = launch.getBlockSizeOperandValues();
93 case DimensionKind::Grid:
94 bounds = launch.getGridSizeOperandValues();
96 case DimensionKind::Cluster:
97 if (launch.hasClusterSize()) {
98 auto clusterBounds = launch.getClusterSizeOperandValues();
100 bounds = *clusterBounds;
107 return value.getZExtValue();
118 case DimensionKind::Other:
120 case DimensionKind::Block:
121 attrName = GPUDialect::KnownBlockSizeAttrHelper::getNameStr();
123 case DimensionKind::Grid:
124 attrName = GPUDialect::KnownGridSizeAttrHelper::getNameStr();
126 case DimensionKind::Cluster:
127 attrName = GPUDialect::KnownClusterSizeAttrHelper::getNameStr();
132 return discardableAttr;
141 max = specified->getZExtValue();
149 return setResultRange(getResult(),
154 max = specified->getZExtValue();
162 max = specified->getZExtValue();
173 max = specified->getZExtValue();
179 std::optional<uint32_t> knownVal =
182 return setResultRange(getResult(),
187 max = specified->getZExtValue();
198 max = specified->getZExtValue();
204 std::optional<uint32_t> knownVal =
207 return setResultRange(getResult(),
211 max = specified->getZExtValue();
219 *
this, DimensionKind::Block, getDimension()))
222 max = specified->getZExtValue();
230 max = specified->getZExtValue();
238 max = specified->getZExtValue();
245 return setResultRange(getResult(),
248 uint64_t blockDimMax =
zext(
251 uint64_t gridDimMax =
zext(
254 setResultRange(getResult(),
262 max = specified->getZExtValue();
270 max = specified->getZExtValue();
278 if (argRange.
umin().getBitWidth() != IndexType::kInternalStorageBitWidth)
282 setResultRange(dimResult, dimRange);
285 setResultRange(idxResult, idxRange);
288 argRanges = argRanges.drop_front(getAsyncDependencies().size());
291 setRange(argRanges[0], gridDims.
x, blockIds.
x);
292 setRange(argRanges[1], gridDims.
y, blockIds.
y);
293 setRange(argRanges[2], gridDims.
z, blockIds.
z);
296 setRange(argRanges[3], blockDims.
x, threadIds.
x);
297 setRange(argRanges[4], blockDims.
y, threadIds.
y);
298 setRange(argRanges[5], blockDims.
z, threadIds.
z);
300 if (
auto clusterIds = getClusterIds()) {
302 auto setClusterRange = [&](
unsigned dim,
Value dimResult,
Value idxResult) {
303 unsigned clusterOperandIndex = kNumConfigOperands + dim;
305 IndexType::kInternalStorageBitWidth ||
306 argRanges[clusterOperandIndex].umin().
getBitWidth() !=
307 IndexType::kInternalStorageBitWidth)
314 argRanges[clusterOperandIndex].intersection(
319 setClusterRange(0, clusterDims.
x, clusterIds->x);
320 setClusterRange(1, clusterDims.
y, clusterIds->y);
321 setClusterRange(2, clusterDims.
z, clusterIds->z);
static std::optional< int64_t > getUpperBound(Value iv)
Gets the constant upper bound on an affine.for iv.
static unsigned getBitWidth(Type type)
static std::optional< uint32_t > getKnownLaunchAttr(GPUFuncOp func, DimensionKind dims, Dimension dim)
static Value valueByDim(KernelDim3 dims, Dimension dim)
static constexpr uint64_t kMaxClusterDim
static constexpr uint64_t kMaxDim
static uint64_t zext(uint32_t arg)
static ConstantIntRanges getIndexRange(uint64_t umin, uint64_t umax)
static constexpr uint64_t kMaxSubgroupSize
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
A set of arbitrary-precision integers representing bounds on a given integer value.
static ConstantIntRanges fromUnsigned(const APInt &umin, const APInt &umax)
Create an ConstantIntRanges with the unsigned minimum and maximum equal to umin and umax and the sign...
ConstantIntRanges intersection(const ConstantIntRanges &other) const
Returns the intersection (computed separately for signed and unsigned bounds) of this range and other...
const APInt & umax() const
The maximum value of an integer when it is interpreted as unsigned.
const APInt & umin() const
The minimum value of an integer when it is interpreted as unsigned.
Operation is the basic unit of execution within MLIR.
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
std::optional< uint32_t > getKnownDimensionSizeAround(Operation *op, DimensionKind kind, Dimension dim)
Retrieve the constant bounds for a given dimension and dimension kind from the context surrounding op...
ConstantIntRanges inferDivU(ArrayRef< ConstantIntRanges > argRanges)
SmallVector< unsigned > getBlockSize(AffineMap dimToLvl)
Given the dimToLvl map, returns the block sizes in a vector.
Include the generated interface declarations.
bool matchPattern(Value value, const Pattern &pattern)
Entry point for matching a pattern over a Value.
detail::constant_int_value_binder m_ConstantInt(IntegerAttr::ValueType *bind_value)
Matches a constant holding a scalar/vector/tensor integer (splat) and writes the integer value to bin...
llvm::function_ref< void(Value, const ConstantIntRanges &)> SetIntRangeFn
The type of the setResultRanges callback provided to ops implementing InferIntRangeInterface.
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
Utility class for the GPU dialect to represent triples of Values accessible through ....