From: 남궁석/동작제어Lab(SR)/Engineer/삼성전자 Date: Tue, 28 Aug 2018 06:41:03 +0000 (+0900) Subject: Fix to check operands in detail (#2374) X-Git-Tag: 0.2~159 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f5712e4f8a6624b630c8b79c8ac359e1bdb2154;p=platform%2Fcore%2Fml%2Fnnfw.git Fix to check operands in detail (#2374) Validation of scale and zeroPoint would be skipped for a while. We do not know whether scalar type can have scale and zeroPoint. To pass ValidationTest and GeneratedTest, this validation code would not be implemented until we can define this issue clearly. Except that, this commit will enable check operands in detail - Add checking scale and zeropoint in `quant8` type - Add checking dimensionCount for scalars Signed-off-by: Seok NamKoong --- diff --git a/runtimes/pure_arm_compute/src/model.cc b/runtimes/pure_arm_compute/src/model.cc index d0c0b43..0346525 100644 --- a/runtimes/pure_arm_compute/src/model.cc +++ b/runtimes/pure_arm_compute/src/model.cc @@ -40,6 +40,45 @@ int ANeuralNetworksModel_addOperand(ANeuralNetworksModel *model, { return ANEURALNETWORKS_BAD_STATE; } + + if (type->type == ANEURALNETWORKS_TENSOR_QUANT8_ASYMM) + { + // Quantized: + // scale: a 32 bit floating point value greater than zero + // zeroPoint: a 32 bit integer, in range [0, 255] + if (type->scale <= 0.0f) + { + return ANEURALNETWORKS_BAD_DATA; + } + + if (type->zeroPoint < 0 || type->zeroPoint > 255) + { + return ANEURALNETWORKS_BAD_DATA; + } + } + // NOTE Validation of scale and zeroPoint would be skipped for a while. + // We do not know whether scalar type can have scale and zeroPoint. + // To pass ValidationTest and GeneratedTest, this validation code + // would not be implemented until we can define this issue clearly. + // + // scale and zeroPoint should be zero for scalars and non-fixed point tensors + // else if ((type->scale != 0.0f) || (type->zeroPoint != 0)) + // { + // return ANEURALNETWORKS_BAD_DATA; + // } + + // scalar is ANEURALNETWORKS_FLOAT32, ANEURALNETWORKS_INT32 or ANEURALNETWORKS_UINT32. + // ANEURALNETWORKS_TENSOR_FLOAT32, ANEURALNETWORKS_TENSOR_INT32 and + // ANEURALNETWORKS_TENSOR_QUANT8_ASYMM are not scalar + // + // dimensionCount should be zero for scalars + if (type->dimensionCount != 0 && + (type->type == ANEURALNETWORKS_FLOAT32 || type->type == ANEURALNETWORKS_INT32 || + type->type == ANEURALNETWORKS_UINT32)) + { + return ANEURALNETWORKS_BAD_DATA; + } + // ASSUME A tensor operand should consists of fp32 or int32 values. // NOTE We do not care about scala operands. assert((type->dimensionCount == 0) || (type->type == ANEURALNETWORKS_TENSOR_FLOAT32 ||