简体   繁体   English

如何使用C ++ API限制tensorflow(r1.1)中的GPU使用率

[英]how to limit GPU usage in tensorflow (r1.1) with C++ API

I'd like to limit GPU allocation of tensorflow in the C++ API. 我想在C ++ API中限制GPU分配的tensorflow。 I know how to do it in python , and it's probably got something to do with struct SessionOptions passed into NewSession(), but I couldn't find more specific info on how to do it. 我知道如何在python中做到这一点,它可能与传递给NewSession()的struct SessionOptions有关,但是我找不到更多关于如何做的具体信息。

Edit: Stackoverflow is suggesting that my question is a duplicate. 编辑:Stackoverflow表明我的问题是重复的。 However I already link to that other post. 但是我已经链接到其他帖子了。 That is how to do it in python. 这是如何在python中做到这一点。 I'm specifically asking how to do it in C++. 我特别想问如何用C ++做。

Turns out to be quite simple: 结果很简单:

tensorflow::SessionOptions session_options;
session_options.config.mutable_gpu_options()->set_allow_growth(allow_growth);
session_options.config.mutable_gpu_options()->set_per_process_gpu_memory_fraction(per_process_gpu_memory_fraction);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM