diff options
| author | Krzysztof Drewniak <Krzysztof.Drewniak@amd.com> | 2025-07-21 13:18:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-21 15:18:19 -0500 |
| commit | 9052a85da803b246fa6a6f8b3b5bcbfc2e9de7a8 (patch) | |
| tree | ac1e47c1bb8aaf241caca99ce06b9df84b7d2c4d /mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp | |
| parent | 860ff8714b2d6f810703c4490e26dd687fc15b8d (diff) | |
[mlir][AMDGPU] Infer canonical layouts for fat_raw_buffer_cast resetOffset (#149867)
When inferring the return type of amdgpu.fat_raw_buffer_cast with the
offset reset, we would sometimes use a strided layout, like
strided<[1]>, in cases where, after stripping the offset, the memref had
the identity layout. This would cause issues with EmulateNarrowTypes,
which does perform this layout canonicalization.
Now, the return type inference will put in an identity layout after
offset stripping for
1. Statically-shaped memrefs of any rank where the strides match the
suffix product of the shape, and
2. Memrefs of rank <= 1 whose strides are [1] (or []) that just had
their offset removed by resetOffset.
Diffstat (limited to 'mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp')
| -rw-r--r-- | mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp index 88c2eb3326d9..18e8270f5aa9 100644 --- a/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp +++ b/mlir/lib/Dialect/AMDGPU/IR/AMDGPUDialect.cpp @@ -16,6 +16,7 @@ #include "mlir/Dialect/GPU/IR/GPUDialect.h" #include "mlir/Dialect/LLVMIR/ROCDLDialect.h" #include "mlir/Dialect/MemRef/Utils/MemRefUtils.h" +#include "mlir/Dialect/Utils/IndexingUtils.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Diagnostics.h" @@ -89,7 +90,22 @@ static FailureOr<MemRefType> getFatRawBufferTypeLike(MemRefType source, auto stridedLayout = dyn_cast<StridedLayoutAttr>(layout); if (!stridedLayout) return failure(); - mb.setLayout(StridedLayoutAttr::get(ctx, 0, stridedLayout.getStrides())); + MemRefLayoutAttrInterface newLayout = + StridedLayoutAttr::get(ctx, 0, stridedLayout.getStrides()); + // Special case: if resetting the offset causes the strided layout to become + // the identity layout, then reset to the identity layout. + // TODO: this'll get a lot simpler when we have the contiguous layout. + SmallVector<int64_t> stridesIfIdentity; + if (source.hasStaticShape()) { + stridesIfIdentity = computeSuffixProduct(source.getShape()); + } else if (source.getRank() <= 1) { + stridesIfIdentity = SmallVector<int64_t>(source.getRank(), 1); + } + if (stridesIfIdentity == stridedLayout.getStrides()) { + newLayout = AffineMapAttr::get( + AffineMap::getMultiDimIdentityMap(source.getRank(), ctx)); + } + mb.setLayout(newLayout); } return (MemRefType)(mb); } |
