13 #include "llvm/ADT/STLForwardCompat.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/MathExtras.h"
29 unsigned width = IndexType::kInternalStorageBitWidth;
35 enum class LaunchDims : uint32_t {
Block = 0,
Grid = 1 };
53 llvm_unreachable(
"All dimension enum cases handled above");
56 static uint64_t
zext(uint32_t arg) {
return static_cast<uint64_t
>(arg); }
58 static std::optional<uint64_t>
62 case LaunchDims::Block:
63 bounds = func.getKnownBlockSizeAttr();
65 case LaunchDims::Grid:
66 bounds = func.getKnownGridSizeAttr();
71 if (bounds.size() <
static_cast<uint32_t
>(dim))
73 return zext(bounds[
static_cast<uint32_t
>(dim)]);
82 if (bounds.size() <
static_cast<uint32_t
>(dim))
84 return zext(bounds[
static_cast<uint32_t
>(dim)]);
87 template <
typename Op>
89 Dimension dim = op.getDimension();
90 if (
auto launch = op->template getParentOfType<LaunchOp>()) {
93 case LaunchDims::Block:
94 bounds = launch.getBlockSizeOperandValues();
96 case LaunchDims::Grid:
97 bounds = launch.getGridSizeOperandValues();
103 return value.getZExtValue();
106 if (
auto gpuFunc = op->template getParentOfType<GPUFuncOp>()) {
111 if (
auto func = op->template getParentOfType<FunctionOpInterface>()) {
114 case LaunchDims::Block:
115 attrName = GPUDialect::KnownBlockSizeAttrHelper::getNameStr();
117 case LaunchDims::Grid:
118 attrName = GPUDialect::KnownGridSizeAttrHelper::getNameStr();
123 return discardableAttr;
132 max = specified->getZExtValue();
140 max = specified->getZExtValue();
148 max = specified->getZExtValue();
156 max = specified->getZExtValue();
162 std::optional<uint64_t> knownVal =
165 return setResultRange(getResult(),
getIndexRange(*knownVal, *knownVal));
169 max = specified->getZExtValue();
177 max = fromContext.value();
179 max = specified->getZExtValue();
187 return setResultRange(getResult(),
getIndexRange(*knownVal, *knownVal));
190 max = specified->getZExtValue();
198 max = fromContext.value();
200 max = specified->getZExtValue();
208 max = specified->getZExtValue();
216 max = specified->getZExtValue();
223 return setResultRange(getResult(),
226 uint64_t blockDimMax =
228 uint64_t gridDimMax =
230 setResultRange(getResult(),
238 max = specified->getZExtValue();
246 max = specified->getZExtValue();
254 if (argRange.
umin().getBitWidth() != IndexType::kInternalStorageBitWidth)
258 setResultRange(dimResult, dimRange);
261 setResultRange(idxResult, idxRange);
264 argRanges = argRanges.drop_front(getAsyncDependencies().size());
267 setRange(argRanges[0], gridDims.
x, blockIds.
x);
268 setRange(argRanges[1], gridDims.
y, blockIds.
y);
269 setRange(argRanges[2], gridDims.
z, blockIds.
z);
272 setRange(argRanges[3], blockDims.
x, threadIds.
x);
273 setRange(argRanges[4], blockDims.
y, threadIds.
y);
274 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 ....