|
| 1 | +#include <string> |
| 2 | +#include "core/compiler.h" |
| 3 | +#include "gtest/gtest.h" |
| 4 | +#include "tests/util/util.h" |
| 5 | +#include "torch/csrc/jit/ir/irparser.h" |
| 6 | + |
| 7 | +TEST(Converters, ATenCumsumConvertsCorrectly) { |
| 8 | + const auto graph = R"IR( |
| 9 | + graph(%0 : Tensor): |
| 10 | + %1 : int = prim::Constant[value=1]() |
| 11 | + %2 : None = prim::Constant() |
| 12 | + %3 : Tensor = aten::cumsum(%0, %1, %2) |
| 13 | + return (%3))IR"; |
| 14 | + |
| 15 | + auto g = std::make_shared<torch::jit::Graph>(); |
| 16 | + torch::jit::parseIR(graph, &*g); |
| 17 | + |
| 18 | + auto in = at::randint(-5, 5, {2, 3, 4}, {at::kCUDA}); |
| 19 | + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 20 | + auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); |
| 21 | + |
| 22 | + in = at::clone(in); |
| 23 | + params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 24 | + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in}); |
| 25 | + |
| 26 | + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt_results[0], 2e-6)); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(Converters, ATenCumsumConvertsCorrectlyWithDynamicInput) { |
| 30 | + const auto graph = R"IR( |
| 31 | + graph(%0 : Tensor): |
| 32 | + %1 : int = prim::Constant[value=1]() |
| 33 | + %2 : None = prim::Constant() |
| 34 | + %3 : Tensor = aten::cumsum(%0, %1, %2) |
| 35 | + return (%3))IR"; |
| 36 | + |
| 37 | + auto g = std::make_shared<torch::jit::Graph>(); |
| 38 | + torch::jit::parseIR(graph, &*g); |
| 39 | + |
| 40 | + auto in = at::randint(-5, 5, {2, 3, 4}, {at::kCUDA}); |
| 41 | + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 42 | + auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); |
| 43 | + |
| 44 | + in = at::clone(in); |
| 45 | + params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 46 | + auto trt_results = trtorch::tests::util::RunGraphEngineDynamic(g, params, {in}); |
| 47 | + |
| 48 | + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt_results[0], 2e-6)); |
| 49 | +} |
| 50 | + |
| 51 | +TEST(Converters, ATenCumsumNegativeDimConvertsCorrectly) { |
| 52 | + const auto graph = R"IR( |
| 53 | + graph(%0 : Tensor): |
| 54 | + %1 : int = prim::Constant[value=-2]() |
| 55 | + %2 : None = prim::Constant() |
| 56 | + %3 : Tensor = aten::cumsum(%0, %1, %2) |
| 57 | + return (%3))IR"; |
| 58 | + |
| 59 | + auto g = std::make_shared<torch::jit::Graph>(); |
| 60 | + torch::jit::parseIR(graph, &*g); |
| 61 | + |
| 62 | + auto in = at::randint(-5, 5, {2, 3, 4}, {at::kCUDA}); |
| 63 | + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 64 | + auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); |
| 65 | + |
| 66 | + in = at::clone(in); |
| 67 | + params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 68 | + auto trt_results = trtorch::tests::util::RunGraphEngine(g, params, {in}); |
| 69 | + |
| 70 | + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt_results[0], 2e-6)); |
| 71 | +} |
| 72 | + |
| 73 | +TEST(Converters, ATenCumsumNegativeDimConvertsCorrectlyWithDynamicInput) { |
| 74 | + const auto graph = R"IR( |
| 75 | + graph(%0 : Tensor): |
| 76 | + %1 : int = prim::Constant[value=-2]() |
| 77 | + %2 : None = prim::Constant() |
| 78 | + %3 : Tensor = aten::cumsum(%0, %1, %2) |
| 79 | + return (%3))IR"; |
| 80 | + |
| 81 | + auto g = std::make_shared<torch::jit::Graph>(); |
| 82 | + torch::jit::parseIR(graph, &*g); |
| 83 | + |
| 84 | + auto in = at::randint(-5, 5, {2, 3, 4}, {at::kCUDA}); |
| 85 | + auto params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 86 | + auto jit_results = trtorch::tests::util::RunGraph(g, params, {in}); |
| 87 | + |
| 88 | + in = at::clone(in); |
| 89 | + params = trtorch::core::conversion::get_named_params(g->inputs(), {}); |
| 90 | + auto trt_results = trtorch::tests::util::RunGraphEngineDynamic(g, params, {in}); |
| 91 | + |
| 92 | + ASSERT_TRUE(trtorch::tests::util::almostEqual(jit_results[0], trt_results[0], 2e-6)); |
| 93 | +} |
0 commit comments