Last active
October 7, 2023 20:55
-
-
Save matthias-springer/e531580242d27f14e0a239e0b6fe80ae 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_tensor: tensor<100xf32>, %B_tensor: tensor<100xf32>, | |
%C_tensor: tensor<100xf32>) -> tensor<100xf32> { | |
%0 = tosa.add %A_tensor, %B_tensor | |
: (tensor<100xf32>, tensor<100xf32>) -> tensor<100xf32> | |
%r = bufferization.materialize_in_destination %0 in %C_tensor | |
: (tensor<100xf32>, tensor<100xf32>) -> (tensor<100xf32>) | |
return %r : tensor<100xf32> | |
} | |
} | |
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 | |
// Eliminate empty tensors | |
transform.bufferization.eliminate_empty_tensors %module1 : !transform.any_op | |
// Bufferize | |
%module2 = transform.bufferization.one_shot_bufferize %module1 | |
{ bufferize_function_boundaries = true } | |
: (!transform.any_op) -> !transform.any_op | |
// Canonicalize + CSE | |
transform.apply_patterns to %module2 { | |
transform.apply_patterns.canonicalization | |
} {apply_cse} : !transform.any_op | |
// Remove function return value | |
%module3 = transform.apply_registered_pass | |
"drop-equivalent-buffer-results" to %module2 | |
: (!transform.any_op) -> !transform.any_op | |
// Deallocate buffers. That's a no-op in this example because no temporary | |
// buffers are allocated. | |
%module4 = transform.apply_registered_pass | |
"buffer-deallocation-pipeline" to %module3 | |
: (!transform.any_op) -> !transform.any_op | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment