|
| 1 | +#include <string> |
| 2 | +#include "core/compiler.h" |
| 3 | +#include "core/lowering/passes/passes.h" |
| 4 | +#include "gtest/gtest.h" |
| 5 | +#include "tests/util/util.h" |
| 6 | +#include "torch/csrc/jit/ir/irparser.h" |
| 7 | +#include "torch/csrc/jit/ir/subgraph_matcher.h" |
| 8 | + |
| 9 | +TEST(LoweringPasses, ViewToReshapeCorrectly) { |
| 10 | + std::string source_graph = R"IR( |
| 11 | + graph(%x : Tensor, %1, %1.1): |
| 12 | + %0 : int = prim::Constant[value=0]() |
| 13 | + %2 : Tensor = aten::permute(%x, %1) |
| 14 | + %3 : Tensor = aten::contiguous(%2, %0) |
| 15 | + %4 : Tensor = aten::view(%3, %1.1) |
| 16 | + return (%4))IR"; |
| 17 | + std::string target_graph = R"IR( |
| 18 | + graph(%x : Tensor, %1, %1.1): |
| 19 | + %0 : int = prim::Constant[value=0]() |
| 20 | + %2 : Tensor = aten::permute(%x, %1) |
| 21 | + %4 : Tensor = aten::reshape(%2, %1.1) |
| 22 | + return (%4))IR"; |
| 23 | + |
| 24 | + torch_tensorrt::core::util::logging::get_logger().set_reportable_log_level( |
| 25 | + torch_tensorrt::core::util::logging::LogLevel::kGRAPH); |
| 26 | + auto sg = std::make_shared<torch::jit::Graph>(); |
| 27 | + torch::jit::parseIR(source_graph, &*sg); |
| 28 | + torch_tensorrt::core::lowering::passes::RemoveContiguous(sg); |
| 29 | + torch_tensorrt::core::lowering::passes::ViewToReshape(sg); |
| 30 | + |
| 31 | + auto tg = std::make_shared<torch::jit::Graph>(); |
| 32 | + torch::jit::parseIR(target_graph, &*tg); |
| 33 | + |
| 34 | + ASSERT_TRUE(!torch::jit::findPatternMatches(*tg, *sg).empty()); |
| 35 | +} |
0 commit comments