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

Function ExecuteWithProfiling

tensorflow/c/eager/c_api_experimental_test.cc:42–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void ExecuteWithProfiling(bool async) {
43 TF_Status* status = TF_NewStatus();
44 TFE_ContextOptions* opts = TFE_NewContextOptions();
45 TFE_ContextOptionsSetAsync(opts, static_cast<unsigned char>(async));
46 TFE_Context* ctx = TFE_NewContext(opts, status);
47 TFE_Profiler* profiler = TFE_NewProfiler();
48 CHECK_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
49 TFE_DeleteContextOptions(opts);
50
51 TFE_TensorHandle* m = TestMatrixTensorHandle();
52 TFE_Op* matmul = MatMulOp(ctx, m, m);
53 TFE_TensorHandle* retvals[1] = {nullptr};
54 int num_retvals = 1;
55
56 // Run op on GPU if it is present.
57 string gpu_device_name;
58 if (GetDeviceName(ctx, &gpu_device_name, "GPU")) {
59 TFE_OpSetDevice(matmul, gpu_device_name.c_str(), status);
60 ASSERT_TRUE(TF_GetCode(status) == TF_OK) << TF_Message(status);
61 }
62
63 TFE_Execute(matmul, &retvals[0], &num_retvals, status);
64 EXPECT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
65 TFE_DeleteOp(matmul);
66 TFE_DeleteTensorHandle(m);
67
68 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
69 ASSERT_EQ(1, num_retvals);
70 TF_Buffer* profiler_result = TF_NewBuffer();
71 if (async) {
72 TFE_Executor* executor = TFE_ContextGetExecutorForThread(ctx);
73 TFE_ExecutorWaitForAllPendingNodes(executor, status);
74 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
75 TFE_DeleteExecutor(executor);
76 }
77 TFE_ProfilerSerializeToString(profiler, profiler_result, status);
78 TFE_DeleteProfiler(profiler);
79 ASSERT_EQ(TF_OK, TF_GetCode(status)) << TF_Message(status);
80 profiler::Trace profile_proto;
81 EXPECT_TRUE(profile_proto.ParseFromString(
82 {reinterpret_cast<const char*>(profiler_result->data),
83 profiler_result->length}));
84 string profile_proto_str = profile_proto.DebugString();
85 if (!gpu_device_name.empty()) {
86 EXPECT_TRUE(HasSubstr(profile_proto_str, "/device:GPU:0"));
87 // device name with "stream:all" is collected by Device Tracer.
88#ifndef TENSORFLOW_USE_ROCM
89 // ROCm platform does not yet support stream level tracing
90 EXPECT_TRUE(HasSubstr(profile_proto_str, "stream:all"));
91#endif
92 }
93 // "/host:CPU" is collected by TraceMe
94 EXPECT_TRUE(HasSubstr(profile_proto_str, "/host:CPU"));
95 EXPECT_TRUE(HasSubstr(profile_proto_str, "MatMul"));
96 TF_DeleteBuffer(profiler_result);
97
98 TF_Tensor* t = TFE_TensorHandleResolve(retvals[0], status);
99 TFE_DeleteTensorHandle(retvals[0]);

Callers 1

TESTFunction · 0.85

Calls 15

TF_NewStatusFunction · 0.85
TFE_NewContextOptionsFunction · 0.85
TFE_NewContextFunction · 0.85
TFE_NewProfilerFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TFE_DeleteContextOptionsFunction · 0.85
TestMatrixTensorHandleFunction · 0.85
TFE_OpSetDeviceFunction · 0.85
TFE_ExecuteFunction · 0.85
TFE_DeleteOpFunction · 0.85

Tested by

no test coverage detected