Skip to content

Commit

Permalink
Merge branch 'feature/fused-ops' into tina.ub-to-emitc-opaque-types
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaAMD committed Jan 8, 2025
2 parents 6823eca + c6d34c5 commit 8bb70cf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mlir/lib/Dialect/SCF/Transforms/TileUsingInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,12 @@ mlir::scf::tileConsumerAndFuseProducersUsingSCF(
tiledAndFusedOps.insert(tiledAndFusedOp);
}

// Drop the extract_slice if it has been replaced by the tiled producer, and
// is no longer used.
if (worklistItem.candidateSlice->use_empty()) {
rewriter.eraseOp(worklistItem.candidateSlice);
}

if (failed(sliceTracker.insertAndApplyPatterns(worklistCandidates))) {
return rewriter.notifyMatchFailure(consumer, "cleanup patterns failed");
}
Expand Down
40 changes: 40 additions & 0 deletions mlir/test/Dialect/Linalg/transform-op-fuse-into-containing.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,46 @@ module {
}
}

// -----

// This test checks that upon tiling and fusion, Linalg ops that have been tiled
// through fusion and are not used elsewhere are indeed dead code and get
// dropped.

// CHECK-LABEL: func @tile_fuse_drop_dead_producer(
// CHECK-SAME: %[[TA:[0-9a-z]+]]: tensor<10x10xf32>) -> tensor<10x10xf32> {
func.func @tile_fuse_drop_dead_producer(%arg0: tensor<10x10xf32>) -> tensor<10x10xf32> {
%c2f = arith.constant 2.0 : f32

// CHECK-NOT: linalg.generic {{{[^\}]*}}} ins(%[[TA]] : tensor<10x10xf32>) outs(%{{.*}} : tensor<10x10xf32>) {
%empty = tensor.empty() : tensor<10x10xf32>
%0 = linalg.generic {indexing_maps = [affine_map<(i, j) -> (i, j)>, affine_map<(i, j) -> (i, j)>], iterator_types = ["parallel", "parallel"]}
ins(%arg0: tensor<10x10xf32>) outs(%empty: tensor<10x10xf32>) {
^bb0(%a: f32, %b: f32):
%res = arith.addf %a, %c2f : f32
linalg.yield %res : f32
} -> tensor<10x10xf32>

%empty2 = tensor.empty() : tensor<10x10xf32>
// CHECK: scf.for {{.*}} {
// CHECK: scf.for {{.*}} {
// CHECK: linalg.generic
// CHECK: linalg.negf
// CHECK: }
// CHECK: }
%1 = linalg.negf ins(%0 : tensor<10x10xf32>) outs(%empty2 : tensor<10x10xf32>) -> tensor<10x10xf32>

return %1 : tensor<10x10xf32>
}

module attributes {transform.with_named_sequence} {
transform.named_sequence @__transform_main(%arg1: !transform.any_op {transform.readonly}) {
%0 = transform.structured.match ops{["linalg.negf"]} in %arg1 : (!transform.any_op) -> !transform.any_op
%tiled_low, %loop1, %loop2 = transform.structured.fuse %0 [5, 2] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op)
transform.yield
}
}


////////////////////////////////////////////////////////////////////////////////
// Tests below are expected to fail.
Expand Down
19 changes: 18 additions & 1 deletion mlir/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ def find_runtime(name):
return path


# Find path to the ASan runtime required for the Python interpreter.
def find_asan_runtime():
if not "asan" in config.available_features or not "Linux" in config.host_os:
return ""
# Find the asan rt lib
return (
subprocess.check_output(
[
config.host_cxx.strip(),
f"-print-file-name=libclang_rt.asan-{config.host_arch}.so",
]
)
.decode("utf-8")
.strip()
)

# Searches for a runtime library with the given name and returns a tool
# substitution of the same name and the found path.
def add_runtime(name):
Expand Down Expand Up @@ -177,7 +193,8 @@ def add_runtime(name):
# Python configuration with sanitizer requires some magic preloading. This will only work on clang/linux.
# TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms).
if "asan" in config.available_features and "Linux" in config.host_os:
python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}"
_asan_rt = find_asan_runtime()
python_executable = f"env LD_PRELOAD={_asan_rt} {config.python_executable}"
# On Windows the path to python could contains spaces in which case it needs to be provided in quotes.
# This is the equivalent of how %python is setup in llvm/utils/lit/lit/llvm/config.py.
elif "Windows" in config.host_os:
Expand Down

0 comments on commit 8bb70cf

Please sign in to comment.