| 7 | using namespace imperative; |
| 8 | |
| 9 | TEST(TestImperative, IORemote) { |
| 10 | REQUIRE_GPU(2); |
| 11 | const char* server_addr = "127.0.0.1"; |
| 12 | uint32_t port = 4567; |
| 13 | mgb_assert(opr::create_zmqrpc_server(server_addr, port) > 0); |
| 14 | HostTensorGenerator<> gen; |
| 15 | CompNode cn0 = CompNode::load("gpu0"), cn1 = CompNode::load("gpu1"); |
| 16 | |
| 17 | size_t vector_size = 233; |
| 18 | auto host_x = gen({vector_size}, cn0), host_y = gen({vector_size}, cn1); |
| 19 | |
| 20 | auto expect = gen({vector_size}); |
| 21 | for (size_t i = 0; i < vector_size; ++i) { |
| 22 | expect->ptr<float>()[i] = host_x->ptr<float>()[i]; |
| 23 | } |
| 24 | |
| 25 | auto run_send = [&](std::shared_ptr<HostTensorND> hnd) { |
| 26 | auto def = imperative::RemoteSend::make( |
| 27 | "io_remote_test", server_addr, port, 1, "nccl"); |
| 28 | auto inp = Tensor::make(*hnd); |
| 29 | SmallVector<LogicalTensorDesc> output_descs; |
| 30 | auto oup = OpDef::apply_on_physical_tensor(*def, {inp}, output_descs, false); |
| 31 | }; |
| 32 | |
| 33 | auto run_recv = [&](std::shared_ptr<HostTensorND> hnd) { |
| 34 | auto def = imperative::RemoteRecv::make( |
| 35 | "io_remote_test", server_addr, port, 0, CompNode::load("gpu1"), |
| 36 | std::vector<int32_t>{(int32_t)vector_size}, dtype::Float32(), "nccl"); |
| 37 | auto inp = Tensor::make(*hnd); |
| 38 | SmallVector<LogicalTensorDesc> output_descs; |
| 39 | auto oup = OpDef::apply_on_physical_tensor(*def, {inp}, output_descs, false); |
| 40 | HostTensorND host_v; |
| 41 | host_v.copy_from(oup[0]->dev_tensor()).sync(); |
| 42 | MGB_ASSERT_TENSOR_NEAR(*expect, host_v, 1e-6); |
| 43 | }; |
| 44 | |
| 45 | std::thread t0(std::bind(run_send, host_x)); |
| 46 | std::thread t1(std::bind(run_recv, host_y)); |
| 47 | |
| 48 | t0.join(); |
| 49 | t1.join(); |
| 50 | } |
| 51 | // vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}} |
nothing calls this directly
no test coverage detected