torch-mlir/test/Dialect/TMTensor/canonicalize.mlir

25 lines
1003 B
MLIR
Raw Normal View History

Re-organize project structure to separate PyTorch dependencies from core project. (#2542) This is a first step towards the structure we discussed here: https://gist.github.com/stellaraccident/931b068aaf7fa56f34069426740ebf20 There are two primary goals: 1. Separate the core project (C++ dialects and conversions) from the hard PyTorch dependencies. We move all such things into projects/pt1 as a starting point since they are presently entangled with PT1-era APIs. Additional work can be done to disentangle components from that (specifically LTC is identified as likely ultimately living in a `projects/ltc`). 2. Create space for native PyTorch2 Dynamo-based infra to be upstreamed without needing to co-exist with the original TorchScript path. Very little changes in this path with respect to build layering or options. These can be updated in a followup without commingling directory structure changes. This also takes steps toward a couple of other layering enhancements: * Removes the llvm-external-projects/torch-mlir-dialects sub-project, collapsing it into the main tree. * Audits and fixes up the core C++ build to account for issues found while moving things. This is just an opportunistic pass through but roughly ~halves the number of build actions for the project from the high 4000's to the low 2000's. It deviates from the discussed plan by having a `projects/` tree instead of `compat/`. As I was thinking about it, this will better accommodate the follow-on code movement. Once things are roughly in place and the CI passing, followups will focus on more in-situ fixes and cleanups.
2023-11-03 10:45:55 +08:00
// RUN: torch-mlir-opt -canonicalize -split-input-file %s | FileCheck %s
// CHECK-LABEL: func.func @tensor.cast(
func.func @tensor.cast(%arg0: tensor<128xi32>) -> tensor<128xi32> {
%init = tensor.empty() : tensor<128xi32>
%c0 = tensor.empty() : tensor<i32>
%casted_arg0 = tensor.cast %arg0 : tensor<128xi32> to tensor<?xi32>
%casted_init = tensor.cast %init : tensor<128xi32> to tensor<?xi32>
// CHECK: tm_tensor.scan
// CHECK-SAME: ins(%{{[a-zA-Z0-9]*}} : tensor<128xi32>)
// CHECK-SAME: outs(%{{[a-zA-Z0-9]*}}, %{{[a-zA-Z0-9]*}} : tensor<128xi32>, tensor<i32>)
%0, %1 = tm_tensor.scan dimension(0) inclusive(true)
ins(%casted_arg0 : tensor<?xi32>)
outs(%casted_init, %c0: tensor<?xi32>, tensor<i32>) {
^bb0(%barg0 : i32, %barg1 : i32, %barg2 : i32):
%sum = arith.addi %barg0, %barg1 : i32
tm_tensor.yield %sum : i32
} -> tensor<?xi32>, tensor<i32>
%2 = tensor.cast %0: tensor<?xi32> to tensor<128xi32>
return %2: tensor<128xi32>
}