Commit e714efcf authored by libinta's avatar libinta Committed by Scott Cyphers

Initial implementation of backend config (#3110) (#3228)

* initial implementation of backend config

* check on backend that does not support config
parent 40b39a1b
......@@ -90,3 +90,9 @@ std::shared_ptr<runtime::Executable> runtime::Backend::load(istream& input_strea
{
throw runtime_error("load opertion unimplemented.");
}
bool runtime::Backend::set_config(const map<string, string>& config, string& error)
{
error = "set_config not supported";
return false;
}
......@@ -139,4 +139,13 @@ public:
// \param op_name is the name of the backend specific op
// \returns a shared pointer to the op if found, else nullptr
virtual std::shared_ptr<ngraph::Node> get_backend_op(const std::string& op_name, ...);
/// \brief Allows sending backend specific configuration. The map contains key, value pairs
/// specific to a particluar backend. The definition of these key, value pairs is
/// defined by each backend.
/// \param config The configuration map sent to the backend
/// \param error An error string describing any error encountered
/// \returns true if the configuration is supported, false otherwise. On false the error
/// parameter value is valid.
virtual bool set_config(const std::map<std::string, std::string>& config, std::string& error);
};
......@@ -105,3 +105,16 @@ std::shared_ptr<runtime::Executable> runtime::interpreter::INTBackend::load(istr
}
return exec;
}
bool runtime::interpreter::INTBackend::set_config(const map<string, string>& config, string& error)
{
bool rc = false;
auto it = config.find("test_echo");
error = "";
if (it != config.end())
{
error = it->second;
rc = true;
}
return rc;
}
......@@ -58,6 +58,8 @@ public:
bool is_supported(const Node& node) const override;
bool set_config(const std::map<std::string, std::string>& config, std::string& error) override;
private:
std::set<std::string> m_unsupported_op_name_list;
};
......@@ -37,6 +37,28 @@ TEST(backend_api, invalid_name)
ASSERT_ANY_THROW(ngraph::runtime::Backend::create("COMPLETELY-BOGUS-NAME"));
}
TEST(backend_api, config)
{
auto backend = runtime::Backend::create("INTERPRETER");
string error;
string message = "hello";
map<string, string> config = {{"test_echo", message}};
EXPECT_TRUE(backend->set_config(config, error));
EXPECT_STREQ(error.c_str(), message.c_str());
EXPECT_FALSE(backend->set_config({}, error));
EXPECT_STREQ(error.c_str(), "");
}
TEST(backend_api, config_unsupported)
{
auto backend = runtime::Backend::create("NOP");
string error;
string message = "hello";
map<string, string> config = {{"test_echo", message}};
EXPECT_FALSE(backend->set_config(config, error));
EXPECT_FALSE(error == "");
}
TEST(backend_api, save_load)
{
Shape shape{2, 2};
......
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