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

Function test_subtensor_record

src/gopt/test/no_memory_copy.cpp:388–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386
387namespace {
388void test_subtensor_record(int level) {
389 auto test_graph = TestGraph();
390 auto compute_graph = test_graph.m_network->graph;
391 compute_graph->options().force_output_use_user_specified_memory = true;
392 compute_graph->options().comp_node_seq_record_level = 1;
393 if (level == 2) {
394 test_graph.create_graph_with_setsubtensor();
395 } else if (level == 1) {
396 test_graph.create_graph_with_subtensor_forward();
397 } else {
398 test_graph.create_graph_with_subtensor_relayout();
399 }
400 HostTensorND truth;
401 auto func = test_graph.compile_without_copy();
402 auto&& outvar = func->get_output_vars()[0];
403 DeviceTensorND tmp(test_graph.m_cn, {2, 8, 7, 7});
404 outvar->init_mem_plan(&tmp);
405 size_t times = 10;
406 for (size_t i = 0; i < times; i++) {
407 auto input_tensor = test_graph.input_tensor;
408 auto layout = input_tensor->layout();
409 size_t length = layout.total_nr_elems();
410 auto storage = TensorStorage<HostTensorStorageTrait>(test_graph.m_cn);
411 storage.ensure_size(length * sizeof(float));
412 float* ptr = storage.ptr()->as<float>();
413 for (size_t d = 0; d < length; d++) {
414 ptr[d] = i / 5 + 3;
415 }
416 input_tensor->only_reset_raw_storage(storage);
417 DeviceTensorND dv(test_graph.m_cn, {2, 8, 7, 7});
418 dv.raw_ptr();
419
420 auto& dev_tensor = outvar->mutable_dev_tensor();
421 dev_tensor.only_reset_raw_storage(dv.storage());
422
423 func->execute();
424 func->wait();
425 if (i % 5 == 0) {
426 truth.copy_from(dv).sync();
427 continue;
428 }
429 HostTensorND to_check;
430 to_check.copy_from(dv).sync();
431 MGB_ASSERT_TENSOR_EQ(to_check, truth);
432 }
433}
434} // namespace
435
436TEST(TestNoCopy, IONoCopyRecordSubTensor) {

Callers 1

TESTFunction · 0.85

Calls 15

TestGraphClass · 0.85
compile_without_copyMethod · 0.80
storageMethod · 0.80
layoutMethod · 0.45
total_nr_elemsMethod · 0.45
ptrMethod · 0.45
raw_ptrMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected