chromium/third_party/ruy/src/ruy/kernel_common.h

/* Copyright 2019 Google LLC. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef RUY_RUY_KERNEL_COMMON_H_
#define RUY_RUY_KERNEL_COMMON_H_

#include <algorithm>
#include <cstdint>
#include <type_traits>

#include "ruy/apply_multiplier.h"
#include "ruy/check_macros.h"
#include "ruy/mat.h"
#include "ruy/matrix.h"
#include "ruy/mul_params.h"
#include "ruy/opt_set.h"
#include "ruy/path.h"
#include "ruy/platform.h"
#include "ruy/profiler/instrumentation.h"
#include "ruy/side_pair.h"
#include "ruy/size_util.h"
#include "ruy/tune.h"

namespace ruy {

template <Path ThePath, typename LhsScalar, typename RhsScalar,
          typename AccumScalar, typename DstScalar>
struct Kernel;

#define RUY_INHERIT_KERNEL(PARENT, CHILD)

// KernelParams are shared across 32-bit and 64-bit NEON code, and x86 code.
//
// In other cases, we still define (empty) versions, so that dummy kernels
// can use the classes in function signatures.
#if ((RUY_PLATFORM_NEON_64 || RUY_PLATFORM_NEON_32) && RUY_OPT(ASM)) || \
    RUY_PLATFORM_X86

#define RUY_ASM_FLAG_HAS_BIAS
#define RUY_ASM_FLAG_HAS_LHS_SUMS
#define RUY_ASM_FLAG_HAS_RHS_SUMS
#define RUY_ASM_FLAG_HAS_PERCHANNEL
#define RUY_ASM_FLAG_NEEDS_LEFT_SHIFT
#define RUY_ASM_FLAG_CHANNEL_DIMENSION_IS_COL

#define RUY_ASM_TYPE_ID_UINT8
#define RUY_ASM_TYPE_ID_INT8
#define RUY_ASM_TYPE_ID_INT16
#define RUY_ASM_TYPE_ID_INT32

template <typename DstScalar>
struct DstTypeId {};

template <>
struct DstTypeId<std::uint8_t> {};

template <>
struct DstTypeId<std::int8_t> {};

template <>
struct DstTypeId<std::int16_t> {};

template <>
struct DstTypeId<std::int32_t> {};

template <int LhsCols, int RhsCols>
struct KernelParams8bit {};

template <typename RhsScalar, typename DstScalar, int LhsCols, int RhsCols>
void MakeKernelParams8bit(const PMat<std::int8_t>& lhs,
                          const PMat<RhsScalar>& rhs,
                          const MulParams<std::int32_t, DstScalar>& mul_params,
                          int start_row, int start_col, int end_row,
                          int end_col, Mat<DstScalar>* dst,
                          KernelParams8bit<LhsCols, RhsCols>* params) {}

template <int LhsCols, int RhsCols>
struct KernelParamsFloat {};

template <int LhsCols, int RhsCols>
inline void MakeKernelParamsFloat(const PMat<float>& lhs,
                                  const PMat<float>& rhs,
                                  const MulParams<float, float>& mul_params,
                                  int start_row, int start_col, int end_row,
                                  int end_col, Mat<float>* dst,
                                  KernelParamsFloat<LhsCols, RhsCols>* params) {}

#else  // ((RUY_PLATFORM_NEON_64 || RUY_PLATFORM_NEON_32) &&
       // RUY_OPT(ASM)) || RUY_PLATFORM_X86

template <int LhsCols, int RhsCols>
struct KernelParams8bit {};

template <int LhsCols, int RhsCols>
struct KernelParamsFloat {};

#endif  // ((RUY_PLATFORM_NEON_64 || RUY_PLATFORM_NEON_32) &&
        //  RUY_OPT(ASM)) || RUY_PLATFORM_X86

}  // namespace ruy

#endif  // RUY_RUY_KERNEL_COMMON_H_