Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

tensorflow

I'd like to limit GPU allocation of tensorflow in the C++ API. 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.

Edit: Stackoverflow is suggesting that my question is a duplicate. However I already link to that other post. That is how to do it in python. I'm specifically asking how to do it in C++.

like image 756
memo Avatar asked May 30 '17 12:05

memo


1 Answers

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);
like image 112
memo Avatar answered Nov 02 '22 23:11

memo