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

Function BM_ReadVariable

tensorflow/c/eager/c_api_test.cc:1513–1550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1511}
1512
1513void BM_ReadVariable(int iters) {
1514 tensorflow::testing::StopTiming();
1515 TF_Status* status = TF_NewStatus();
1516 TFE_ContextOptions* opts = TFE_NewContextOptions();
1517 TFE_Context* ctx = TFE_NewContext(opts, status);
1518 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1519 TFE_DeleteContextOptions(opts);
1520
1521 TFE_TensorHandle* var_handle = CreateVariable(ctx, 5.0, status);
1522 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1523
1524 TFE_Op* op = TFE_NewOp(ctx, "ReadVariableOp", status);
1525 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1526 TFE_OpSetAttrType(op, "dtype", TF_FLOAT);
1527 TFE_OpAddInput(op, var_handle, status);
1528 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1529
1530 int num_retvals = 1;
1531 TFE_TensorHandle* h = nullptr;
1532 tensorflow::testing::StartTiming();
1533 for (int i = 0; i < iters; ++i) {
1534 TFE_Execute(op, &h, &num_retvals, status);
1535 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1536 CHECK_EQ(1, num_retvals);
1537 CHECK(h);
1538 CHECK_EQ(TF_FLOAT, TFE_TensorHandleDataType(h));
1539 CHECK_EQ(0, TFE_TensorHandleNumDims(h, status));
1540 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1541 h = nullptr;
1542 }
1543 tensorflow::testing::StopTiming();
1544 TFE_DeleteOp(op);
1545
1546 TFE_DeleteTensorHandle(var_handle);
1547 TFE_DeleteContext(ctx);
1548 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
1549 TF_DeleteStatus(status);
1550}
1551BENCHMARK(BM_ReadVariable);
1552
1553TEST(CAPI, StringAttributes) {

Callers

nothing calls this directly

Calls 15

StopTimingFunction · 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
CreateVariableFunction · 0.85
TFE_NewOpFunction · 0.85
TFE_OpSetAttrTypeFunction · 0.85
TFE_OpAddInputFunction · 0.85
StartTimingFunction · 0.85

Tested by

no test coverage detected