[Mlir-commits] [mlir] [mlir][linalg] Emit a warning when tile_using_forall generates non thread-safe code (PR #80813)

Oleksandr Alex Zinenko llvmlistbot at llvm.org
Thu Mar 21 03:52:11 PDT 2024


================
@@ -304,6 +304,44 @@ static void calculateTileOffsetsAndSizes(
   }
 }
 
+/// Returns a vector of bools representing if, for the given axis, `op` can be
+/// tiled by without incurring in a race condition and thus it is thread-safe to
+/// do the tiling. This is checked by iterating over the affine map represented
+/// by the tiling sizes (which is derived from `numThreads` or
+/// `nominalTileSizes`) and ensuring that the corresponding iterator type is
+/// not "reduction". If it is, then we know that such dimension is unsafe to
+/// tile.
+SmallVector<bool>
+safeToTileToForall(mlir::MLIRContext *ctx, LinalgOp linalgOp,
+                   ArrayRef<OpFoldResult> numThreads,
+                   std::optional<ArrayRef<OpFoldResult>> nominalTileSizes,
+                   int numDims) {
+  ArrayRef<OpFoldResult> tilingValues =
+      nominalTileSizes.has_value() ? *nominalTileSizes : numThreads;
+  int minTile = nominalTileSizes.has_value() ? 0 : 1;
----------------
ftynse wrote:

I really dislike how this mixes tile sizes and num threads in one variable. These are opposite things. Could we rather not mix them and just have two separate checks below?

https://github.com/llvm/llvm-project/pull/80813


More information about the Mlir-commits mailing list