| 91 | } // anonymous namespace |
| 92 | |
| 93 | TEST(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 | |
| 126 | TEST(TestGraph, MemFwd0) { |
| 127 | HostTensorGenerator<> gen; |
nothing calls this directly
no test coverage detected