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

Function BM_ExecuteFunction

tensorflow/c/eager/c_api_test.cc:1381–1423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1379TEST(CAPI, FunctionDefAndExecuteAsync) { FunctionDefAndExecute(true); }
1380
1381void BM_ExecuteFunction(int iters, int async) {
1382 tensorflow::testing::StopTiming();
1383 tensorflow::testing::SetLabel(async ? "ExecuteFunctionAsync"
1384 : "ExecuteFunction");
1385 TF_Status* status = TF_NewStatus();
1386 TFE_ContextOptions* opts = TFE_NewContextOptions();
1387 TFE_ContextOptionsSetAsync(opts, static_cast<unsigned char>(async));
1388 TFE_Context* ctx = TFE_NewContext(opts, status);
1389 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1390 TFE_DeleteContextOptions(opts);
1391
1392 string function_def = MatMulFunction();
1393 TFE_ContextAddFunctionDef(ctx, function_def.data(), function_def.size(),
1394 status);
1395 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1396
1397 TFE_TensorHandle* m = TestMatrixTensorHandle();
1398 TFE_Op* matmul = TFE_NewOp(ctx, "MatMulFunction", status);
1399 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1400 TFE_OpAddInput(matmul, m, status);
1401 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1402 TFE_TensorHandle* retval[1] = {nullptr};
1403 int num_retvals = 1;
1404 tensorflow::testing::StartTiming();
1405 for (int i = 0; i < iters; ++i) {
1406 TFE_Execute(matmul, &retval[0], &num_retvals, status);
1407 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1408 }
1409 if (async) {
1410 TFE_Executor* executor = TFE_ContextGetExecutorForThread(ctx);
1411 TFE_ExecutorWaitForAllPendingNodes(executor, status);
1412 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1413 TFE_DeleteExecutor(executor);
1414 }
1415 tensorflow::testing::StopTiming();
1416 TFE_DeleteTensorHandle(m);
1417 TFE_DeleteTensorHandle(retval[0]);
1418 TFE_ContextRemoveFunction(ctx, "MatMulFunction", status);
1419 ASSERT_TRUE(TF_GetCode(status) == TF_OK) << TF_Message(status);
1420 TFE_DeleteContext(ctx);
1421 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1422 TF_DeleteStatus(status);
1423}
1424BENCHMARK(BM_ExecuteFunction)->Arg(0)->Arg(1);
1425
1426TFE_TensorHandle* CreateVariable(TFE_Context* ctx, float value,

Callers

nothing calls this directly

Calls 15

StopTimingFunction · 0.85
SetLabelFunction · 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
TestMatrixTensorHandleFunction · 0.85
TFE_NewOpFunction · 0.85

Tested by

no test coverage detected