A little bit unusual use case is to try to run the program with Tensorflow dependencies on GPU and if the CUDA/cuDNN installation is misconfigured either catch missing library and gracefully stop the program, or catch missing library and set device to CPU.
Tensorflow is relatively smart and lets me run the code until session->run(...). Then, if say cudnn_ops_infer64_8.dll is not in the PATH the program stops and throws the following message:
Could not load library cudnn_ops_infer64_8.dll. Error code 126
Please make sure cudnn_ops_infer64_8.dll is in your library path!
This problem is not reflected in Status and seems to be not catchable by standard try...catch. Is it possible to make the described scenario work? Pseudo-code would be
tf_style_try {
session->Run({ {input_name, *input_tensor } }, { "StatefulPartitionedCall:0" }, {}, &predictions);
} catch (tf_style_exception &tfexception ) {
setDevice("/cpu:0");
session->Run({ {input_name, *input_tensor } }, { "StatefulPartitionedCall:0" }, {}, &predictions);
}
or maybe
bool libaries_ok = check_tf_libraries();
if(libraries_ok) {
// run on GPU
} else {
// run on CPU or stop gracefully
}