问题
I know how to set intra and inter threads in python tensorflow which is as shown below
n_cpus=1
sess = tf.Session(config=tf.ConfigProto(
device_count={ "CPU": n_cpus },
inter_op_parallelism_threads=n_cpus,
intra_op_parallelism_threads=8
));
But I need to implement this in c++. SO any equivalent code to set inter and intra threads in tensorflow c++ ??
回答1:
You can implement this in C++ by using the following code.
Status LoadGraph(string graph_file_name, std::unique_ptr<tensorflow::Session>* session) {
tensorflow::GraphDef graph_def;
Status load_graph_status =
ReadBinaryProto(tensorflow::Env::Default(), graph_file_name, &graph_def);
if (!load_graph_status.ok()) {
return tensorflow::errors::NotFound("Failed to load compute graph at '",
graph_file_name, "'");
}
// initialize the number of worker threads
tensorflow::SessionOptions options;
tensorflow::ConfigProto & config = options.config;
config.set_inter_op_parallelism_threads(1);
config.set_intra_op_parallelism_threads(1);
config.set_use_per_session_threads(false);
session->reset(tensorflow::NewSession(options));
Status session_create_status = (*session)->Create(graph_def);
if (!session_create_status.ok()) {
return session_create_status;
}
return Status::OK();
}
来源:https://stackoverflow.com/questions/61361334/how-to-set-inter-op-parallelism-threads-and-intra-op-parallelism-threads-for-see