Skip to content

Commit 3818237

Browse files
committed
[mlir][Tiling] Properly reject "buffer semantic" operations
Our tiling implementation assumes a "tensor semantic" for the operation to be tiled. Prior to this patch, if we provide a tilable op with "buffer semantic", we will assert instead of gracefully reject the input. This patch turns the assert in a proper error. Differential Revision: https://reviews.llvm.org/D143558
1 parent f25c775 commit 3818237

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

mlir/lib/Dialect/Linalg/Transforms/Tiling.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ static FailureOr<ForeachThreadTilingResult> tileToForeachThreadOpImpl(
381381
if (destinationStyleOp) {
382382
for (OpOperand *outOperand : destinationStyleOp.getDpsInitOperands()) {
383383
auto *it = llvm::find(dest, outOperand->get());
384-
assert(it != dest.end() && "dest operand not found in dest");
384+
if (it == dest.end())
385+
return op->emitOpError("must have \"tensor semantic\" for tiling");
385386
unsigned destNum = std::distance(dest.begin(), it);
386387
outOperand->set(destBbArgs[destNum]);
387388
}

mlir/test/Dialect/GPU/transform-gpu-failing.mlir

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,32 @@ transform.sequence failures(propagate) {
274274
transform.gpu.map_nested_foreach_to_threads %funcop { blockDim = [32, 32]}
275275
}
276276

277+
// -----
278+
279+
func.func @tiling_buffer_semantic_op(%x: memref<32x32xf32>, %y: memref<32x32xf32>, %stream : !gpu.async.token) {
280+
%one = arith.constant 1 : index
281+
%name = gpu.launch async[%stream] blocks(%arg3, %arg4, %arg5) in (%arg9 = %one, %arg10 = %one, %arg11 = %one)
282+
threads(%arg6, %arg7, %arg8) in (%arg12 = %one, %arg13 = %one, %arg14 = %one)
283+
{
284+
// expected-error @below {{'linalg.generic' op must have "tensor semantic" for tiling}}
285+
// expected-note @below {{when applied to this op}}
286+
linalg.generic
287+
{indexing_maps = [affine_map<(d0, d1) -> (d0, d1)>,
288+
affine_map<(d0, d1) -> (d0, d1)>],
289+
iterator_types = ["parallel", "parallel"]}
290+
ins(%x : memref<32x32xf32>)
291+
outs(%y : memref<32x32xf32>) {
292+
^bb0(%in: f32, %out: f32):
293+
linalg.yield %in : f32
294+
}
295+
gpu.terminator
296+
}
297+
return
298+
}
277299

300+
transform.sequence failures(propagate) {
301+
^bb1(%arg0: !pdl.operation):
302+
%matmul = transform.structured.match ops{["linalg.generic"]} in %arg0 : (!pdl.operation) -> !pdl.operation
303+
// expected-error @below {{transform.structured.tile_to_foreach_thread_op failed to apply}}
304+
%foreach, %tiled = transform.structured.tile_to_foreach_thread_op %matmul num_threads [10, 20, 30] (mapping = [ #gpu.thread<y>, #gpu.thread<x>, #gpu.thread<z> ] )
305+
}

0 commit comments

Comments
 (0)