From 53c79d179af81c06a5bc4b7025b9696ecef5701b Mon Sep 17 00:00:00 2001 From: Lev Proleev Date: Tue, 19 Nov 2019 17:37:06 +0000 Subject: [PATCH 1/3] Add TENSOR_QUANT8_ASYMM_SIGNED support to ADD, MUL and SUB. Bug: 143934463 Bug: 143934627 Bug: 143935040 Test: NNTest_static and 1.3 VTS Change-Id: I47ffc2c264390f3c6b98aa9567fb47f2c58333fe Merged-In: I47ffc2c264390f3c6b98aa9567fb47f2c58333fe (cherry picked from commit 122bc2c0cc36f46b9d82bafde69b3881faaa71c0) --- current.txt | 2 +- neuralnetworks/1.3/types.hal | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/current.txt b/current.txt index b6ef9dcc8b..b0357ee561 100644 --- a/current.txt +++ b/current.txt @@ -597,7 +597,7 @@ adb0efdf1462e9b2e742c0dcadd598666aac551f178be06e755bfcdf5797abd0 android.hardwar 9e59fffceed0dd72a9799e04505db5f777bbbea1af0695ba4107ef6d967c6fda android.hardware.neuralnetworks@1.3::IDevice 4a6c3b3556da951b4def21ba579a227c022980fe4465df6cdfbe20628fa75f5a android.hardware.neuralnetworks@1.3::IPreparedModel 94e803236398bed1febb11cc21051bc42ec003700139b099d6c479e02a7ca3c3 android.hardware.neuralnetworks@1.3::IPreparedModelCallback -554baa3b317e077b850afcbaac99daeef56861b1786540e56275a4fcad1f43e3 android.hardware.neuralnetworks@1.3::types +103cb87c5ed46851badac097f8d190da60f39b5ab32d60e2e93f64d3014ea75c android.hardware.neuralnetworks@1.3::types 274fb1254a6d1a97824ec5c880eeefc0e410dc6d3a2a4c34052201169d2b7de0 android.hardware.radio@1.5::types c8e81d912827a5d49b2ddcdc4eb4556c5d231a899a1dca879309e04210daa4a0 android.hardware.radio@1.5::IRadio a62a93faf173b14a6175b683ebf61ffa568dc61f81e369d2dce7b1265e86cf2f android.hardware.radio@1.5::IRadioIndication diff --git a/neuralnetworks/1.3/types.hal b/neuralnetworks/1.3/types.hal index f959e45b5a..db86bf6ea1 100644 --- a/neuralnetworks/1.3/types.hal +++ b/neuralnetworks/1.3/types.hal @@ -109,6 +109,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4 * @@ -116,7 +117,8 @@ enum OperationType : int32_t { * * 0: A tensor. * * 1: A tensor of the same {@link OperandType}, and compatible dimensions * as input0. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor, * the scales and zeroPoint can be different from input0 scale and zeroPoint. * * 2: An {@link OperandType::INT32} scalar, and has to be one of the * {@link FusedActivationFunc} values. Specifies the activation to @@ -124,7 +126,8 @@ enum OperationType : int32_t { * * Outputs: * * 0: The sum, a tensor of the same {@link OperandType} as input0. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, * the scale and zeroPoint can be different from inputs' scale and zeroPoint. */ ADD = @1.2::OperationType:ADD, @@ -1345,6 +1348,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4 * @@ -1358,7 +1362,8 @@ enum OperationType : int32_t { * * Outputs: * * 0: The product, a tensor of the same {@link OperandType} as input0. - * For output tensor of {@link OperandType::TENSOR_QUANT8_ASYMM}, + * For output tensor of {@link OperandType::TENSOR_QUANT8_ASYMM} + * and {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED}, * the following condition must be satisfied: * output_scale > input1_scale * input2_scale. */ @@ -2083,6 +2088,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} (since HAL version 1.2) + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4 * @@ -2096,7 +2102,8 @@ enum OperationType : int32_t { * * Outputs: * * 0: A tensor of the same {@link OperandType} as input0. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor, * the scale and zeroPoint can be different from inputs' scale and zeroPoint. */ SUB = @1.2::OperationType:SUB, From d1b3450b3d317cb687f87b6dd954f288adfdaf82 Mon Sep 17 00:00:00 2001 From: Lev Proleev Date: Wed, 20 Nov 2019 13:55:16 +0000 Subject: [PATCH 2/3] Add TENSOR_QUANT8_ASYMM_SIGNED support for pooling ops * Update AVERAGE_POOL_2D and MAX_POOL_2D Bug: 143934716 Bug: 143934303 Test: quantization coupling tests in CTS and VTS Change-Id: I15f36d6f819c92f96a46c40f9cc1491627644278 Merged-In: I15f36d6f819c92f96a46c40f9cc1491627644278 (cherry picked from commit 3f17cc3daa2a81127f736e13346d95e35c710e65) --- current.txt | 2 +- neuralnetworks/1.3/types.hal | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/current.txt b/current.txt index b0357ee561..122316b1cf 100644 --- a/current.txt +++ b/current.txt @@ -597,7 +597,7 @@ adb0efdf1462e9b2e742c0dcadd598666aac551f178be06e755bfcdf5797abd0 android.hardwar 9e59fffceed0dd72a9799e04505db5f777bbbea1af0695ba4107ef6d967c6fda android.hardware.neuralnetworks@1.3::IDevice 4a6c3b3556da951b4def21ba579a227c022980fe4465df6cdfbe20628fa75f5a android.hardware.neuralnetworks@1.3::IPreparedModel 94e803236398bed1febb11cc21051bc42ec003700139b099d6c479e02a7ca3c3 android.hardware.neuralnetworks@1.3::IPreparedModelCallback -103cb87c5ed46851badac097f8d190da60f39b5ab32d60e2e93f64d3014ea75c android.hardware.neuralnetworks@1.3::types +6256b2b1df586fc01e80ecf001770d941385602682ec2055ba7b3979a02c8ebf android.hardware.neuralnetworks@1.3::types 274fb1254a6d1a97824ec5c880eeefc0e410dc6d3a2a4c34052201169d2b7de0 android.hardware.radio@1.5::types c8e81d912827a5d49b2ddcdc4eb4556c5d231a899a1dca879309e04210daa4a0 android.hardware.radio@1.5::IRadio a62a93faf173b14a6175b683ebf61ffa568dc61f81e369d2dce7b1265e86cf2f android.hardware.radio@1.5::IRadioIndication diff --git a/neuralnetworks/1.3/types.hal b/neuralnetworks/1.3/types.hal index db86bf6ea1..3641355221 100644 --- a/neuralnetworks/1.3/types.hal +++ b/neuralnetworks/1.3/types.hal @@ -149,6 +149,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: 4, with "NHWC" or "NCHW" data layout. * With the default data layout NHWC, the data is stored in the order of: @@ -210,7 +211,8 @@ enum OperationType : int32_t { * Outputs: * * 0: The output 4-D tensor, of shape * [batches, out_height, out_width, depth]. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor, * the scale and zeroPoint must be the same as input0. */ AVERAGE_POOL_2D = @1.2::OperationType:AVERAGE_POOL_2D, @@ -1259,6 +1261,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: 4, with "NHWC" or "NCHW" data layout. * With the default data layout NHWC, the data is stored in the order of: @@ -1320,7 +1323,8 @@ enum OperationType : int32_t { * Outputs: * * 0: The output 4-D tensor, of shape * [batches, out_height, out_width, depth]. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor, * the scale and zeroPoint must be the same as input0. */ MAX_POOL_2D = @1.2::OperationType:MAX_POOL_2D, From cdb67453de1f54e38b6d321a4fc2e658d4734dd7 Mon Sep 17 00:00:00 2001 From: Lev Proleev Date: Thu, 21 Nov 2019 17:35:30 +0000 Subject: [PATCH 3/3] Add TENSOR_QUANT8_ASYMM_SIGNED support for activations Ops updated: RELU, RELU1, RELU6, TANH, LOGISTIC Fix: 143933951 Fix: 143934720 Fix: 143933831 Fix: 143934770 Fix: 143934743 Test: quantization coupling tests in CTS and VTS Change-Id: Id5e7a8c6b30463708bd93dbf6a3f30d05c2bcf40 Merged-In: Id5e7a8c6b30463708bd93dbf6a3f30d05c2bcf40 (cherry picked from commit 3466c78b04ee9cbbd8622157ef1357f1dfb5bb6a) --- current.txt | 2 +- neuralnetworks/1.3/types.hal | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/current.txt b/current.txt index 122316b1cf..ef574347f3 100644 --- a/current.txt +++ b/current.txt @@ -597,7 +597,7 @@ adb0efdf1462e9b2e742c0dcadd598666aac551f178be06e755bfcdf5797abd0 android.hardwar 9e59fffceed0dd72a9799e04505db5f777bbbea1af0695ba4107ef6d967c6fda android.hardware.neuralnetworks@1.3::IDevice 4a6c3b3556da951b4def21ba579a227c022980fe4465df6cdfbe20628fa75f5a android.hardware.neuralnetworks@1.3::IPreparedModel 94e803236398bed1febb11cc21051bc42ec003700139b099d6c479e02a7ca3c3 android.hardware.neuralnetworks@1.3::IPreparedModelCallback -6256b2b1df586fc01e80ecf001770d941385602682ec2055ba7b3979a02c8ebf android.hardware.neuralnetworks@1.3::types +2d16429145dc1158bf3e45c7de86a39e461dec3ec00512c11a7e5249535a2e96 android.hardware.neuralnetworks@1.3::types 274fb1254a6d1a97824ec5c880eeefc0e410dc6d3a2a4c34052201169d2b7de0 android.hardware.radio@1.5::types c8e81d912827a5d49b2ddcdc4eb4556c5d231a899a1dca879309e04210daa4a0 android.hardware.radio@1.5::IRadio a62a93faf173b14a6175b683ebf61ffa568dc61f81e369d2dce7b1265e86cf2f android.hardware.radio@1.5::IRadioIndication diff --git a/neuralnetworks/1.3/types.hal b/neuralnetworks/1.3/types.hal index 3641355221..3551d5762a 100644 --- a/neuralnetworks/1.3/types.hal +++ b/neuralnetworks/1.3/types.hal @@ -956,6 +956,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4. * @@ -967,6 +968,8 @@ enum OperationType : int32_t { * * 0: The output tensor of same shape as input0. * For {@link OperandType::TENSOR_QUANT8_ASYMM}, * the scale must be 1.f / 256 and the zeroPoint must be 0. + * For {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED}, + * the scale must be 1.f / 256 and the zeroPoint must be -128. */ LOGISTIC = @1.2::OperationType:LOGISTIC, @@ -1384,6 +1387,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4. * @@ -1393,7 +1397,8 @@ enum OperationType : int32_t { * * Outputs: * * 0: The output tensor of same shape as input0. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor, * the scale and zeroPoint must be the same as input0. */ RELU = @1.2::OperationType:RELU, @@ -1409,6 +1414,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4. * @@ -1418,7 +1424,8 @@ enum OperationType : int32_t { * * Outputs: * * 0: The output tensor of the same shape as input0. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor, * the scale and zeroPoint must be the same as input0. */ RELU1 = @1.2::OperationType:RELU1, @@ -1434,6 +1441,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4. * @@ -1443,7 +1451,8 @@ enum OperationType : int32_t { * * Outputs: * * 0: The output tensor of same shape as input0. - * For a {@link OperandType::TENSOR_QUANT8_ASYMM} tensor, + * For a {@link OperandType::TENSOR_QUANT8_ASYMM} and + * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor, * the scale and zeroPoint must be the same as input0. */ RELU6 = @1.2::OperationType:RELU6, @@ -1764,6 +1773,7 @@ enum OperationType : int32_t { * * {@link OperandType::TENSOR_FLOAT16} (since HAL version 1.2) * * {@link OperandType::TENSOR_FLOAT32} * * {@link OperandType::TENSOR_QUANT8_ASYMM} (since HAL version 1.2) + * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since HAL version 1.3) * * Supported tensor rank: up to 4. * @@ -1775,6 +1785,8 @@ enum OperationType : int32_t { * * 0: The output tensor of same shape as input0. * For {@link OperandType::TENSOR_QUANT8_ASYMM}, * the scale must be 1.f / 128 and the zeroPoint must be 128. + * For {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED}, + * the scale must be 1.f / 128 and the zeroPoint must be 0. */ TANH = @1.2::OperationType:TANH,