19static constexpr uint64_t
kMaxDim = std::numeric_limits<uint32_t>::max();
26 unsigned width = IndexType::kInternalStorageBitWidth;
31static uint64_t
zext(uint32_t arg) {
return static_cast<uint64_t
>(arg); }
42 llvm_unreachable(
"All dimension enum cases handled above");
45static std::optional<uint32_t>
49 case DimensionKind::Other:
51 case DimensionKind::Block:
52 bounds =
func.getKnownBlockSizeAttr();
54 case DimensionKind::Grid:
55 bounds =
func.getKnownGridSizeAttr();
57 case DimensionKind::Cluster:
58 bounds =
func.getKnownClusterSizeAttr();
63 if (bounds.size() <=
static_cast<uint32_t
>(dim))
65 return bounds[
static_cast<uint32_t
>(dim)];
76 if (bounds.size() <=
static_cast<uint32_t
>(dim))
78 return bounds[
static_cast<uint32_t
>(dim)];
81std::optional<uint32_t>
87 case DimensionKind::Other:
89 case DimensionKind::Block:
90 bounds = launch.getBlockSizeOperandValues();
92 case DimensionKind::Grid:
93 bounds = launch.getGridSizeOperandValues();
95 case DimensionKind::Cluster:
96 if (launch.hasClusterSize()) {
97 auto clusterBounds = launch.getClusterSizeOperandValues();
99 bounds = *clusterBounds;
106 return value.getZExtValue();
117 case DimensionKind::Other:
119 case DimensionKind::Block:
120 attrName = GPUDialect::KnownBlockSizeAttrHelper::getNameStr();
122 case DimensionKind::Grid:
123 attrName = GPUDialect::KnownGridSizeAttrHelper::getNameStr();
125 case DimensionKind::Cluster:
126 attrName = GPUDialect::KnownClusterSizeAttrHelper::getNameStr();
131 return discardableAttr;
140 max = specified->getZExtValue();
148 return setResultRange(getResult(),
153 max = specified->getZExtValue();
161 max = specified->getZExtValue();
172 max = specified->getZExtValue();
178 std::optional<uint32_t> knownVal =
181 return setResultRange(getResult(),
186 max = specified->getZExtValue();
197 max = specified->getZExtValue();
203 std::optional<uint32_t> knownVal =
206 return setResultRange(getResult(),
210 max = specified->getZExtValue();
218 *
this, DimensionKind::Block, getDimension()))
221 max = specified->getZExtValue();
229 max = specified->getZExtValue();
237 max = specified->getZExtValue();
244 return setResultRange(getResult(),
247 uint64_t blockDimMax =
zext(
250 uint64_t gridDimMax =
zext(
253 setResultRange(getResult(),
261 max = specified->getZExtValue();
269 max = specified->getZExtValue();
277 if (argRange.
umin().getBitWidth() != IndexType::kInternalStorageBitWidth)
281 setResultRange(dimResult, dimRange);
284 setResultRange(idxResult, idxRange);
287 argRanges = argRanges.drop_front(getAsyncDependencies().size());
290 setRange(argRanges[0], gridDims.
x, blockIds.
x);
291 setRange(argRanges[1], gridDims.
y, blockIds.
y);
292 setRange(argRanges[2], gridDims.
z, blockIds.
z);
295 setRange(argRanges[3], blockDims.
x, threadIds.
x);
296 setRange(argRanges[4], blockDims.
y, threadIds.
y);
297 setRange(argRanges[5], blockDims.
z, threadIds.
z);
static std::optional< int64_t > getUpperBound(Value iv)
Gets the constant upper bound on an affine.for iv.
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...
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 ....