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

Function test_peer_copy_from_device

src/core/test/comp_node.cpp:434–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432
433namespace {
434void test_peer_copy_from_device(const char* comp_node) {
435 REQUIRE_THREAD();
436 auto cn_gpu = CompNode::load(comp_node);
437 auto cn_cpu = CompNode::load("cpux");
438
439 HostTensorGenerator<> gen;
440 auto a = gen({20, 3, 112, 112});
441 auto b = gen({20, 3, 112, 112});
442 auto c = gen({20, 3, 112, 112});
443 DeviceTensorND dev_a{cn_gpu}, dev_b{cn_cpu}, dev_c{cn_gpu};
444 dev_a.copy_from(*a).sync();
445 dev_b.copy_from(*b).sync();
446 dev_c.copy_from(*c).sync();
447
448 auto wait_event = cn_gpu.create_event();
449
450 opr::Sleep::sleep(cn_gpu, 0.1);
451 dev_a.copy_from(dev_c);
452 wait_event->record();
453 cn_cpu.device_wait_event(*wait_event);
454 dev_b.copy_from(dev_a);
455
456 dev_b.sync();
457
458 HostTensorND result;
459 result.copy_from(dev_b);
460
461 CompNode::sync_all();
462
463 MGB_ASSERT_TENSOR_EQ(result, *c);
464}
465} // namespace
466
467TEST(TestCompNodeCPU, PeerCopyFromCUDA) {

Callers 1

TESTFunction · 0.85

Calls 7

device_wait_eventMethod · 0.80
loadFunction · 0.50
genFunction · 0.50
syncMethod · 0.45
copy_fromMethod · 0.45
create_eventMethod · 0.45
recordMethod · 0.45

Tested by

no test coverage detected