9

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++.

memo
  • 3,554
  • 4
  • 31
  • 36

1 Answers1

10

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);
memo
  • 3,554
  • 4
  • 31
  • 36