13 #include "llvm/Support/ErrorHandling.h"
27 unsigned width = IndexType::kInternalStorageBitWidth;
33 enum class LaunchDims : uint32_t {
Block = 0,
Grid = 1 };
51 llvm_unreachable(
"All dimension enum cases handled above");
54 static uint64_t
zext(uint32_t arg) {
return static_cast<uint64_t
>(arg); }
56 static std::optional<uint64_t>
60 case LaunchDims::Block:
61 bounds = func.getKnownBlockSizeAttr();
63 case LaunchDims::Grid:
64 bounds = func.getKnownGridSizeAttr();
69 if (bounds.size() <
static_cast<uint32_t
>(dim))
71 return zext(bounds[
static_cast<uint32_t
>(dim)]);
80 if (bounds.size() <
static_cast<uint32_t
>(dim))
82 return zext(bounds[
static_cast<uint32_t
>(dim)]);
85 template <
typename Op>
87 Dimension dim = op.getDimension();
88 if (
auto launch = op->template getParentOfType<LaunchOp>()) {
91 case LaunchDims::Block:
92 bounds = launch.getBlockSizeOperandValues();
94 case LaunchDims::Grid:
95 bounds = launch.getGridSizeOperandValues();
101 return value.getZExtValue();
104 if (
auto gpuFunc = op->template getParentOfType<GPUFuncOp>()) {
109 if (
auto func = op->template getParentOfType<FunctionOpInterface>()) {
112 case LaunchDims::Block:
113 attrName = GPUDialect::KnownBlockSizeAttrHelper::getNameStr();
115 case LaunchDims::Grid:
116 attrName = GPUDialect::KnownGridSizeAttrHelper::getNameStr();
121 return discardableAttr;
130 max = specified->getZExtValue();
138 max = specified->getZExtValue();
146 max = specified->getZExtValue();
154 max = specified->getZExtValue();
160 std::optional<uint64_t> knownVal =
163 return setResultRange(getResult(),
getIndexRange(*knownVal, *knownVal));
167 max = specified->getZExtValue();
175 max = fromContext.value();
177 max = specified->getZExtValue();
185 return setResultRange(getResult(),
getIndexRange(*knownVal, *knownVal));
188 max = specified->getZExtValue();
196 max = fromContext.value();
198 max = specified->getZExtValue();
206 max = specified->getZExtValue();
214 max = specified->getZExtValue();
221 return setResultRange(getResult(),
224 uint64_t blockDimMax =
226 uint64_t gridDimMax =
228 setResultRange(getResult(),
236 max = specified->getZExtValue();
244 max = specified->getZExtValue();
252 if (argRange.
umin().getBitWidth() != IndexType::kInternalStorageBitWidth)
256 setResultRange(dimResult, dimRange);
259 setResultRange(idxResult, idxRange);
262 argRanges = argRanges.drop_front(getAsyncDependencies().size());
265 setRange(argRanges[0], gridDims.
x, blockIds.
x);
266 setRange(argRanges[1], gridDims.
y, blockIds.
y);
267 setRange(argRanges[2], gridDims.
z, blockIds.
z);
270 setRange(argRanges[3], blockDims.
x, threadIds.
x);
271 setRange(argRanges[4], blockDims.
y, threadIds.
y);
272 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 Value valueByDim(KernelDim3 dims, Dimension dim)
If the operation op is in a context that is annotated with maximum launch dimensions (a launch op wit...
static constexpr uint64_t kMaxClusterDim
static std::optional< uint64_t > getKnownLaunchDim(Op op, LaunchDims type)
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 std::optional< uint64_t > getKnownLaunchAttr(GPUFuncOp func, LaunchDims dims, Dimension dim)
static Value max(ImplicitLocOpBuilder &builder, Value value, Value bound)
Block represents an ordered list of Operations.
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.
This provides public APIs that all operations should have.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
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...
Utility class for the GPU dialect to represent triples of Values accessible through ....