Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'get_num_inputs' to GraphRuntime #6118

Merged
merged 2 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/tvm/contrib/graph_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def __init__(self, module):
self._get_output = module["get_output"]
self._get_input = module["get_input"]
self._get_num_outputs = module["get_num_outputs"]
self._get_num_inputs = module["get_num_inputs"]
self._load_params = module["load_params"]
self._share_params = module["share_params"]

Expand Down Expand Up @@ -187,6 +188,16 @@ def get_num_outputs(self):
"""
return self._get_num_outputs()

def get_num_inputs(self):
"""Get the number of inputs to the graph

Returns
-------
count : int
The number of inputs.
"""
return self._get_num_inputs()

def get_input(self, index, out=None):
"""Get index-th input to out

Expand Down
9 changes: 9 additions & 0 deletions src/runtime/graph/graph_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ void GraphRuntime::SetInputZeroCopy(int index, DLTensor* data_ref) {
* \return The number of outputs from graph.
*/
int GraphRuntime::NumOutputs() const { return outputs_.size(); }
/*!
* \brief Get the number of inputs
*
* \return The number of inputs to the graph.
*/
int GraphRuntime::NumInputs() const { return input_nodes_.size(); }
/*!
* \brief Return NDArray for given input index.
* \param index The input index.
Expand Down Expand Up @@ -433,6 +439,9 @@ PackedFunc GraphRuntime::GetFunction(const std::string& name,
} else if (name == "get_num_outputs") {
return PackedFunc(
[sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = this->NumOutputs(); });
} else if (name == "get_num_inputs") {
return PackedFunc(
[sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { *rv = this->NumInputs(); });
} else if (name == "run") {
return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { this->Run(); });
} else if (name == "load_params") {
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/graph/graph_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ class TVM_DLL GraphRuntime : public ModuleNode {
* \return The number of outputs from graph.
*/
int NumOutputs() const;
/*!
* \brief Get the number of inputs
*
* \return The number of inputs to the graph.
*/
int NumInputs() const;
/*!
* \brief Return NDArray for given input index.
* \param index The input index.
Expand Down