MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TestRemoteExecute

Function TestRemoteExecute

tensorflow/c/eager/c_api_test.cc:173–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173void TestRemoteExecute(bool async) {
174 tensorflow::ServerDef server_def = GetServerDef(2);
175
176 // This server def has the task index set to 0.
177 string serialized = server_def.SerializeAsString();
178
179 server_def.set_task_index(1);
180
181 std::unique_ptr<tensorflow::GrpcServer> worker_server;
182 ASSERT_TRUE(tensorflow::GrpcServer::Create(
183 server_def, tensorflow::Env::Default(), &worker_server)
184 .ok());
185 ASSERT_TRUE(worker_server->Start().ok());
186
187 TF_Status* status = TF_NewStatus();
188 TFE_ContextOptions* opts = TFE_NewContextOptions();
189 TFE_ContextOptionsSetAsync(opts, static_cast<unsigned char>(async));
190 TFE_ContextOptionsSetDevicePlacementPolicy(opts,
191 TFE_DEVICE_PLACEMENT_EXPLICIT);
192 TFE_Context* ctx = TFE_NewContext(opts, status);
193 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
194 TFE_DeleteContextOptions(opts);
195
196 TFE_ContextSetServerDef(ctx, 0, serialized.data(), serialized.size(), status);
197 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
198
199 TFE_TensorHandle* h0_task0 = TestMatrixTensorHandle();
200 TFE_TensorHandle* h1_task0 = TestMatrixTensorHandle();
201 const char remote_device_name[] =
202 "/job:localhost/replica:0/task:1/device:CPU:0";
203 auto* h0_task1 =
204 TFE_TensorHandleCopyToDevice(h0_task0, ctx, remote_device_name, status);
205 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
206 auto* h1_task1 =
207 TFE_TensorHandleCopyToDevice(h1_task0, ctx, remote_device_name, status);
208 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
209
210 TFE_Op* matmul = MatMulOp(ctx, h0_task1, h1_task1);
211 TFE_OpSetDevice(matmul, remote_device_name, status);
212 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
213
214 TFE_TensorHandle* retvals[1];
215 int num_retvals = 1;
216 TFE_Execute(matmul, &retvals[0], &num_retvals, status);
217 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
218
219 TF_Tensor* t = TFE_TensorHandleResolve(retvals[0], status);
220 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
221 float product[4] = {0};
222 EXPECT_EQ(sizeof(product), TF_TensorByteSize(t));
223 memcpy(&product[0], TF_TensorData(t), TF_TensorByteSize(t));
224 TF_DeleteTensor(t);
225 EXPECT_EQ(7, product[0]);
226 EXPECT_EQ(10, product[1]);
227 EXPECT_EQ(15, product[2]);
228 EXPECT_EQ(22, product[3]);
229
230 TFE_DeleteTensorHandle(h0_task0);

Callers 1

TESTFunction · 0.85

Calls 15

DefaultFunction · 0.85
TF_NewStatusFunction · 0.85
TFE_NewContextOptionsFunction · 0.85
TFE_NewContextFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TFE_DeleteContextOptionsFunction · 0.85
TFE_ContextSetServerDefFunction · 0.85
TestMatrixTensorHandleFunction · 0.85

Tested by

no test coverage detected