Neargye / hello_tf_c_api

Neural Network TensorFlow C API
MIT License
468 stars 134 forks source link

Specify device #13

Closed ttdd11 closed 5 years ago

ttdd11 commented 5 years ago

Thanks for this it is very helpful. Is it possible to specify a specific device for the graph (ie. gpu:0) as per the c++ api?

Neargye commented 5 years ago

Hi @ttdd11 Try something like

TF_OperationDescription* desc = TF_NewOperation(graph, op_type, op_name);
TF_SetDevice(desc, "/gpu:0");

I have not tried these operations, but I think you can search for information on these functions, it looks like they do what you need

ttdd11 commented 5 years ago

@Neargye Okay i tried this. Here is my code:

TF_Operation* op;
std::size_t pos = 0;

while ((op = TF_GraphNextOperation(graph, &pos)) != nullptr) {
    const char* name = TF_OperationName(op);
    QString strName = QString(name);
    TF_OperationDescription* desc = TF_NewOperation(graph, TF_OperationOpType(op), TF_OperationName(op));
    TF_SetDevice(desc, "/gpu:0");

Has no effect of the device being used.

Neargye commented 5 years ago

Unfortunately, I did not try to run on GPU using this function TF_ImportGraphDefOptionsSetDefaultDevice