Fix Comments (#16513)

### Description
Address comments in #14040 


### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->

---------

Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
This commit is contained in:
JiCheng 2023-06-30 08:37:57 +08:00 committed by GitHub
parent 05c4566fe9
commit 0051497055
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -183,22 +183,24 @@ NnapiExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph_view
result = utils::CreateSupportedPartitions(graph_viewer, is_node_supported, on_group_closed,
gen_metadef_name, NNAPI, kNnapiExecutionProvider);
// Generally, NNAPI support graph with inputs and outputs except constant initializer.
// So far, we have a few cases that sub-graph has zero inputs,
// Generally, NNAPI supports sub-graphs with at least one non-constant initializer input and one output.
// So far, we have a few cases that sub-graph has zero valid inputs, like `CastLike`
// a) A sub-graph has only initializer as inputs
// b) A sub-graph has zero inputs
// b) A sub-graph has zero inputs, like a `Constant` node
// So we just remove these sub-graph which is captured by NNAPI.
// A existing example is CastLike, as which can't be fold in constant folding pass.
// CastLike Op will be inlined into Cast after Pass transform.
// Can we remove it if support CastLike in CF or support Pass transform after InlineNodes?
// CastLike Op will be inlined into Cast after constant folding optimizer.
// Can we remove it if support CastLike in constant folding
// or support doing constant folding optimizer after InlineNodes?
std::for_each(result.begin(), result.end(), [&graph_viewer](auto& capability) {
if (capability && capability->sub_graph && capability->sub_graph->GetMetaDef()) {
const auto* meta_def = capability->sub_graph->GetMetaDef();
bool not_empty_inputs = std::any_of(meta_def->inputs.begin(), meta_def->inputs.end(), [&graph_viewer](const auto& input) {
bool has_any_non_constant_inputs = std::any_of(meta_def->inputs.begin(), meta_def->inputs.end(), [&graph_viewer](const auto& input) {
return !graph_viewer.IsConstantInitializer(input, true);
});
if (!not_empty_inputs || meta_def->outputs.empty()) {
// ALL inputs are constant
if (!has_any_non_constant_inputs) {
capability.reset();
}
}