1 /* Copyright 2019 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 #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_SSE_TENSOR_UTILS_IMPL_H_ 16 #define TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_SSE_TENSOR_UTILS_IMPL_H_ 17 18 #include <cstdint> 19 20 #include "tensorflow/lite/kernels/cpu_backend_context.h" 21 22 #if defined(_MSC_VER) 23 #define __restrict__ __restrict 24 #endif 25 26 namespace tflite { 27 namespace tensor_utils { 28 29 #if defined(__AVX2__) 30 // Matrix multiplication for float values. 31 void Avx2MatrixBatchVectorMultiplyAccumulateImpl( 32 const float* __restrict__ matrix, int m_rows, int m_cols, 33 const float* __restrict__ vector, int n_batch, float* __restrict__ result); 34 35 // Matrix multiplication for quantized values using asymmetric quantization. 36 void Avx2MatrixBatchVectorMultiplyAccumulateImpl( 37 const int8_t* __restrict__ matrix, const int m_rows, const int m_cols, 38 const int8_t* __restrict__ vectors, 39 const float* __restrict__ scaling_factors, int n_batch, 40 float* __restrict__ result, const float* per_channel_scale, 41 const int32_t* input_offset, int32_t* scratch, int32_t* row_sums, 42 bool* compute_row_sums, CpuBackendContext* context); 43 #endif // defined(__AVX2__) 44 45 #ifdef __SSSE3__ 46 47 // Matrix multiplication for quantized values using symmetric quantization. 48 void SseMatrixBatchVectorMultiplyAccumulate( 49 const int8_t* __restrict__ matrix, const int m_rows, const int m_cols, 50 const int8_t* __restrict__ vectors, 51 const float* __restrict__ scaling_factors, int n_batch, 52 float* __restrict__ result); 53 54 // Matrix multiplication for quantized values using symmetric quantization 55 // with additional scratch memory for GEMM operation prior to scaling. 56 void SseMatrixBatchVectorMultiplyAccumulate( 57 const int8_t* __restrict__ matrix, const int m_rows, const int m_cols, 58 const int8_t* __restrict__ vectors, 59 const float* __restrict__ scaling_factors, int n_batch, int32_t* scratch, 60 float* __restrict__ result, CpuBackendContext* context); 61 62 // Matrix multiplication for quantized values using asymmetric quantization. 63 void SseMatrixBatchVectorMultiplyAccumulate( 64 const int8_t* __restrict__ matrix, const int m_rows, const int m_cols, 65 const int8_t* __restrict__ vectors, 66 const float* __restrict__ scaling_factors, int n_batch, 67 float* __restrict__ result, const float* per_channel_scale, 68 const int32_t* input_offset, int32_t* scratch, int32_t* row_sums, 69 bool* compute_row_sums, CpuBackendContext* context); 70 71 // Matrix multiplication for quantized values using symmetric quantization. 72 // Sparse version. 73 void SseSparseMatrixBatchVectorMultiplyAccumulate( 74 const int8_t* __restrict__ matrix, const uint8_t* __restrict__ ledger, 75 const int m_rows, const int m_cols, const int8_t* __restrict__ vectors, 76 const float* __restrict__ scaling_factors, int n_batch, 77 float* __restrict__ result); 78 79 void SseReductionSumVector(const int8_t* input_vector, int32_t* output_vector, 80 const int output_size, const int reduction_size); 81 82 #endif // __SSSE3__ 83 84 } // namespace tensor_utils 85 } // namespace tflite 86 87 #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_SSE_TENSOR_UTILS_IMPL_H_ 88