16#include "llvm/ADT/SmallVectorExtras.h"
17#include "llvm/ADT/TypeSwitch.h"
18#include "llvm/Support/Debug.h"
25void XeGPUDialect::initialize() {
27#define GET_TYPEDEF_LIST
28#include <mlir/Dialect/XeGPU/IR/XeGPUTypes.cpp.inc>
32#include <mlir/Dialect/XeGPU/IR/XeGPU.cpp.inc>
35#define GET_ATTRDEF_LIST
36#include <mlir/Dialect/XeGPU/IR/XeGPUAttrs.cpp.inc>
39#define GET_OP_INTERFACE_CLASSES
40#include "mlir/Dialect/XeGPU/IR/XeGPUOpInterface.cpp.inc"
59 llvm::zip_equal(srcShape,
61 [](
const auto &t) {
return std::min(std::get<0>(t), std::get<1>(t)); });
65 llvm::zip(delinearizedId, subShape), [&](
const auto &t) ->
Value {
81 llvm::map_to_vector(llvm::zip_equal(base, distUnitLocalOffset),
82 [&](
const auto &t) ->
Value {
84 loc, std::get<0>(t), std::get<1>(t));
88 llvm::zip_equal(adds, srcShape), [&](
const auto &t) ->
Value {
94 coordinates.push_back(mods);
104 for (
size_t i = 0; i <
shape.size(); ++i)
105 distUnitShape[i] = std::min(
shape[i], layout[i] * subShape[i]);
109 for (
size_t i = 0; i <
shape.size(); ++i)
110 localOffset[i] = canonicalIds[i] * subShape[i];
117 for (
size_t i = 0; i <
shape.size(); ++i)
118 coord[i] = (unitOffs[i] + localOffset[i]) %
shape[i];
119 coordinates.push_back(coord);
127 xegpu::DistributeLayoutAttr attr) {
128 assert(attr &&
"Layout attribute is missing.");
145 if (layout.size() !=
shape.size())
148 if (ratio.has_value()) {
149 newShape = ratio.value();
157 if (data.size() != shape.size())
160 if (!ratio.has_value() && rr)
162 if (!ratio.has_value())
172 auto maybeSgShape = tryDistribute(shape, attr.getEffectiveSgLayoutAsInt(),
173 attr.getEffectiveSgDataAsInt());
176 auto sgShape = maybeSgShape.value();
179 auto maybeInstShape =
180 tryDistribute(sgShape, {}, attr.getEffectiveInstDataAsInt(),
false);
183 auto instShape = maybeInstShape.value();
186 auto maybeLaneShape =
187 tryDistribute(instShape, attr.getEffectiveLaneLayoutAsInt(),
188 attr.getEffectiveLaneDataAsInt());
189 return maybeLaneShape.has_value();
195BlockTensorDescAttr BlockTensorDescAttr::get(mlir::MLIRContext *context,
196 xegpu::MemorySpace memory_space,
198 bool boundary_check) {
199 auto scopeAttr = MemorySpaceAttr::get(context, memory_space);
201 IntegerAttr::get(IntegerType::get(context, 64), array_length);
203 return Base::get(context, scopeAttr, lengthAttr, boundaryAttr);
206bool BlockTensorDescAttr::hasDefaultsOnly() {
207 return getMemorySpace().getValue() == xegpu::MemorySpace::Global &&
208 getArrayLength().getInt() == 1 && getBoundaryCheck().getValue();
215ScatterTensorDescAttr::get(mlir::MLIRContext *context,
216 xegpu::MemorySpace memory_space,
int chunk_size) {
217 auto scopeAttr = MemorySpaceAttr::get(context, memory_space);
219 IntegerAttr::get(IntegerType::get(context, 64), chunk_size);
220 return Base::get(context, scopeAttr, chunkSizeAttr);
223LogicalResult ScatterTensorDescAttr::verify(
224 llvm::function_ref<mlir::InFlightDiagnostic()>
emitError,
225 MemorySpaceAttr memory_space, IntegerAttr chunk_size) {
226 int64_t chunkSize = chunk_size.getInt();
228 return emitError() <<
"invalid chunk size";
237LayoutAttr::verify(llvm::function_ref<mlir::InFlightDiagnostic()>
emitError,
243 if (!sg_layout && !inst_data && !lane_layout)
249 if (sg_layout && inst_data && sg_layout.size() != inst_data.size()) {
251 <<
"expected sg_layout and inst_data to have the same rank";
254 if (sg_layout && lane_layout && sg_layout.size() != lane_layout.size()) {
256 <<
"expected sg_layout and lane_layout to have the same rank";
259 if (inst_data && lane_layout && inst_data.size() != lane_layout.size()) {
260 return emitError() <<
"expected inst_data and lane_layout to have the same "
261 "rank, got inst_data "
262 << inst_data.size() <<
", lane_layout "
263 << lane_layout.size();
266 if ((sg_layout && !sg_data) || (!sg_layout && sg_data))
267 return emitError() <<
"sg_layout and sg_data must be used together";
268 if (sg_layout && sg_data && sg_layout.size() != sg_data.size())
270 <<
"expected sg_data and sg_layout to have the same rank";
272 if ((lane_layout && !lane_data) || (!lane_layout && lane_data))
273 return emitError() <<
"lane_layout and lane_data must be used together";
274 if (lane_layout && lane_data && lane_layout.size() != lane_data.size())
276 <<
"expected lane_data and lane_layout to have the same rank";
279 if (!sg_layout && !lane_layout)
281 <<
"expected sg_layout/lane_layout being used with order";
283 if (sg_layout && order.size() != sg_layout.size())
285 <<
"expected order and sg_layout to have the same rank";
287 if (lane_layout && order.size() != lane_layout.size())
289 <<
"expected order and lane_layout to have the same rank";
295FailureOr<SmallVector<Value>>
296LayoutAttr::delinearizeId(OpBuilder &builder, Location loc, Value linearId) {
298 SmallVector<int64_t> sgLayoutInt;
299 if (isForWorkgroup()) {
300 sgLayoutInt = getEffectiveSgLayoutAsInt();
301 }
else if (isForSubgroup()) {
302 sgLayoutInt = getEffectiveLaneLayoutAsInt();
310 SmallVector<int64_t> order;
311 if (orderAttr && !orderAttr.empty()) {
312 order = llvm::map_to_vector(orderAttr.
asArrayRef(), [](int32_t idx) {
313 return static_cast<int64_t>(idx);
317 order = llvm::to_vector(
318 llvm::reverse(llvm::seq<int64_t>(0, sgLayoutInt.size())));
321 if (order.size() != sgLayoutInt.size()) {
325 SmallVector<Value>
result(sgLayoutInt.size());
326 Value remaining = linearId;
349 for (
size_t i = 0; i < order.size(); ++i) {
350 int64_t dimIdx = order[i];
351 int64_t dimSize = sgLayoutInt[dimIdx];
354 builder.
createOrFold<arith::ConstantIndexOp>(loc, dimSize);
361 builder.
createOrFold<arith::RemUIOp>(loc, remaining, dimSizeVal);
368 if (i < order.size() - 1) {
370 builder.
createOrFold<arith::DivUIOp>(loc, remaining, dimSizeVal);
379FailureOr<SmallVector<SmallVector<Value>>>
380LayoutAttr::computeDistributedCoords(OpBuilder &builder, Location loc,
381 Value linearId, ArrayRef<int64_t> shape) {
382 SmallVector<int64_t> layout;
383 SmallVector<int64_t> subShape;
384 if (isForWorkgroup()) {
385 layout = getEffectiveSgLayoutAsInt();
386 subShape = getEffectiveSgDataAsInt();
387 }
else if (isForSubgroup()) {
388 layout = getEffectiveLaneLayoutAsInt();
389 subShape = getEffectiveLaneDataAsInt();
393 assert(!subShape.empty() &&
"sgdata or lanedata cannot be empty for "
394 "distributed coordinates computation");
397 auto maybeIds = delinearizeId(builder, loc, linearId);
400 SmallVector<Value> ids = *maybeIds;
402 return genCoordinates(builder, loc, ids, layout, subShape, shape);
405bool LayoutAttr::isEqualTo(
const xegpu::DistributeLayoutAttr &other) {
406 if (dyn_cast<xegpu::SliceAttr>(other))
409 return *
this == dyn_cast<xegpu::LayoutAttr>(other);
415SmallVector<SmallVector<int64_t>>
416LayoutAttr::computeStaticDistributedCoords(int64_t linearId,
417 ArrayRef<int64_t> shape) {
418 SmallVector<int64_t> layoutVec;
419 SmallVector<int64_t> subShape;
420 SmallVector<int64_t> instData;
421 if (isForWorkgroup()) {
422 layoutVec = getEffectiveSgLayoutAsInt();
423 subShape = getEffectiveSgDataAsInt();
424 }
else if (isForSubgroup()) {
425 instData = getEffectiveInstDataAsInt();
426 layoutVec = getEffectiveLaneLayoutAsInt();
427 subShape = getEffectiveLaneDataAsInt();
429 if (!instData.empty()) {
433 assert(!subShape.empty() &&
"sgdata or lanedata cannot be empty");
436 SmallVector<int64_t> order = getEffectiveOrderAsInt();
437 SmallVector<int64_t> delinearizedId(layoutVec.size());
438 int64_t remaining = linearId;
439 for (
size_t i = 0; i < order.size(); ++i) {
440 int64_t dimIdx = order[i];
441 delinearizedId[dimIdx] = remaining % layoutVec[dimIdx];
442 remaining = remaining / layoutVec[dimIdx];
450LayoutAttr::setUnitDimData(SmallVector<int64_t> unitDims)
const {
451 auto sgDataOpt = getSgData();
452 auto instDataOpt = getInstData();
453 auto laneDataOpt = getLaneData();
455 SmallVector<int32_t> sgData;
456 SmallVector<int32_t> instData;
457 SmallVector<int32_t> laneData;
460 sgData = llvm::to_vector(sgDataOpt.asArrayRef());
463 instData = llvm::to_vector(instDataOpt.asArrayRef());
466 laneData = llvm::to_vector(laneDataOpt.asArrayRef());
468 for (
auto dim : unitDims) {
469 if (dim <
static_cast<int64_t
>(sgData.size()))
471 if (dim <
static_cast<int64_t
>(instData.size()))
473 if (dim <
static_cast<int64_t
>(laneData.size()))
477 return LayoutAttr::get(
491LayoutAttr::setUnitDimLayout(SmallVector<int64_t> unitDims)
const {
492 auto sgLayoutOpt = getSgLayout();
493 auto laneLayoutOpt = getLaneLayout();
495 SmallVector<int32_t> sgLayout;
496 SmallVector<int32_t> laneLayout;
499 sgLayout = llvm::to_vector(sgLayoutOpt.asArrayRef());
501 laneLayout = llvm::to_vector(laneLayoutOpt.asArrayRef());
503 for (
auto dim : unitDims) {
504 if (dim <
static_cast<int64_t
>(sgLayout.size()))
506 if (dim <
static_cast<int64_t
>(laneLayout.size()))
510 return LayoutAttr::get(
514 getSgData(), getInstData(),
517 getLaneData(), getOrder());
522DistributeLayoutAttr LayoutAttr::setDimData(int64_t dim, int64_t sgData,
526 SmallVector<int64_t> sgDataVec = getEffectiveSgDataAsInt();
527 SmallVector<int64_t> instDataVec = getEffectiveInstDataAsInt();
528 SmallVector<int64_t> laneDataVec = getEffectiveLaneDataAsInt();
530 if (dim <
static_cast<int64_t
>(sgDataVec.size()) && sgData != -1)
531 sgDataVec[dim] = sgData;
532 if (dim <
static_cast<int64_t
>(instDataVec.size()) && instData != -1)
533 instDataVec[dim] = instData;
534 if (dim <
static_cast<int64_t
>(laneDataVec.size()) && laneData != -1)
535 laneDataVec[dim] = laneData;
537 SmallVector<int32_t> sgDataVec32(sgDataVec.begin(), sgDataVec.end());
538 SmallVector<int32_t> instDataVec32(instDataVec.begin(), instDataVec.end());
539 SmallVector<int32_t> laneDataVec32(laneDataVec.begin(), laneDataVec.end());
541 return LayoutAttr::get(
556DistributeLayoutAttr LayoutAttr::dropDims(SmallVector<int64_t> dimGroup) {
558 SmallVector<int64_t> sgLayout = getEffectiveSgLayoutAsInt();
559 SmallVector<int64_t> sgData = getEffectiveSgDataAsInt();
560 SmallVector<int64_t> instData = getEffectiveInstDataAsInt();
561 SmallVector<int64_t> laneLayout = getEffectiveLaneLayoutAsInt();
562 SmallVector<int64_t> laneData = getEffectiveLaneDataAsInt();
563 SmallVector<int64_t> origOrder = getEffectiveOrderAsInt();
565 SmallVector<int64_t> sortedDimGroup = dimGroup;
566 llvm::sort(sortedDimGroup);
568 for (
auto dimIdx : llvm::reverse(sortedDimGroup)) {
569 if (!sgLayout.empty()) {
570 sgLayout.erase(sgLayout.begin() + dimIdx);
571 sgData.erase(sgData.begin() + dimIdx);
573 if (!instData.empty())
574 instData.erase(instData.begin() + dimIdx);
575 if (!laneLayout.empty()) {
576 laneLayout.erase(laneLayout.begin() + dimIdx);
577 laneData.erase(laneData.begin() + dimIdx);
581 SmallVector<int64_t> newOrder;
582 for (int64_t d : origOrder) {
583 if (llvm::is_contained(dimGroup, d))
585 int64_t offset = llvm::count_if(dimGroup, [&](int64_t s) {
return s < d; });
586 newOrder.push_back(d - offset);
588 if (sgLayout.empty() && laneLayout.empty())
594 SmallVector<int32_t> v32(v.begin(), v.end());
597 auto droppedLayout = xegpu::LayoutAttr::get(
598 getContext(), toAttr(sgLayout), toAttr(sgData), toAttr(instData),
599 toAttr(laneLayout), toAttr(laneData), toAttr(newOrder));
600 return droppedLayout;
606DistributeLayoutAttr LayoutAttr::collapseDims(SmallVector<int64_t> dimGroup) {
608 SmallVector<int64_t> sgLayout = getEffectiveSgLayoutAsInt();
609 SmallVector<int64_t> sgData = getEffectiveSgDataAsInt();
610 SmallVector<int64_t> instData = getEffectiveInstDataAsInt();
611 SmallVector<int64_t> laneLayout = getEffectiveLaneLayoutAsInt();
612 SmallVector<int64_t> laneData = getEffectiveLaneDataAsInt();
613 SmallVector<int64_t> origOrder = getEffectiveOrderAsInt();
615 SmallVector<int64_t> sortedDimGroup = dimGroup;
616 llvm::sort(sortedDimGroup);
617 int64_t dimBeforeCurrent = -1;
618 for (
auto dimIdx : sortedDimGroup) {
622 if (dimBeforeCurrent >= 0) {
623 if (getOrder() && !getOrder().empty()) {
624 int64_t orderBefore = origOrder[dimBeforeCurrent];
625 int64_t orderCurrent = origOrder[dimIdx];
626 if (orderBefore != (orderCurrent - 1))
627 llvm::report_fatal_error(
628 "dimensions being collapsed must be adjacent in order");
630 if (dimIdx != (dimBeforeCurrent + 1))
631 llvm::report_fatal_error(
632 "dimensions being collapsed must be adjacent");
635 dimBeforeCurrent = dimIdx;
638 int firstDim = sortedDimGroup.front();
643 if (!sgLayout.empty()) {
644 int64_t collapsedSglayout = 1, collapsedSgData = 1;
645 for (
auto dimIdx : dimGroup) {
646 collapsedSglayout *= sgLayout[dimIdx];
647 collapsedSgData *= sgData[dimIdx];
649 for (
auto dimIdx : llvm::reverse(sortedDimGroup)) {
650 sgLayout.erase(sgLayout.begin() + dimIdx, sgLayout.begin() + dimIdx + 1);
651 sgData.erase(sgData.begin() + dimIdx, sgData.begin() + dimIdx + 1);
653 sgLayout.insert(sgLayout.begin() + firstDim, collapsedSglayout);
654 sgData.insert(sgData.begin() + firstDim, collapsedSgData);
657 if (!instData.empty()) {
658 int64_t collapsedInstData = 1;
659 for (
auto dimIdx : dimGroup)
660 collapsedInstData *= instData[dimIdx];
661 for (
auto dimIdx : llvm::reverse(sortedDimGroup))
662 instData.erase(instData.begin() + dimIdx, instData.begin() + dimIdx + 1);
663 instData.insert(instData.begin() + firstDim, collapsedInstData);
666 if (!laneLayout.empty()) {
667 int64_t collapsedLaneLayout = 1, collapsedLaneData = 1;
668 for (
auto dimIdx : dimGroup) {
669 collapsedLaneLayout *= laneLayout[dimIdx];
670 collapsedLaneData *= laneData[dimIdx];
672 for (
auto dimIdx : llvm::reverse(sortedDimGroup)) {
673 laneLayout.erase(laneLayout.begin() + dimIdx,
674 laneLayout.begin() + dimIdx + 1);
675 laneData.erase(laneData.begin() + dimIdx, laneData.begin() + dimIdx + 1);
677 laneLayout.insert(laneLayout.begin() + firstDim, collapsedLaneLayout);
678 laneData.insert(laneData.begin() + firstDim, collapsedLaneData);
681 SmallVector<int64_t> newOrder;
683 if (orderAttr && !orderAttr.empty()) {
685 for (
auto dimIdx : llvm::reverse(sortedDimGroup)) {
686 if (dimIdx != firstDim)
687 origOrder.erase(origOrder.begin() + dimIdx);
692 llvm::to_vector(llvm::seq<size_t>(0, orderAttr.size()));
696 [&](
size_t a,
size_t b) {
return origOrder[a] < origOrder[
b]; });
698 newOrder = llvm::to_vector(llvm::map_range(
699 indices, [&](
size_t i) {
return static_cast<int64_t
>(i); }));
705 SmallVector<int32_t> v32(v.begin(), v.end());
708 auto collapsedLayout = xegpu::LayoutAttr::get(
709 getContext(), toAttr(sgLayout), toAttr(sgData), toAttr(instData),
710 toAttr(laneLayout), toAttr(laneData), toAttr(newOrder));
711 return collapsedLayout;
715DistributeLayoutAttr LayoutAttr::transposeDims(ArrayRef<int64_t> permutation) {
717 SmallVector<int64_t> origSgLayout = getEffectiveSgLayoutAsInt();
718 SmallVector<int64_t> origSgData = getEffectiveSgDataAsInt();
719 SmallVector<int64_t> origInstData = getEffectiveInstDataAsInt();
720 SmallVector<int64_t> origLaneLayout = getEffectiveLaneLayoutAsInt();
721 SmallVector<int64_t> origLaneData = getEffectiveLaneDataAsInt();
722 SmallVector<int64_t> origOrder = getEffectiveOrderAsInt();
724 SmallVector<int32_t> sgLayout;
725 SmallVector<int32_t> sgData;
726 SmallVector<int32_t> instData;
727 SmallVector<int32_t> laneLayout;
728 SmallVector<int32_t> laneData;
729 SmallVector<int32_t> order;
731 for (int64_t idx : permutation) {
732 if (!origLaneLayout.empty()) {
733 laneLayout.push_back(
static_cast<int32_t
>(origLaneLayout[idx]));
734 laneData.push_back(
static_cast<int32_t
>(origLaneData[idx]));
736 if (!origInstData.empty())
737 instData.push_back(
static_cast<int32_t
>(origInstData[idx]));
738 if (!origSgLayout.empty()) {
739 sgLayout.push_back(
static_cast<int32_t
>(origSgLayout[idx]));
740 sgData.push_back(
static_cast<int32_t
>(origSgData[idx]));
742 order.push_back(
static_cast<int32_t
>(origOrder[idx]));
744 if (origLaneLayout.empty() && origSgLayout.empty())
750 return xegpu::LayoutAttr::get(
getContext(), toAttr(sgLayout), toAttr(sgData),
751 toAttr(instData), toAttr(laneLayout),
752 toAttr(laneData), toAttr(order));
756bool LayoutAttr::isTransposeOf(
const xegpu::DistributeLayoutAttr &other,
757 ArrayRef<int64_t> perm,
761 if (getRank() != other.getRank() ||
762 perm.size() !=
static_cast<size_t>(getRank()))
766 auto checkTranspose = [](ArrayRef<int64_t> dst, ArrayRef<int64_t> src,
767 ArrayRef<int64_t> perm) {
768 for (
const auto &ta : llvm::enumerate(perm)) {
769 if (src[ta.index()] != dst[ta.value()])
775 return checkTranspose(getEffectiveSgLayoutAsInt(),
776 other.getEffectiveSgLayoutAsInt(), perm) &&
777 checkTranspose(getEffectiveSgDataAsInt(),
778 other.getEffectiveSgDataAsInt(), perm) &&
779 checkTranspose(getEffectiveOrderAsInt(),
780 other.getEffectiveOrderAsInt(), perm);
782 return checkTranspose(getEffectiveInstDataAsInt(),
783 other.getEffectiveInstDataAsInt(), perm);
785 return checkTranspose(getEffectiveLaneLayoutAsInt(),
786 other.getEffectiveLaneLayoutAsInt(), perm) &&
787 checkTranspose(getEffectiveLaneDataAsInt(),
788 other.getEffectiveLaneDataAsInt(), perm) &&
789 checkTranspose(getEffectiveOrderAsInt(),
790 other.getEffectiveOrderAsInt(), perm);
795bool LayoutAttr::isCompatibleWith(
const xegpu::DistributeLayoutAttr &other,
796 SmallVector<int64_t> shape,
800 if (getEffectiveOrderAsInt() == other.getEffectiveOrderAsInt()) {
803 if (getEffectiveSgLayoutAsInt() == other.getEffectiveSgLayoutAsInt() &&
804 getEffectiveSgDataAsInt() == other.getEffectiveSgDataAsInt())
807 if (getEffectiveLaneLayoutAsInt() ==
808 other.getEffectiveLaneLayoutAsInt() &&
809 getEffectiveLaneDataAsInt() == other.getEffectiveLaneDataAsInt())
813 auto compareCoordsForAllIds = [&](int64_t size) {
814 for (int64_t
id : llvm::seq<int64_t>(0, size)) {
815 auto coords = computeStaticDistributedCoords(
id, shape);
816 auto otherCoords = other.computeStaticDistributedCoords(
id, shape);
817 if (coords != otherCoords)
825 return compareCoordsForAllIds(wgSize);
828 return (getEffectiveInstDataAsInt() == other.getEffectiveInstDataAsInt());
831 int64_t subgroupSize =
computeProduct(getEffectiveLaneLayoutAsInt());
832 return compareCoordsForAllIds(subgroupSize);
841SliceAttr::verify(llvm::function_ref<InFlightDiagnostic()>
emitError,
845 return emitError() <<
"expected dims attribute";
848 llvm::SmallDenseSet<int64_t> seen;
851 return emitError() <<
"invalid dim (" << dim <<
") in slice attribute.";
852 if (!seen.insert(dim).second)
853 return emitError() <<
"repeated dim (" << dim <<
") in slice attribute.";
858SliceAttr SliceAttr::flatten()
const {
859 xegpu::DistributeLayoutAttr parent = getParent();
860 SmallVector<DenseI64ArrayAttr> slicedDims({
getDims()});
862 while (
auto sliceAttr = dyn_cast<xegpu::SliceAttr>(parent)) {
863 parent = sliceAttr.getParent();
864 slicedDims.push_back(sliceAttr.getDims());
867 auto layoutAttr = dyn_cast<xegpu::LayoutAttr>(parent);
869 llvm::to_vector(llvm::seq<int64_t>(0, layoutAttr.getRank()));
872 SmallVector<int64_t> remainingDims(
indices);
873 for (
auto dim : llvm::reverse(slicedDims))
874 remainingDims = XeGPUDialect::slice(llvm::ArrayRef<int64_t>(remainingDims),
878 SmallVector<int64_t> flattendDims = XeGPUDialect::slice(
879 llvm::ArrayRef<int64_t>(
indices), llvm::ArrayRef<int64_t>(remainingDims));
881 return xegpu::SliceAttr::get(
886FailureOr<SmallVector<Value>>
887SliceAttr::delinearizeId(OpBuilder &builder, Location loc, Value linearId) {
888 SliceAttr attr = flatten();
889 auto parent = dyn_cast<LayoutAttr>(attr.getParent());
890 return parent.delinearizeId(builder, loc, linearId);
896FailureOr<SmallVector<SmallVector<Value>>>
897SliceAttr::computeDistributedCoords(OpBuilder &builder, Location loc,
898 Value linearId, ArrayRef<int64_t> shape) {
899 assert(getRank() ==
static_cast<int64_t
>(shape.size()) &&
"invalid shape.");
901 SmallVector<int64_t> layout;
902 SmallVector<int64_t> subShape;
903 if (isForWorkgroup()) {
904 layout = getEffectiveSgLayoutAsInt();
905 subShape = getEffectiveSgDataAsInt();
906 }
else if (isForSubgroup()) {
907 layout = getEffectiveLaneLayoutAsInt();
908 subShape = getEffectiveLaneDataAsInt();
913 if (subShape.empty())
917 auto maybeIds = delinearizeId(builder, loc, linearId);
923 ArrayRef<int64_t> dims = flatten().getDims().
asArrayRef();
924 SmallVector<Value> canonicalIds =
925 XeGPUDialect::slice(ArrayRef<Value>(*maybeIds), dims);
927 return genCoordinates(builder, loc, canonicalIds, layout, subShape, shape);
934SmallVector<SmallVector<int64_t>>
935SliceAttr::computeStaticDistributedCoords(int64_t linearId,
936 ArrayRef<int64_t> shape) {
937 assert(getRank() ==
static_cast<int64_t
>(shape.size()) &&
"invalid shape.");
939 SmallVector<int64_t> layout;
940 SmallVector<int64_t> subShape;
941 SmallVector<int64_t> instData;
942 if (isForWorkgroup()) {
943 layout = getEffectiveSgLayoutAsInt();
944 subShape = getEffectiveSgDataAsInt();
945 }
else if (isForSubgroup()) {
946 instData = getEffectiveInstDataAsInt();
947 layout = getEffectiveLaneLayoutAsInt();
948 subShape = getEffectiveLaneDataAsInt();
950 if (!instData.empty()) {
955 assert(!subShape.empty() &&
"sgdata or lanedata cannot be empty");
958 SliceAttr flattened = flatten();
959 auto parent = dyn_cast<LayoutAttr>(flattened.getParent());
960 SmallVector<int64_t> parentLayoutVec;
961 if (parent.isForWorkgroup())
962 parentLayoutVec = parent.getEffectiveSgLayoutAsInt();
964 parentLayoutVec = parent.getEffectiveLaneLayoutAsInt();
966 SmallVector<int64_t> order = parent.getEffectiveOrderAsInt();
967 SmallVector<int64_t> allIds(parentLayoutVec.size());
968 int64_t remaining = linearId;
969 for (
size_t i = 0; i < order.size(); ++i) {
970 int64_t dimIdx = order[i];
971 allIds[dimIdx] = remaining % parentLayoutVec[dimIdx];
972 if (i < order.size() - 1)
973 remaining = remaining / parentLayoutVec[dimIdx];
978 ArrayRef<int64_t> dims = flattened.getDims().asArrayRef();
979 SmallVector<int64_t> canonicalIds =
980 XeGPUDialect::slice(ArrayRef<int64_t>(allIds), dims);
985bool SliceAttr::isSliceOf(
const xegpu::DistributeLayoutAttr &other) {
986 auto flattenedThis = flatten();
989 if (
auto otherLayout = dyn_cast<xegpu::LayoutAttr>(other))
990 return flattenedThis.getParent() == otherLayout;
992 auto flattenedOther = dyn_cast<xegpu::SliceAttr>(other).flatten();
994 if (flattenedThis.getParent() != flattenedOther.getParent())
998 llvm::SmallDenseSet<int64_t> thisDims(
999 flattenedThis.getDims().asArrayRef().begin(),
1000 flattenedThis.getDims().asArrayRef().end());
1001 return llvm::all_of(flattenedOther.getDims().asArrayRef(),
1002 [&](int64_t dim) { return thisDims.contains(dim); });
1005bool SliceAttr::isEqualTo(
const xegpu::DistributeLayoutAttr &other) {
1006 if (dyn_cast<xegpu::LayoutAttr>(other))
1009 auto flattenedThis = flatten();
1010 auto flattenedOther = dyn_cast<xegpu::SliceAttr>(other).flatten();
1012 return ((flattenedThis.getParent() == flattenedOther.getParent()) &&
1013 (flattenedThis.getDims() == flattenedOther.getDims()));
1016bool SliceAttr::isCompatibleWith(
const xegpu::DistributeLayoutAttr &other,
1017 SmallVector<int64_t> shape,
1021 if (getEffectiveOrderAsInt() == other.getEffectiveOrderAsInt()) {
1024 if (getEffectiveSgLayoutAsInt() == other.getEffectiveSgLayoutAsInt() &&
1025 getEffectiveSgDataAsInt() == other.getEffectiveSgDataAsInt())
1028 if (getEffectiveLaneLayoutAsInt() ==
1029 other.getEffectiveLaneLayoutAsInt() &&
1030 getEffectiveLaneDataAsInt() == other.getEffectiveLaneDataAsInt())
1034 auto compareCoordsForAllIds = [&](int64_t size) {
1035 for (int64_t
id : llvm::seq<int64_t>(0, size)) {
1036 auto coords = computeStaticDistributedCoords(
id, shape);
1037 auto otherCoords = other.computeStaticDistributedCoords(
id, shape);
1038 if (coords != otherCoords)
1044 auto flattenedThis = flatten();
1045 auto parent = dyn_cast<LayoutAttr>(flattenedThis.getParent());
1047 int64_t wgSize =
computeProduct(parent.getEffectiveSgLayoutAsInt());
1048 return compareCoordsForAllIds(wgSize);
1051 return (getEffectiveInstDataAsInt() == other.getEffectiveInstDataAsInt());
1054 int64_t subgroupSize =
computeProduct(parent.getEffectiveLaneLayoutAsInt());
1055 return compareCoordsForAllIds(subgroupSize);
1060xegpu::SliceAttr SliceAttr::dropSliceDims(ArrayRef<int64_t> sliceDimsToDrop) {
1061 if (sliceDimsToDrop.empty())
1063 SmallVector<int64_t> sliceDims{
getDims().asArrayRef()};
1064 for (
auto dim : sliceDimsToDrop) {
1065 auto foundIt = std::find(sliceDims.begin(), sliceDims.end(), dim);
1066 assert(foundIt != sliceDims.end() &&
1067 "Expected to find the specified reduction dim in slice dims");
1068 sliceDims.erase(foundIt);
1071 auto sliceWithoutDims = xegpu::SliceAttr::get(
1075 return sliceWithoutDims;
1083static SmallVector<int64_t>
1091 std::max(maxDim, *std::max_element(sliceDims.begin(), sliceDims.end()));
1093 std::max(maxDim, *std::max_element(dimsToMap.begin(), dimsToMap.end()));
1094 int64_t parentSpaceRank = maxDim + sliceDims.size() + 1;
1098 llvm::SmallDenseSet<int64_t> slicedDimsSet(sliceDims.begin(),
1101 for (
int64_t i = 0; i < parentSpaceRank; ++i) {
1102 if (!slicedDimsSet.contains(i))
1103 remainingDims.push_back(i);
1108 for (
auto dim : dimsToMap) {
1109 int64_t mappedDim = remainingDims[dim];
1110 adjustUnitDims.push_back(mappedDim);
1113 return adjustUnitDims;
1119 DistributeLayoutAttr parentLayout = getParent();
1127 parentLayout.setUnitDimData(adjustUnitDims), getDims());
1133 DistributeLayoutAttr parentLayout = getParent();
1140 return SliceAttr::get(
1141 getContext(), parentLayout.setUnitDimLayout(adjustUnitDims), getDims());
1146DistributeLayoutAttr SliceAttr::setDimData(int64_t dim, int64_t sgData,
1147 int64_t instData, int64_t laneData) {
1148 ArrayRef<int64_t> sliceDims =
getDims().asArrayRef();
1149 auto parent = getParent();
1151 SmallVector<int64_t> dimSet;
1152 dimSet.push_back(dim);
1153 SmallVector<int64_t> adjustDims =
1155 return SliceAttr::get(
1157 parent.setDimData(adjustDims[0], sgData, instData, laneData),
getDims());
1178DistributeLayoutAttr SliceAttr::dropDims(SmallVector<int64_t> dimGroup) {
1180 SmallVector<int64_t> sliceDims = llvm::to_vector(
getDims().asArrayRef());
1181 SmallVector<int64_t> dimsInParentSpace =
1184 auto droppedParent = getParent().dropDims(dimsInParentSpace);
1189 SmallVector<int64_t> newSliceDims;
1190 for (int64_t d : sliceDims) {
1192 llvm::count_if(dimsInParentSpace, [&](int64_t s) {
return s < d; });
1193 newSliceDims.push_back(d - offset);
1196 return SliceAttr::get(
getContext(), droppedParent,
1203DistributeLayoutAttr SliceAttr::collapseDims(SmallVector<int64_t> dimGroup) {
1206 SmallVector<int64_t> sliceDims = llvm::to_vector(
getDims().asArrayRef());
1207 assert(
"expect sliceDims not being collapsed" &&
1208 llvm::none_of(dimGroup, [&](int64_t dim) {
1209 return llvm::is_contained(sliceDims, dim);
1211 SmallVector<int64_t> dimsInParentSpace =
1214 auto collapsedParent = getParent().collapseDims(dimsInParentSpace);
1215 return SliceAttr::get(
getContext(), collapsedParent,
1222 llvm::sort(sortedSliceDims);
1224 for (
size_t i = 1; i < sortedSliceDims.size(); ++i) {
1225 assert((sortedSliceDims[i] == sortedSliceDims[i - 1] + 1) &&
1226 "slice dims non consecutive, cannot be transposed");
1230 if (sortedSliceDims.front() == 0) {
1233 for (
int64_t dim : permutation)
1234 permForParent.push_back(dim + sortedSliceDims.size());
1235 for (
int64_t i = sortedSliceDims.size() - 1; i >= 0; --i)
1236 permForParent.push_back(i);
1240 for (
int64_t i = sortedSliceDims.size() - 1; i >= 0; --i)
1241 permForParent.push_back(i + permutation.size());
1242 for (
int64_t dim : permutation)
1243 permForParent.push_back(dim);
1245 return permForParent;
1251 DistributeLayoutAttr parent = getParent();
1254 auto transposedParent = parent.transposeDims(permForParent);
1255 return SliceAttr::get(
getContext(), transposedParent,
1260bool SliceAttr::isTransposeOf(
const xegpu::DistributeLayoutAttr &other,
1264 auto otherSlice = dyn_cast<xegpu::SliceAttr>(other);
1265 if (!otherSlice || getDims() != otherSlice.getDims())
1269 DistributeLayoutAttr parent = getParent();
1271 auto otherParent = otherSlice.getParent();
1272 return parent.isTransposeOf(otherParent, permForParent, kind);
1280RangeAttr::verify(llvm::function_ref<mlir::InFlightDiagnostic()>
emitError,
1281 IntegerAttr startOfRange, IntegerAttr endOfRange) {
1282 if (startOfRange.getInt() >= endOfRange.getInt())
1283 return emitError() <<
"'end' : " << endOfRange.getInt()
1284 <<
" must be greater than 'start' : "
1285 << startOfRange.getInt();
1294mlir::Type TensorDescType::parse(AsmParser &parser) {
1295 llvm::SmallVector<int64_t> shape;
1296 mlir::Type elementType;
1297 mlir::FailureOr<mlir::Attribute> encoding;
1298 mlir::FailureOr<mlir::Attribute> layout;
1306 parser.
emitError(shapeLoc,
"failed to parse parameter 'shape'");
1311 if (mlir::failed(parser.
parseType(elementType))) {
1312 parser.
emitError(elemTypeLoc,
"failed to parse parameter 'elementType'");
1318 mlir::Attribute attr;
1320 if (mlir::succeeded(res)) {
1321 if (mlir::isa<LayoutAttr>(attr)) {
1325 if (mlir::isa<BlockTensorDescAttr, ScatterTensorDescAttr>(attr)) {
1338 return TensorDescType::getChecked(
1340 elementType, encoding.value_or(BlockTensorDescAttr::get(ctxt)),
1341 layout.value_or(mlir::Attribute()));
1344void TensorDescType::print(AsmPrinter &printer)
const {
1348 for (int64_t dim : shape) {
1349 if (mlir::ShapedType::isDynamic(dim))
1358 auto encoding = getEncoding();
1359 auto blockAttr = llvm::dyn_cast_if_present<BlockTensorDescAttr>(encoding);
1360 if (encoding && (!blockAttr || !blockAttr.hasDefaultsOnly()))
1361 printer <<
", " << encoding;
1363 if (
auto layout = getLayout())
1364 printer <<
", " << layout;
1369TensorDescType TensorDescType::get(llvm::ArrayRef<int64_t> shape,
1370 mlir::Type elementType,
int array_length,
1371 bool boundary_check,
1372 MemorySpace memory_space,
1373 mlir::Attribute layout) {
1375 auto attr = BlockTensorDescAttr::get(context, memory_space, array_length,
1377 return Base::get(context, shape, elementType, attr, layout);
1380TensorDescType TensorDescType::get(llvm::ArrayRef<int64_t> shape,
1381 mlir::Type elementType,
int chunk_size,
1382 MemorySpace memory_space,
1383 mlir::Attribute layout) {
1385 auto attr = ScatterTensorDescAttr::get(context, memory_space, chunk_size);
1386 return Base::get(context, shape, elementType, attr, layout);
1390TensorDescType::verify(llvm::function_ref<InFlightDiagnostic()>
emitError,
1391 llvm::ArrayRef<int64_t> shape, mlir::Type elementType,
1392 mlir::Attribute encoding, mlir::Attribute layout) {
1393 size_t rank = shape.size();
1396 return emitError() <<
"expected non-zero rank tensor";
1398 auto blockAttr = mlir::dyn_cast_if_present<BlockTensorDescAttr>(encoding);
1400 MemorySpaceAttr memorySpaceAttr = blockAttr.getMemorySpace();
1401 if (rank > 1 && memorySpaceAttr &&
1402 memorySpaceAttr.getValue() == MemorySpace::SLM)
1403 return emitError() <<
"SLM is only supported for 1D block tensor";
1407 return emitError() <<
"unsupported element type " << elementType
1408 <<
": expected integer or float";
1413 int chunkAlignmentFactor =
1417 auto scatterAttr = mlir::dyn_cast_if_present<ScatterTensorDescAttr>(encoding);
1419 int64_t chunkSize = scatterAttr.getChunkSizeAsInt();
1420 if (rank == 1 && chunkSize != 1)
1421 return emitError() <<
"expected non-contiguous elements for 1D tensor";
1426 if (chunkSize > 1) {
1427 if (shape.back() != chunkSize)
1428 return emitError() <<
"expected last dim of tensor to match chunk size";
1429 if (shape.back() % chunkAlignmentFactor != 0)
1430 return emitError() <<
"expected last dim of tensor to be a multiple of "
1431 << chunkAlignmentFactor;
1435 auto layoutAttr = llvm::dyn_cast_if_present<LayoutAttr>(layout);
1437 if (rank != (
size_t)layoutAttr.getRank())
1438 return emitError() <<
"expected layout rank to match tensor rank";
1440 auto laneData = layoutAttr.getLaneData();
1441 if (scatterAttr && laneData) {
1445 int64_t chunkSize = scatterAttr.getChunkSizeAsInt();
1446 if (chunkSize > 1 && laneData[rank - 1] % chunkAlignmentFactor)
1448 <<
"expected last dim of lane_data to be a multiple of: "
1449 << chunkAlignmentFactor;
1452 if (!XeGPUDialect::isEvenlyDistributable(shape, layoutAttr)) {
1453 std::string shapeStr;
1454 llvm::raw_string_ostream stream(shapeStr);
1455 llvm::interleaveComma(shape, stream);
1456 return emitError() <<
"cannot distribute [" << shapeStr <<
"] using "
1466mlir::Type MemDescType::parse(AsmParser &parser) {
1467 llvm::SmallVector<int64_t> shape;
1468 mlir::Type elementType;
1469 mlir::FailureOr<MemLayoutAttr> layout;
1477 parser.
emitError(shapeLoc,
"failed to parse parameter 'shape'");
1482 if (mlir::failed(parser.
parseType(elementType))) {
1483 parser.
emitError(elemTypeLoc,
"failed to parse parameter 'elementType'");
1491 if (mlir::failed(res))
1501 return MemDescType::getChecked(
1503 elementType, layout.value_or(MemLayoutAttr()));
1506void MemDescType::print(AsmPrinter &printer)
const {
1513 if (
auto layout = getMemLayout())
1514 printer <<
", " << layout;
1523Attribute MemLayoutAttr::parse(AsmParser &parser, Type type) {
1528 llvm::SmallDenseSet<StringRef> seenKeys;
1529 SmallVector<NamedAttribute> attributes;
1531 auto parseElt = [&]() -> ParseResult {
1534 return parser.
emitError(loc,
"expected valid attribute name");
1536 if (!seenKeys.insert(nameId).second)
1537 return parser.
emitError(loc,
"duplicate key '")
1538 << nameId <<
" in mem layout attribute";
1546 attributes.emplace_back(nameId, attr);
1562 loc, context, DictionaryAttr::get(context, attributes));
1565void MemLayoutAttr::print(AsmPrinter &printer)
const {
1567 ArrayRef<NamedAttribute> attrs = getAttrs().getValue();
1568 for (
size_t i = 0; i < attrs.size(); i++) {
1569 printer << attrs[i].getName().str() <<
" = " << attrs[i].getValue();
1570 if (i < attrs.size() - 1)
1579template <
typename ArithOp>
1584 return ArithOp::create(builder, loc, aVal, bVal).getResult();
1589 genBinOp<arith::DivSIOp>(a, builder.getIndexAttr(b), loc, builder)
1593 genBinOp<arith::RemSIOp>(a, builder.getIndexAttr(b), loc, builder)
1597 genBinOp<arith::MulIOp>(a, builder.getIndexAttr(b), loc, builder)
1600#define add(a, b) genBinOp<arith::AddIOp>(a, b, loc, builder)
1609 assert(offsets.size() == blockShape.size() &&
1610 "offsets and blockShape must have the same size");
1614 for (
auto [offset, block] : llvm::zip(offsets, blockShape)) {
1615 divs.push_back(
div(offset, block));
1616 rems.push_back(
rem(offset, block));
1618 blockedOffsets.append(divs.begin(), divs.end());
1619 blockedOffsets.append(rems.begin(), rems.end());
1621 return blockedOffsets;
1629 ArrayAttr strideAttr = getStrideAttr();
1631 for (
Attribute attr : strideAttr.getValue()) {
1632 strides.push_back(cast<IntegerAttr>(attr).getInt());
1640 llvm::to_vector<4>(llvm::seq<int>(0, strides.size()));
1641 llvm::sort(perm, [&](
int a,
int b) {
return strides[a] < strides[
b]; });
1643 assert(strides[perm[0]] == 1 &&
"inner most dim must have stride 1");
1645 SmallVector<int64_t> innerBlkStride(innerBlkShape.size());
1646 innerBlkStride[perm[0]] = 1;
1647 for (
size_t i = 1; i < perm.size(); ++i)
1648 innerBlkStride[perm[i]] =
1649 innerBlkStride[perm[i - 1]] * innerBlkShape[perm[i - 1]];
1655 SmallVector<int64_t> matrixShapeOrig(matrixShape.size());
1656 SmallVector<int64_t> BlkShapeOrig(matrixShape.size());
1657 for (
size_t i = 0; i < perm.size() - 1; ++i) {
1658 matrixShapeOrig[perm[i]] = strides[perm[i + 1]] / strides[perm[i]];
1659 BlkShapeOrig[perm[i]] = matrixShapeOrig[perm[i]] / innerBlkShape[perm[i]];
1662 int64_t innerBlkSize = 1;
1663 for (
auto s : innerBlkShape)
1666 SmallVector<int64_t> outerBlkStride(matrixShape.size());
1667 outerBlkStride[perm[0]] = innerBlkSize;
1668 for (
size_t i = 0; i < perm.size() - 1; ++i) {
1669 outerBlkStride[perm[i + 1]] =
1670 outerBlkStride[perm[i]] * BlkShapeOrig[perm[i]];
1674 SmallVector<int64_t> blockedStrides;
1675 blockedStrides.append(outerBlkStride.begin(), outerBlkStride.end());
1676 blockedStrides.append(innerBlkStride.begin(), innerBlkStride.end());
1678 return blockedStrides;
1682Value MemDescType::getLinearOffsets(OpBuilder &builder, Location loc,
1683 ArrayRef<OpFoldResult> offsets) {
1686 SmallVector<int64_t> blockShape = getBlockShape();
1687 SmallVector<int64_t> strides = getStrideShape();
1688 SmallVector<OpFoldResult> blockedOffsets;
1691 if (llvm::equal(blockShape, matrixShape)) {
1693 strides.erase(strides.begin(), strides.begin() + matrixShape.size());
1695 assert(offsets.size() == blockShape.size() &&
1696 "offsets and blockShape must have the same size");
1700 SmallVector<OpFoldResult> divs, rems;
1702 for (
auto [offset, block] : llvm::zip(offsets, blockShape)) {
1703 divs.push_back(
div(offset, block));
1704 rems.push_back(
rem(offset, block));
1706 blockedOffsets.append(divs.begin(), divs.end());
1707 blockedOffsets.append(rems.begin(), rems.end());
1708 offsets = blockedOffsets;
1713 for (
size_t i = 0; i < offsets.size(); ++i) {
1714 OpFoldResult mulResult =
mul(offsets[i], strides[i]);
1716 linearOffset = arith::AddIOp::create(builder, loc, mulVal, linearOffset);
1719 return linearOffset;
1725#include <mlir/Dialect/XeGPU/IR/XeGPUDialect.cpp.inc>
1726#define GET_ATTRDEF_CLASSES
1727#include <mlir/Dialect/XeGPU/IR/XeGPUAttrs.cpp.inc>
1728#define GET_TYPEDEF_CLASSES
1729#include <mlir/Dialect/XeGPU/IR/XeGPUTypes.cpp.inc>
static Type getElementType(Type type)
Determine the element type of type.
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
MLIRContext * getContext() const
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual ParseResult parseDimensionList(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)=0
Parse a dimension list of a tensor or memref type.
virtual ParseResult parseEqual()=0
Parse a = token.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseOptionalComma()=0
Parse a , token if present.
auto getChecked(SMLoc loc, ParamsT &&...params)
Invoke the getChecked method of the given Attribute or Type class, using the provided location to emi...
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseGreater()=0
Parse a '>' token.
virtual ParseResult parseType(Type &result)=0
Parse a type.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
void printDimensionList(ArrayRef< int64_t > shape)
Attributes are known-constant values of operations.
static BoolAttr get(MLIRContext *context, bool value)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
void createOrFold(SmallVectorImpl< Value > &results, Location location, Args &&...args)
Create an operation of specific op type at the current insertion point, and immediately try to fold i...
This class represents a single result from folding an operation.
A range-style iterator that allows for iterating over the offsets of all potential tiles of size tile...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Specialization of arith.constant op that returns an integer of index type.
static ConstantIndexOp create(OpBuilder &builder, Location location, int64_t value)
static DenseArrayAttrImpl get(MLIRContext *context, ArrayRef< int32_t > content)
ArrayRef< T > asArrayRef() const
auto getDims(VectorType vType)
Returns a range over the dims (size and scalability) of a VectorType.
constexpr unsigned generalPackedFormatBitSize
static SmallVector< SmallVector< int64_t > > genStaticCoordinates(llvm::ArrayRef< int64_t > canonicalIds, llvm::ArrayRef< int64_t > layout, llvm::ArrayRef< int64_t > subShape, llvm::ArrayRef< int64_t > shape)
LayoutKind
Specifies the level of a layout hierarchy for comparison or propagation.
static SmallVector< int64_t > mapSlicedDimsToParentSpace(const SmallVector< int64_t > &dimsToMap, ArrayRef< int64_t > sliceDims)
SmallVector< OpFoldResult > getBlockedOffsets(OpBuilder &builder, Location loc, ArrayRef< OpFoldResult > offsets, ArrayRef< int64_t > blockShape)
OpFoldResult genBinOp(OpFoldResult a, OpFoldResult b, Location loc, OpBuilder &builder)
static SmallVector< SmallVector< Value > > genCoordinates(OpBuilder &builder, Location loc, SmallVector< Value > delinearizedId, ArrayRef< int64_t > subShapesLayout, ArrayRef< int64_t > subShape, ArrayRef< int64_t > srcShape)
SmallVector< int64_t > getPermForParentLayout(ArrayRef< int64_t > sliceDims, ArrayRef< int64_t > permutation)
Include the generated interface declarations.
detail::DenseArrayAttrImpl< int64_t > DenseI64ArrayAttr
SmallVector< int64_t > computeElementwiseMul(ArrayRef< int64_t > v1, ArrayRef< int64_t > v2)
Return a vector containing llvm::zip_equal(v1, v2) multiplied elementwise.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
int64_t computeProduct(ArrayRef< int64_t > basis)
Self-explicit.
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
Value getValueOrCreateConstantIndexOp(OpBuilder &b, Location loc, OpFoldResult ofr)
Converts an OpFoldResult to a Value.
std::optional< SmallVector< int64_t > > computeShapeRatio(ArrayRef< int64_t > shape, ArrayRef< int64_t > subShape)
Return the multi-dimensional integral ratio of subShape to the trailing dimensions of shape.
bool isPermutationVector(ArrayRef< int64_t > interchange)
Method to check if an interchange vector is a permutation.