Created
October 4, 2023 12:52
-
-
Save matthias-springer/50f5cc3a7b8ad85054c19b96770042dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RUN: mlir-opt %s -test-transform-dialect-interpreter="debug-payload-root-tag=payload" | |
module attributes {transform.target_tag="payload"} { | |
// TOSA element-wise addition. %A and %B are the inputs, %C is the output. | |
func.func @test_matmul(%A: memref<100xf32>, %B: memref<100xf32>, | |
%C: memref<100xf32>) { | |
%A_tensor = bufferization.to_tensor %A restrict : memref<100xf32> | |
%B_tensor = bufferization.to_tensor %B restrict : memref<100xf32> | |
%0 = tosa.add %A_tensor, %B_tensor | |
: (tensor<100xf32>, tensor<100xf32>) -> tensor<100xf32> | |
bufferization.materialize_in_destination %0 in restrict writable %C | |
: (tensor<100xf32>, memref<100xf32>) -> () | |
return | |
} | |
} | |
transform.sequence failures(propagate) { | |
^bb0(%module1: !transform.any_op): | |
// Convert TOSA to Linalg | |
%func1 = transform.structured.match ops{["func.func"]} in %module1 | |
: (!transform.any_op) -> !transform.any_op | |
%func2 = transform.apply_registered_pass "tosa-to-linalg" to %func1 | |
: (!transform.any_op) -> !transform.any_op | |
// Tile linalg.generic | |
%matmul = transform.structured.match ops{["linalg.generic"]} in %func2 | |
: (!transform.any_op) -> !transform.any_op | |
%1, %loop = transform.structured.tile_using_for %matmul [5] | |
: (!transform.any_op) -> (!transform.any_op, !transform.any_op) | |
// Canonicalize + CSE | |
transform.apply_patterns to %func2 { | |
transform.apply_patterns.canonicalization | |
} {apply_cse} : !transform.any_op | |
// Eliminate empty tensors | |
transform.bufferization.eliminate_empty_tensors %func2 : !transform.any_op | |
// Bufferize | |
%module2 = transform.bufferization.one_shot_bufferize %module1 | |
: (!transform.any_op) -> !transform.any_op | |
// Canonicalize + CSE | |
transform.apply_patterns to %module2 { | |
transform.apply_patterns.canonicalization | |
} {apply_cse} : !transform.any_op | |
// Deallocate buffers. That's a no-op in this example because no temporary | |
// buffers are allocated. | |
%module3 = transform.apply_registered_pass | |
"buffer-deallocation-pipeline" to %module2 | |
: (!transform.any_op) -> !transform.any_op | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment