chromium/third_party/ruy/src/ruy/pack_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_PACK_COMMON_H_
#define RUY_RUY_PACK_COMMON_H_

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include <type_traits>

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

namespace ruy {

template <typename Scalar>
Scalar SymmetricZeroPoint() {}

template <Path ThePath, typename Scalar>
struct PackedTypeImpl {};

PackedType;

template <typename PackedScalar, typename Scalar>
PackedScalar Pack(Scalar x) {}

template <Path ThePath, typename FixedKernelLayout, typename Scalar,
          typename PackedScalar, typename SumsType, Order SrcOrder>
struct PackImpl;

#define RUY_INHERIT_PACK(PARENT, CHILD)

// A generic yet fairly fast implementation of
//
//    PackImpl<ThePath, FixedKernelLayout<Order::kRowMajor, 1, KernelCols>,
//             float, float, float, Order::kRowMajor>
//
// that is, a packing code path for the case of floating-point, row-major
// source matrix, targeting typical float kernel layouts consisting of a
// single row.
//
// The only reason why this isn't a partial specialization of PackImpl is that
// this leads to ambiguous partial specializations as this conflicts with
// the ones defined by RUY_INHERIT_PACK.
//
// What's special about floating-point kernels is that they tend to use
// FixedKernelLayout<Order::kRowMajor, 1, KernelCols> for some value of
// KernelCols, making it easy to implement the packing code as essentially
// a bunch of memcpy's with compile-time-fixed size
// (KernelCols * sizeof(float)), typically 16, 32 or 64 bytes. Unlike the
// quantized case, there are no sums to compute, and the float kernels tend
// to use this kind of simple layout on multiple architectures, unlike the
// heavily architecture-specific layouts of quantized kernels.
//
// Here are the current instantiations of this template (as of 2020):
// Path          | KernelCols
// --------------+---------------------------------
// kNeon (ARM32) | 8 and 4 (for LHS and RHS sides)
// kNeon (ARM64) | 8
// kAvxFma       | 8
// kAvx512       | 16
template <Path ThePath, int KernelCols>
struct MemcpyRowMajorFloatPackImpl {};

#define RUY_USE_MEMCPY_ROWMAJOR_FLOAT_PACK(ThePath, KernelCols)

}  // namespace ruy

#endif  // RUY_RUY_PACK_COMMON_H_