Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Initial implementation of backend config (#3110) (#3228)
Browse files Browse the repository at this point in the history
* initial implementation of backend config

* check on backend that does not support config
  • Loading branch information
libinta authored and diyessi committed Jul 15, 2019
1 parent 40b39a1 commit e714efc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ngraph/runtime/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions src/ngraph/runtime/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,13 @@ class ngraph::runtime::Backend
// \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);
};
13 changes: 13 additions & 0 deletions src/ngraph/runtime/interpreter/int_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/ngraph/runtime/interpreter/int_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class ngraph::runtime::interpreter::INTBackend : public Backend

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;
};
22 changes: 22 additions & 0 deletions test/backend_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit e714efc

Please sign in to comment.