success = castToOperand(reinterpret_cast<const int32_t *>(input.buffer), output.type,
output.buffer, numberOfElements);
break;
- // TODO-NNRT implement other operands. (ex: TENSOR_QUANT8_ASYMM)
+ case OperandType::TENSOR_QUANT8_ASYMM:
+ success =
+ castQuant8ToOperand(reinterpret_cast<const uint8_t *>(input.buffer), input.scale,
+ input.zeroPoint, output.type, output.buffer, numberOfElements);
+ break;
default:
// Unsupported type.
LOG(ERROR) << getOperandTypeName(input.type) << " is unsupported type.";
return true;
}
+bool castQuant8ToOperand(const uint8_t *inputData, float scale, int32_t zeroPoint,
+ const OperandType outType, uint8_t *outputData, int numElements)
+{
+ switch (outType)
+ {
+ case OperandType::FLOAT32:
+ copyQuant8Cast(inputData, inputData + 1, scale, zeroPoint,
+ reinterpret_cast<float *>(outputData));
+ break;
+ case OperandType::INT32:
+ copyQuant8Cast(inputData, inputData + 1, scale, zeroPoint,
+ reinterpret_cast<int32_t *>(outputData));
+ break;
+ case OperandType::UINT32:
+ copyQuant8Cast(inputData, inputData + 1, scale, zeroPoint,
+ reinterpret_cast<uint32_t *>(outputData));
+ break;
+ case OperandType::TENSOR_FLOAT32:
+ copyQuant8Cast(inputData, inputData + numElements, scale, zeroPoint,
+ reinterpret_cast<float *>(outputData));
+ break;
+ case OperandType::TENSOR_INT32:
+ copyQuant8Cast(inputData, inputData + numElements, scale, zeroPoint,
+ reinterpret_cast<int32_t *>(outputData));
+ break;
+ // TODO-NNRT implement other operands. (ex: TENSOR_QUANT8_ASYMM)
+ default:
+ // Unsupported type.
+ LOG(ERROR) << getOperandTypeName(outType) << "is unsupported type.";
+ return false;
+ }
+ return true;
+}
+
} // namespace rt
} // namespace nnfw
return true;
}
+// Cast operation from TENSOR_QUANT8_ASYMM to outType
+bool castQuant8ToOperand(const uint8_t *inputData, float scale, int32_t zeroPoint,
+ const OperandType outType, uint8_t *outputData, int numElements);
+
// TODO: add more documentation from upstream.
// Reverse order of bits in the mask to match the expected order in kernel
inline int ReverseMaskBits(int mask, int num_dimensions)
std::transform(inFirst, inLast, out, [](FromT a) { return static_cast<ToT>(a); });
}
+template <typename ToT>
+void copyQuant8Cast(const uint8_t *inFirst, const uint8_t *inLast, float scale, int32_t zeroPoint,
+ ToT *out)
+{
+ std::transform(inFirst, inLast, out, [scale, zeroPoint](uint8_t a) {
+ return static_cast<ToT>((float)(a - zeroPoint) * scale);
+ });
+}
+
} // namespace rt
} // namespace nnfw