为什么 GPU 上的 Tensorflow 模型推理会引发如此多的 CUDA cuEventRecord API 调用?

Why Tensorflow model inference on GPU incurs so many CUDA cuEventRecord API calls?

我 运行 一个 GPU (Tesla P100) 上的 Tensorflow 对象检测模型(these models 之一)。为了检查性能瓶颈,我使用了 Nvidia nvprof 分析工具来分析我的对象检测应用程序(在几帧上执行对象检测)。分析结果如下

======== Profiling result:
  2             Type  Time(%)      Time     Calls       Avg       Min       Max  Name
  3       API calls:   32.13%  15.2177s    434480  35.025us  5.1550us  954.27ms  cudaLaunchKernel
  4                    30.20%  14.3065s    942706  15.175us     361ns  77.372ms  cuEventRecord
  5                    13.39%  6.34349s    117067  54.186us  2.7000us  5.4721ms  cudaFuncGetAttributes
  6                     6.26%  2.96509s    575202  5.1540us     562ns  1.2027ms  cuEventQuery
  7                     6.16%  2.91725s     67072  43.494us  7.2690us  77.337ms  cuMemcpyDtoHAsync
...

通过查看 Nvidia visual profiler,我发现对象检测应用程序包含多个线程。其中一些线程不断调用 cuEventRecord CUDA 驱动程序 API 调用。分析结果显示 cuEventRecord API 调用的持续时间约为 cuda 运行time+driver 活动总持续时间的 30%。我想知道这个 cuEventRecord API 调用是否与探查器有关:nvprof。如果不是,这些 cuEventRecord 调用是否会导致 tensorflow 模型推理的性能下降以及进行这些 cuEventRecord API 调用的意义何在?

I was wondering whether this cuEventRecord API call has something to do with the profiler: nvprof

没有。

If not, whether these cuEventRecord invocation would cause performance degradation for tensorflow model inference.

它们是 Tensorflow 正常运行的一部分。

what is the point to have these cuEventRecord API calls?

据我了解,Tensorflow 设计有大量流水线设备代码路径,该路径依赖于事件、流同步和流回调函数的广泛使用,以确保 GPU 保持占用状态,并且计算的不同阶段以正确的顺序安排、上传和下载。这可能就是您在这里看到的。