c++ - 关闭 session 后 Tensorflow C++ 不释放 GPU 资源

标签 c++ tensorflow gpu

我在 Windows 10 上从源代码(分支 r1.7)编译了带有 GPU 支持的 tensorflow C++。创建新 session 后,GPU 上分配了 3GB 内存。正如 nvidia-smi 命令所确认的那样,关闭 session 似乎不会导致从 GPU 释放内存。 GPU 内存仅在 C++ 程序退出时释放。如何在代码中释放内存?

int main()
{
    SessionOptions options;
    Session* session;
    tensorflow::Status status = NewSession(SessionOptions(), &session); // returns ok

    status = session->Close(); // returns ok
    delete session;

    // GPU memory is still occupied at this point
    std::string s;
    std::cin >> s;

    return 0;
}
// GPU memory is released when process exits

最佳答案

来自 doc :

Note that we do not release memory, since that can lead to even worse memory fragmentation.

当前 issue找到解决办法。似乎为了避免必须关闭自己的进程,您需要创建一个子进程来为您完成这项工作。

关于c++ - 关闭 session 后 Tensorflow C++ 不释放 GPU 资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51095257/

相关文章:

python - 将展平层与输入层连接

python - 分析时 TensorFlow 中的 NoOp 是什么?

tensorflow - CuDNNLSTM : Failed to call ThenRnnForward

c++ - 错误 1 ​​错误 C2678 : binary '!=' : no operator found which takes a left-hand operand of type 'std::ofstream' (or there is no acceptable conversion)

c++ - 在 VS2010 中动态链接 Boost 1.51.0 时链接器错误 LNK2019

python - Tensorflow - 数据维度、占位符

python - TensorFlow 对象检测 API 奇怪的行为

windows-10 - 如何使用 python 测量 Windows 中每个进程的 GPU 使用率?

c++ - 使用 openGL 绘制 OBJ 文件

c++ - 矩阵模板实现的不好的方面