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

Function TEST

src/core/test/graph/mem_fwd.cpp:93–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91} // anonymous namespace
92
93TEST(TestGraph, ShareDevMem) {
94 HostTensorGenerator<> gen;
95 auto host_x = gen({1234});
96
97 auto make_graph = [&]() {
98 auto graph = ComputingGraph::make();
99 auto x = opr::Host2DeviceCopy::make(*graph, host_x), y = x + 1;
100 return std::make_pair(graph, y);
101 };
102
103 auto run = [&](bool share) {
104 HostTensorND host_y0, host_y1;
105 auto g0 = make_graph(), g1 = make_graph();
106 if (share)
107 g0.first->share_device_memory_with(*g1.first);
108 auto f0 = g0.first->compile({make_callback_copy(g0.second, host_y0)});
109 auto f1 = g1.first->compile({make_callback_copy(g1.second, host_y1)});
110 f0->execute();
111 f1->execute();
112 f0->wait();
113 f1->wait();
114 if (share) {
115 ASSERT_EQ(dev_ptr(g0.second), dev_ptr(g1.second));
116 } else {
117 ASSERT_NE(dev_ptr(g0.second), dev_ptr(g1.second));
118 }
119 MGB_ASSERT_TENSOR_EQ(host_y0, host_y1);
120 };
121
122 run(false);
123 run(true);
124}
125
126TEST(TestGraph, MemFwd0) {
127 HostTensorGenerator<> gen;

Callers

nothing calls this directly

Calls 15

make_callback_copyFunction · 0.85
dev_ptrFunction · 0.85
make_no_fwdFunction · 0.85
maxFunction · 0.85
output_fileFunction · 0.85
addFunction · 0.85
prev_dev_ptrFunction · 0.85
is_static_var_storageFunction · 0.85
swapFunction · 0.85
set_priorityFunction · 0.85
renameMethod · 0.80
eq_layoutMethod · 0.80

Tested by

no test coverage detected