diff --git a/examples/cpp/hello_tf.cpp b/examples/cpp/hello_tf.cpp index e8097a30e..0a549f241 100644 --- a/examples/cpp/hello_tf.cpp +++ b/examples/cpp/hello_tf.cpp @@ -35,16 +35,20 @@ using namespace std; // Prints the available backends -void PrintAvailableBackends() { +int PrintAvailableBackends() { // Get the list of backends auto supported_backends = tensorflow::ngraph_bridge::BackendManager::GetSupportedBackendNames(); vector backends(supported_backends.begin(), supported_backends.end()); - - cout << "Available backends: " << endl; + if (backends.empty()) { + std::cout << "No backend available " << std::endl; + return -1; + } + std::cout << "Available backends: " << std::endl; for (auto& backend_name : backends) { - cout << "Backend: " << backend_name << std::endl; + std::cout << "Backend: " << backend_name << std::endl; } + return 0; } // Create a simple computation graph and run @@ -116,13 +120,18 @@ void PrintVersion() { ? std::string("Yes") : std::string("No")) << std::endl; - - PrintAvailableBackends(); + std::cout << std::endl; } int main(int argc, char** argv) { PrintVersion(); + // Print the avialable backends and if none are available + // error out + if (PrintAvailableBackends()) { + return -1; + } + // Run a simple example RunSimpleNetworkExample(); diff --git a/ngraph_bridge/ngraph_backend_manager.cc b/ngraph_bridge/ngraph_backend_manager.cc index 45bd45c2f..926437200 100644 --- a/ngraph_bridge/ngraph_backend_manager.cc +++ b/ngraph_bridge/ngraph_backend_manager.cc @@ -134,10 +134,24 @@ void BackendManager::UnlockBackend(const string& backend_name) { // Returns the nGraph supported backend names vector BackendManager::GetSupportedBackendNames() { +// Register backends for static linking +#if defined(NGRAPH_CPU_STATIC_LIB_ENABLE) + ngraph_register_cpu_backend(); +#endif +#if defined(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE) + ngraph_register_interpreter_backend(); +#endif return ng::runtime::BackendManager::get_registered_backends(); } size_t BackendManager::GetNumOfSupportedBackends() { +// Register backends for static linking +#if defined(NGRAPH_CPU_STATIC_LIB_ENABLE) + ngraph_register_cpu_backend(); +#endif +#if defined(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE) + ngraph_register_interpreter_backend(); +#endif return ng::runtime::BackendManager::get_registered_backends().size(); }