Add NNAPI delegate support for Elu
PiperOrigin-RevId: 311772163 Change-Id: I94393872c9afa25aafc2fc55f688d47caa57ed14
This commit is contained in:
parent
1f530076d1
commit
9cb8d45b72
tensorflow/lite
@ -56,6 +56,7 @@ FloatActivationsOpTest/PRelu,29
|
||||
LogisticOpTest/LogisticOpTest/Sigmoid(.+nt8)?/\d+
|
||||
LogisticOpTest/LogisticOpTest/Sigmoid/\d+
|
||||
TanhOpTest/TanhOpTest/Tanh(.+nt8)?/\d+,29
|
||||
FloatActivationsOpTest/Elu,30
|
||||
FloatActivationsOpTest/HardSwish
|
||||
QuantizedActivationsOpTest/HardSwish
|
||||
QuantizedActivationsOpTest/HardSwishBias
|
||||
@ -301,14 +302,14 @@ VariedShapeSpec/ReshapeOpTest/WithStretchDimension/1
|
||||
|
||||
# resize_bilinear_test
|
||||
// align_corners & half_pixel_centers are not implemented in NNAPI before API 30
|
||||
ResizeBilinearOpTest/ResizeBilinearOpTest.+HalfPixelCenters.*,30
|
||||
ResizeBilinearOpTest/ResizeBilinearOpTest.+HalfPixelCenters.*/0,30
|
||||
// Only models with constant size tensor are accelerated
|
||||
ResizeBilinearOpTest/ResizeBilinearOpTest/.+/0,29
|
||||
|
||||
# resize_nearest_neighbor_test
|
||||
// align_corners & half_pixel_centers are not implemented in NNAPI before API 30
|
||||
ResizeNearestNeighborOpTest/ResizeNearestNeighborOpTest.+AlignCorners.*,30
|
||||
ResizeNearestNeighborOpTest/ResizeNearestNeighborOpTest.+HalfPixelCenters.*,30
|
||||
ResizeNearestNeighborOpTest/ResizeNearestNeighborOpTest.+AlignCorners.*/0,30
|
||||
ResizeNearestNeighborOpTest/ResizeNearestNeighborOpTest.+HalfPixelCenters.*/0,30
|
||||
// Only models with constant size tensor are accelerated
|
||||
ResizeNearestNeighborOpTest/ResizeNearestNeighborOpTest/.+/0,29
|
||||
|
||||
|
@ -18,6 +18,7 @@ limitations under the License.
|
||||
#include <cstdarg>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
@ -1623,7 +1624,7 @@ bool NNAPIDelegateKernel::Validate(
|
||||
}
|
||||
} break;
|
||||
case kTfLiteBuiltinResizeBilinear: {
|
||||
ExpectMaxOpVersion(version, 2, &val_ctx);
|
||||
ExpectMaxOpVersion(version, 3, &val_ctx);
|
||||
const auto& input = context->tensors[node->inputs->data[0]];
|
||||
const auto output_dims = context->tensors[node->outputs->data[0]].dims;
|
||||
Expect(input.dims->size == 4,
|
||||
@ -1663,7 +1664,7 @@ bool NNAPIDelegateKernel::Validate(
|
||||
}
|
||||
} break;
|
||||
case kTfLiteBuiltinResizeNearestNeighbor: {
|
||||
ExpectMaxOpVersion(version, 2, &val_ctx);
|
||||
ExpectMaxOpVersion(version, 3, &val_ctx);
|
||||
ExpectMinAndroidSdkVersion(android_sdk_version, kMinSdkVersionForNNAPI12,
|
||||
&val_ctx);
|
||||
ExpectIsFloatOrQuant8Operator(context, node, &val_ctx);
|
||||
@ -2334,6 +2335,11 @@ bool NNAPIDelegateKernel::Validate(
|
||||
NNAPIValidationFailureType::kUnsupportedInputType,
|
||||
"NNAPI only supports floating point input.", &val_ctx);
|
||||
} break;
|
||||
case kTfLiteBuiltinElu: {
|
||||
ExpectOpVersion(version, 1, &val_ctx);
|
||||
ExpectMinAndroidSdkVersion(android_sdk_version, kMinSdkVersionForNNAPI13,
|
||||
&val_ctx);
|
||||
} break;
|
||||
default:
|
||||
// All other operators are not mapped.
|
||||
AddValidationFailure(NNAPIValidationFailureType::kUnsupportedOperator,
|
||||
@ -3111,6 +3117,10 @@ TfLiteStatus NNAPIDelegateKernel::Map(
|
||||
mapping_args.builder->AddScalarBoolOperand(builtin->keep_dims);
|
||||
*nn_op_type = ANEURALNETWORKS_REDUCE_SUM;
|
||||
} break;
|
||||
case kTfLiteBuiltinElu: {
|
||||
mapping_args.builder->AddScalarFloat32Operand(1.0);
|
||||
*nn_op_type = ANEURALNETWORKS_ELU;
|
||||
} break;
|
||||
default:
|
||||
// All other operators are not mapped.
|
||||
return kTfLiteError;
|
||||
|
@ -31,6 +31,7 @@ namespace nnapi {
|
||||
constexpr int32_t kMinSdkVersionForNNAPI = 27;
|
||||
constexpr int32_t kMinSdkVersionForNNAPI11 = 28;
|
||||
constexpr int32_t kMinSdkVersionForNNAPI12 = 29;
|
||||
constexpr int32_t kMinSdkVersionForNNAPI13 = 30;
|
||||
|
||||
// Track tensor indices to NN API tensor indices mapping.
|
||||
class OperandMapping {
|
||||
|
@ -2050,7 +2050,7 @@ TEST_P(CifgPeepholeProjectionNoClippingLayerNormLstmTest,
|
||||
}};
|
||||
|
||||
VerifyGoldens(lstm_input_, lstm_golden_output_, &layer_norm_lstm,
|
||||
/*tolerance=*/0.000902065);
|
||||
/*tolerance=*/0.0009021);
|
||||
}
|
||||
|
||||
class CifgPeepholeProjectionNoClippingLayerNormLstmInt8Test
|
||||
|
@ -136,6 +136,13 @@ enum {
|
||||
ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_LSTM = 92,
|
||||
ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_RNN = 93,
|
||||
ANEURALNETWORKS_RESIZE_NEAREST_NEIGHBOR = 94,
|
||||
ANEURALNETWORKS_QUANTIZED_LSTM = 95,
|
||||
ANEURALNETWORKS_IF = 96,
|
||||
ANEURALNETWORKS_WHILE = 97,
|
||||
ANEURALNETWORKS_ELU = 98,
|
||||
ANEURALNETWORKS_HARD_SWISH = 99,
|
||||
ANEURALNETWORKS_FILL = 100,
|
||||
ANEURALNETWORKS_RANK = 101,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -45,19 +45,6 @@ int32_t GetAndroidSdkVersion() {
|
||||
}
|
||||
result = result * 10 + digit;
|
||||
}
|
||||
// TODO(levp): remove once SDK gets updated to 29th level
|
||||
// Upgrade SDK version for pre-release Q to be able to test functionality
|
||||
// available from SDK level 29.
|
||||
if (result == 28) {
|
||||
char versionCodename[PROP_VALUE_MAX];
|
||||
const char* versionCodenameProp = "ro.build.version.codename";
|
||||
length = __system_property_get(versionCodenameProp, versionCodename);
|
||||
if (length != 0) {
|
||||
if (versionCodename[0] == 'Q') {
|
||||
return 29;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user