Skip to content

[Caffe2] Android NNApi integration bugs. #6868

@shashishekhar

Description

@shashishekhar

Issue description

I found a few bugs in NNApi integration while running benchmarks.

Code example

Bug 1: Invalid size is passed for tensors.
Caffe2 seems to be passing invalid size for tensors in setInput and setOutput.
If I am not wrong, they should be passing tensor->nbytes() instead of tensor->bytes()
https://github.com/caffe2/caffe2/blob/master/caffe2/mobile/contrib/nnapi/nnapi.cc#L659
In ANeuralNetworksExecution_setInput the length parameter is number of bytes, not number of elements in the tensor.
https://developer.android.com/ndk/reference/group___neural_networks.html#gaf5540f8785a31b550ba7e7a78eed6a85

Bug 2: The scale is only supported for Quantized int8 tensors and should be 0 otherwise.
https://github.com/caffe2/caffe2/blob/master/caffe2/mobile/contrib/nnapi/nnapi.cc#L517
NNApi::addTensorOperand should assign scale conditionally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions