MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / TEST

Function TEST

src/tensorrt/test/opr_replace.cpp:33–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31using namespace tensorrt;
32
33TEST(TestTensorRTReplace, Basic) {
34 REQUIRE_GPU(1);
35 HostTensorGenerator<> gen;
36 std::shared_ptr<HostTensorND> host_x, host_w, host_b, host_w_full, host_o;
37 std::shared_ptr<ComputingGraph> graph;
38
39 host_x = gen({5, 8, 28, 28});
40 host_w = gen({2, 16, 4, 3, 3});
41 host_b = gen({1, 32, 1, 1});
42 host_w_full = gen({32 * 13 * 13, 10});
43 host_o = gen({1, 10});
44
45 graph = ComputingGraph::make();
46 using ConvParam = megdnn::Convolution::Param;
47 ConvParam conv_param1;
48 conv_param1.sparse = ConvParam::Sparse::GROUP;
49 auto x = Host2DeviceCopy::make(*graph, host_x),
50 w_conv1 = SharedDeviceTensor::make(*graph, *host_w),
51 b_conv1 = SharedDeviceTensor::make(*graph, *host_b),
52 f_conv1 = opr::Convolution::make(x, w_conv1, conv_param1),
53 y_conv1 = f_conv1 + b_conv1;
54 using PoolParam = megdnn::Pooling::Param;
55 PoolParam pool_param1;
56 pool_param1.mode = PoolParam::Mode::MAX;
57 pool_param1.window_h = 2;
58 pool_param1.window_w = 2;
59 auto y_reshape = y_conv1.reshape({5, 32, 26, 26});
60 auto y_pooling1 = opr::Pooling::make(y_reshape, pool_param1);
61 auto w_full1 = SharedDeviceTensor::make(*graph, *host_w_full);
62 auto x_full1 = y_pooling1.reshape({5, 32 * 13 * 13});
63 auto y_full1 = opr::MatrixMul::make(x_full1, w_full1);
64 auto o = SharedDeviceTensor::make(*graph, *host_o);
65 auto out = y_full1 + o;
66
67 SymbolVar out_trt;
68 unpack_vector(
69 gopt::GraphOptimizer{}
70 .add_pass<gopt::TensorRTReplacePass>()
71 .apply({{out}})
72 .endpoint_vars(),
73 out_trt);
74 HostTensorND host_z1;
75 HostTensorND host_z2;
76
77 ASSERT_NE(out_trt.node(), out.node());
78 auto func = graph->compile(
79 {make_callback_copy(out, host_z1), make_callback_copy(out_trt, host_z2)});
80 func->execute();
81
82 MGB_ASSERT_TENSOR_NEAR(host_z1, host_z2, 1e-3);
83}
84
85TEST(TensorRTReplacePass, MatrixMul) {
86 REQUIRE_GPU(1);

Callers

nothing calls this directly

Calls 15

unpack_vectorFunction · 0.85
make_callback_copyFunction · 0.85
maxFunction · 0.85
make_deconvFunction · 0.85
addFunction · 0.85
subFunction · 0.85
iobuf_sizeMethod · 0.80
make_scalar_dtMethod · 0.80
emplace_backMethod · 0.80
set_dtypeMethod · 0.80
renameMethod · 0.80
genFunction · 0.50

Tested by

no test coverage detected