Fix to check operands in detail (#2374)
author남궁석/동작제어Lab(SR)/Engineer/삼성전자 <sk.namkoong@samsung.com>
Tue, 28 Aug 2018 06:41:03 +0000 (15:41 +0900)
committer이춘석/동작제어Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>
Tue, 28 Aug 2018 06:41:03 +0000 (15:41 +0900)
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 <sk.namkoong@samsung.com>
runtimes/pure_arm_compute/src/model.cc

index d0c0b43..0346525 100644 (file)
@@ -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 ||