1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_DELEGATES_XNNPACK_QUANTIZATION_UTIL_H_ 17 #define TENSORFLOW_LITE_DELEGATES_XNNPACK_QUANTIZATION_UTIL_H_ 18 19 #include <cstddef> 20 #include <cstdint> 21 22 #include "tensorflow/lite/kernels/internal/types.h" 23 24 namespace tflite { 25 namespace xnnpack { 26 27 // Dequantizes INT8 value using given zero point and scale. 28 // packed_s8_data should contain raw tensor data corresponding to 29 // a given tensor_shape. unpacked_fp32_data should be preallocated 30 // to have the same size. 31 void DequantizeInt8(const int8_t* packed_s8_data, float* unpacked_fp32_data, 32 const RuntimeShape& tensor_shape, int32_t zero_point, 33 double scale); 34 35 // Per-channel dequantizes INT8 value using given zero points and 36 // scales. packed_s8_data should contain raw tensor data corresponding 37 // to a given tensor_shape. unpacked_fp32_data should be preallocated 38 // to have the same size. 39 void PerChannelDequantizeInt8(const int8_t* packed_s8_data, 40 float* unpacked_fp32_data, 41 const RuntimeShape& tensor_shape, 42 const int32_t* zero_points, const float* scales, 43 int32_t quantized_dimension); 44 45 // Dequantizes INT8 value using given zero point and scale. 46 // packed_fp16_data should have tensor_elements size and contain raw 47 // FP16 tensor data. unpacked_fp32_data should be preallocated to 48 // have the same size. 49 void DequantizeFloat16(const uint16_t* packed_fp16_data, 50 float* unpacked_fp32_data, size_t tensor_elements); 51 52 } // namespace xnnpack 53 } // namespace tflite 54 55 #endif // TENSORFLOW_LITE_DELEGATES_XNNPACK_QUANTIZATION_UTIL_H_ 56