forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_te_fuser_pass.cpp
65 lines (56 loc) · 1.99 KB
/
test_te_fuser_pass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <test/cpp/tensorexpr/test_base.h>
#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/jit/ir/irparser.h>
#include <torch/csrc/jit/passes/tensorexpr_fuser.h>
#include <torch/csrc/jit/tensorexpr/mem_arena.h>
#include <torch/csrc/jit/testing/file_check.h>
#include <sstream>
namespace torch {
namespace jit {
using namespace torch::jit::tensorexpr;
void testFuserPass_1() {
KernelScope kernel_scope;
const auto graph_string = R"IR(
graph(%0 : Float(128:1, device=cpu),
%1 : Float(128:1, device=cpu)):
%12 : int = prim::Constant[value=1]()
%2.1 : Float(128:1, device=cpu) = aten::mul(%0, %1)
%2 : Float(128:1, device=cpu) = aten::mul(%2.1, %1)
%3 : Float(128:1, device=cpu) = aten::add_(%2, %1, %12)
%4 : Float(128:1, device=cpu) = aten::mul(%2, %1)
%5 : Float(128:1, device=cpu) = aten::add(%2, %4, %12)
return (%5))IR";
auto g = std::make_shared<Graph>();
torch::jit::parseIR(graph_string, g.get());
g->lint();
FuseTensorExprs(g);
// We should not be able to fuse across the in-place operation here.
testing::FileCheck()
.check("tensorexpr::Group_0")
->check("aten::add_")
->check("tensorexpr::Group_1")
->run(*g);
}
void testFuserPass_2() {
KernelScope kernel_scope;
const auto graph_string = R"IR(
graph(%0 : Float(128:1, device=cpu),
%1 : Float(128:1, device=cpu)):
%12 : int = prim::Constant[value=1]()
%a : Float(128:1, device=cpu) = aten::mul(%0, %1)
%b : Float(128:1, device=cpu) = aten::add(%0, %1, %12)
%c : Float(128:1, device=cpu) = aten::add_(%b, %1, %12)
%d : Float(128:1, device=cpu) = aten::mul(%c, %a)
return (%d))IR";
auto g = std::make_shared<Graph>();
torch::jit::parseIR(graph_string, g.get());
g->lint();
FuseTensorExprs(g);
// We should not be able to fuse across the in-place operation here.
testing::FileCheck()
.check("aten::add_")
->check("tensorexpr::Group_0")
->run(*g);
}
} // namespace jit
} // namespace torch