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

Pablo Antonio Martinez llvmlistbot at llvm.org
Thu Mar 21 09:33:34 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;
----------------
pabloantoniom wrote:

I feel the same. However, having duplicated code (one check for tile sizes and numThreads) does not look good to me either. However, now I have noticed that when tile sizes are specified, numThreads are automatically derived from tile sizes (in `tileToForallOpUsingTileSizes`). Therefore, we now that numThreads will always contain the values that we need to check, so I have simplified the implementation to check only numThreads.

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


More information about the Mlir-commits mailing list