1 /* Copyright 2020 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_GPU_COMMON_QUANTIZATION_UTIL_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_QUANTIZATION_UTIL_H_ 18 19 #include <stdint.h> 20 21 #include <vector> 22 23 #include "absl/container/flat_hash_map.h" 24 #include "tensorflow/lite/c/common.h" 25 #include "tensorflow/lite/delegates/gpu/common/status.h" 26 27 namespace tflite { 28 namespace gpu { 29 30 // Dequantizes input tensors pre-inference, leaving float tensors intact. 31 // input_indices contains dequantized (fp32) outputs, that are used as 32 // inputs to GPU delegate. 33 // quant_conversion_map contains bidirectional mapping between dequantized 34 // tensor and its original quantized one. 35 absl::Status DequantizeInputs( 36 TfLiteContext* context, const std::vector<uint32_t>& input_indices, 37 const absl::flat_hash_map<int, int>& quant_conversion_map); 38 39 absl::Status DequantizeInputs( 40 TfLiteContext* context, const std::vector<int64_t>& input_indices, 41 const absl::flat_hash_map<int, int>& quant_conversion_map); 42 43 // Quantizes output tensors post-inference, leaving float tensors intact. 44 // output_indices contains (fp32) inputs to be quantized, which are outputs of 45 // GPU delegate. 46 // quant_conversion_map contains bidirectional mapping between dequantized 47 // tensor and its original quantized one. 48 absl::Status QuantizeOutputs( 49 TfLiteContext* context, const std::vector<uint32_t>& output_indices, 50 const absl::flat_hash_map<int, int>& quant_conversion_map); 51 52 absl::Status QuantizeOutputs( 53 TfLiteContext* context, const std::vector<int64_t>& output_indices, 54 const absl::flat_hash_map<int, int>& quant_conversion_map); 55 } // namespace gpu 56 } // namespace tflite 57 58 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_QUANTIZATION_UTIL_H_ 59