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

Reject softmax if dim > 65535 which not supported #75

Open
wants to merge 1 commit into
base: vsi_nnapi_delegate_v2.4.0
Choose a base branch
from

Conversation

sunshinemyson
Copy link

Signed-off-by: xiang.zhang xiang.zhang@verisilicon.com

Signed-off-by: xiang.zhang <xiang.zhang@verisilicon.com>
@xiaofengren
Copy link

xiaofengren commented Oct 15, 2021

Hello Xiang
We tried this patch on our side and it report build failure, like as followings:

nnapi_delegate.cc:1870:23: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
| 1870 | for(auto d : input.dims) {

So we made below changes for your patch and verified it, the issue was fixed. Here is our patch:
diff --git a/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc b/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc
index e1de9e9d289..5a02db7279a 100644
--- a/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc
+++ b/tensorflow/lite/delegates/nnapi/nnapi_delegate.cc
@@ -2075,8 +2075,12 @@ bool NNAPIDelegateKernel::Validate(
"Output type should be one of kTfLiteFloat32, kTfLiteUInt8, "
"kTfLiteInt8.",
&val_ctx);
- const auto& input = context->tensors[node->inputs->data[0]];
- const int input_rank = input.dims->size;
+ auto input_dims = context->tensors[node->inputs->data[0]].dims;
+ if (input_dims->data[1] > 65536 || input_dims->data[2] > 65536) {
+ Expect(input_dims->data[1] < 65535, NNAPIValidationFailureType::kUnsupportedOperandSize, "Input dimension larger than 65535", &val_ctx);
+ Expect(input_dims->data[2] < 65535, NNAPIValidationFailureType::kUnsupportedOperandSize, "Input dimension larger than 65535", &val_ctx);
+ }
+ const int input_rank = input_dims->size;
Expect(input_rank <= 4,
NNAPIValidationFailureType::kUnsupportedOperandRank,
"Input rank should be <= 4", &val_ctx);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants