如何插入tensorflow中使用的cuda runtime API?

How to interpose cuda runtime API used within tensorflow?

我已经在带有 CUDA 10 和合适 GPU 的 x86-64 Ubuntu 计算机上安装了 tensorflow(不是来自源代码)。我的目标是拦截(使用 LD_PRELOAD)任何 tensorflow 应用程序的 CUDA 运行时 API。不幸的是,对于我的用例,我无法从不是 x86-64 的目标机器的源代码构建 tensorflow。

我能够拦截我从用 C++ 编写的动态加载 cuda 运行时的测试程序发出的 cudaLaunchKernel 调用 API,并且在第一次检查时我认为 python 应该类似地动态加载相同的 cuda .so - 我很困惑,因为 LD_PRELOAD 不适用于正常安装的 tensorflow 应用程序 运行 cuda 已启用。

我希望 tensorflow 中的 cudaLaunchKernel 调用应该被我 LD_PRELOAD 的插入库拦截。这是正确的吗?

Tensorflow 编写 stream_executor 似乎是为了避免使用 CUDA 的运行时 API,而是用开源代码包装 CUDA 的驱动程序 API (cuLaunchKernel) 本身。 这在this中被引用 Pull Request to Tensorflow to allow interposing of CUDA's Runtime API, which was rejected. As well, in TF source (see here),我们看到正在积极使用 cu*/driver API 而不是运行时 API。