Unverified Commit d7893701 authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Cyphers/exec can create tensors (#3445)

* Add method to check if an Executable can create tensors

* Add a Backend check to see if Executable can create tensors

* Update per review comment

* style

* Possible fix so that backend does not keep holding on to the dummy ng_exec
parent 005c1189
......@@ -151,3 +151,24 @@ bool runtime::Backend::set_config(const map<string, string>& config, string& err
error = "set_config not supported";
return false;
}
bool runtime::Backend::executable_can_create_tensors()
{
auto A = make_shared<op::Parameter>(element::f32, Shape());
auto function = make_shared<Function>(NodeVector{A}, ParameterVector{A});
auto exec = compile(function);
bool exec_can_create_tensors = false;
try
{
auto t0 = exec->create_input_tensor(0);
auto t1 = exec->create_input_tensor(0, 1);
auto t2 = exec->create_output_tensor(0);
auto t3 = exec->create_output_tensor(0, 1);
exec_can_create_tensors = true;
}
catch (...)
{
}
remove_compiled_function(exec);
return exec_can_create_tensors;
}
......@@ -172,6 +172,8 @@ public:
/// \param ptr pointer to the memory to determine if its in device memory or not
virtual bool is_device_memory(void* ptr);
virtual bool executable_can_create_tensors();
private:
// mutex to modify s_backend_shared_library_search_directory thread safe
static std::mutex m_mtx;
......
......@@ -365,6 +365,7 @@ if (NGRAPH_CPU_ENABLE)
# The INTERPRETER backend is required for convolution, and backwards unit tests
target_link_libraries(unit-test PRIVATE cpu_backend interpreter_backend)
target_link_libraries(unit-test PRIVATE libmkldnn)
target_compile_definitions(unit-test PRIVATE NGRAPH_CPU_ENABLE)
endif()
if (NGRAPH_TOOLS_ENABLE)
......
......@@ -91,3 +91,14 @@ TEST(backend_api, save_load)
}
}
#endif
#if defined(NGRAPH_INTERPRETER_ENABLE) && defined(NGRAPH_CPU_ENABLE)
TEST(backend_api, executable_can_create_tensor)
{
auto interpreter = runtime::Backend::create("INTERPRETER");
auto cpu = runtime::Backend::create("CPU");
EXPECT_TRUE(interpreter->executable_can_create_tensors());
EXPECT_FALSE(cpu->executable_can_create_tensors());
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment