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

Function test_basic_input_no_copy

src/gopt/test/no_memory_copy.cpp:163–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161
162namespace {
163void test_basic_input_no_copy(bool record) {
164 auto test_graph = TestGraph();
165 auto compute_graph = test_graph.m_network->graph;
166 compute_graph->options().comp_node_seq_record_level = record;
167 test_graph.create_graph();
168 HostTensorND out, out_pre;
169 auto func = test_graph.compile_with_copy(out);
170 size_t times = 10;
171 for (size_t i = 0; i < times; i++) {
172 if (i % 2 == 0) {
173 auto input_tensor = test_graph.input_tensor;
174 auto layout = input_tensor->layout();
175 size_t length = layout.total_nr_elems();
176 auto storage = TensorStorage<HostTensorStorageTrait>(test_graph.m_cn);
177 storage.ensure_size(length * sizeof(float));
178 float* ptr = storage.ptr()->as<float>();
179 for (size_t d = 0; d < length; d++) {
180 ptr[d] = i;
181 }
182 if (record) {
183 input_tensor->only_reset_raw_storage(storage);
184 } else {
185 input_tensor->reset(storage, layout);
186 }
187 }
188 func->execute();
189 func->wait();
190 if (i % 2 != 0) {
191 MGB_ASSERT_TENSOR_EQ(out, out_pre);
192 }
193 out_pre.copy_from(out).sync();
194 }
195}
196} // namespace
197
198TEST(TestNoCopy, InputNoCopyPtrEQ) {

Callers 1

TESTFunction · 0.85

Calls 12

TestGraphClass · 0.85
create_graphMethod · 0.80
compile_with_copyMethod · 0.80
layoutMethod · 0.45
total_nr_elemsMethod · 0.45
ptrMethod · 0.45
resetMethod · 0.45
executeMethod · 0.45
waitMethod · 0.45
syncMethod · 0.45
copy_fromMethod · 0.45

Tested by

no test coverage detected