[Mlir-commits] [mlir] [MLIR][XeGPU] Allow some nd ops to have argument shapes mismatch for … (PR #120566)
Adam Siemieniuk
llvmlistbot at llvm.org
Tue Jan 14 06:56:59 PST 2025
================
@@ -73,6 +73,29 @@ static bool isWriteHintOrNone(const CachePolicyAttr &attr) {
kind == CachePolicy::WRITE_BACK || kind == CachePolicy::WRITE_THROUGH;
}
+// Validations for nd instruction arguments is successful if any of these are
+// true:
+// - tensor descriptor and the output vector shapes exactly match.
+// - tensor descriptor has a sg_map attribute and the distributed vector shape
+// matches the tensor descriptor shape when scaled using sg_map factors on
+// each dimension.
+static bool isArgShapesValid(ArrayRef<int64_t> descShape,
+ ArrayRef<int64_t> valShape, SGMapAttr sgMap) {
+ if (descShape == valShape)
+ return true;
+
+ if (!sgMap)
+ return false;
+
+ for (const auto &[factor, dim, expected] :
+ llvm::zip_equal(sgMap.getWiLayout(), valShape, descShape)) {
----------------
adam-smnk wrote:
There's still the issue that we can have:
```mlir
%1 = xegpu.create_nd_tdesc %src[0, 0] : memref<24x32xf32> ->
!xegpu.tensor_desc<16xf32, #xegpu.sg_map<wi_layout = [1, 16], wi_data = [1, 1]>>
// expected-error at +1 {{Result shape doesn't match TensorDesc shape.}}
%2 = xegpu.load_nd %1
: !xegpu.tensor_desc<16xf32, #xegpu.sg_map<wi_layout = [1, 16], wi_data = [1, 1]>>
-> vector<16xf32>
```
I think such `tensor_desc` shouldn't be allowed in the first place. But for now maybe add a check for `sg_map` size.
https://github.com/llvm/llvm-project/pull/120566
More information about the Mlir-commits
mailing list