我在Windows 10上从源(分支r1.7)编译了具有GPU支持的tensorflow C ++。创建新会话后,在GPU上分配了3GB内存。通过nvidia-smi命令确认,关闭会话似乎不会导致内存从GPU释放。仅当C ++程序退出时才释放GPU内存。如何用代码释放内存?
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