• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef __SSSE3__
30 
31 // Matrix multiplication for quantized values using symmetric quantization.
32 void SseMatrixBatchVectorMultiplyAccumulate(
33     const int8_t* __restrict__ matrix, const int m_rows, const int m_cols,
34     const int8_t* __restrict__ vectors,
35     const float* __restrict__ scaling_factors, int n_batch,
36     float* __restrict__ result);
37 
38 // Matrix multiplication for quantized values using symmetric quantization
39 // with additional scratch memory for GEMM operation prior to scaling.
40 void SseMatrixBatchVectorMultiplyAccumulate(
41     const int8_t* __restrict__ matrix, const int m_rows, const int m_cols,
42     const int8_t* __restrict__ vectors,
43     const float* __restrict__ scaling_factors, int n_batch, int32_t* scratch,
44     float* __restrict__ result, CpuBackendContext* context);
45 
46 // Matrix multiplication for quantized values using asymmetric quantization.
47 void SseMatrixBatchVectorMultiplyAccumulate(
48     const int8_t* __restrict__ matrix, const int m_rows, const int m_cols,
49     const int8_t* __restrict__ vectors,
50     const float* __restrict__ scaling_factors, int n_batch,
51     float* __restrict__ result, const float* per_channel_scale,
52     const int32_t* input_offset, int32_t* scratch, int32_t* row_sums,
53     bool* compute_row_sums, CpuBackendContext* context);
54 
55 // Matrix multiplication for quantized values using symmetric quantization.
56 // Sparse version.
57 void SseSparseMatrixBatchVectorMultiplyAccumulate(
58     const int8_t* __restrict__ matrix, const uint8_t* __restrict__ ledger,
59     const int m_rows, const int m_cols, const int8_t* __restrict__ vectors,
60     const float* __restrict__ scaling_factors, int n_batch,
61     float* __restrict__ result);
62 
63 void SseReductionSumVector(const int8_t* input_vector, int32_t* output_vector,
64                            const int output_size, const int reduction_size);
65 
66 #endif  // __SSSE3__
67 
68 }  // namespace tensor_utils
69 }  // namespace tflite
70 
71 #endif  // TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_SSE_TENSOR_UTILS_IMPL_H_
72