chromium/third_party/eigen3/src/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h

// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2014 Benoit Steiner <[email protected]>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_CXX11_TENSOR_TENSOR_EVALUATOR_H
#define EIGEN_CXX11_TENSOR_TENSOR_EVALUATOR_H

// IWYU pragma: private
#include "./InternalHeaderCheck.h"

namespace Eigen {

/** \class TensorEvaluator
 * \ingroup CXX11_Tensor_Module
 *
 * \brief The tensor evaluator classes.
 *
 * These classes are responsible for the evaluation of the tensor expression.
 *
 * TODO: add support for more types of expressions, in particular expressions
 * leading to lvalues (slicing, reshaping, etc...)
 */

// Generic evaluator
template <typename Derived, typename Device>
struct TensorEvaluator {};

namespace internal {
template <typename T>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T loadConstant(const T* address) {}
// Use the texture cache on CUDA devices whenever possible
#if defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 350
template <>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float loadConstant(const float* address) {
  return __ldg(address);
}
template <>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE double loadConstant(const double* address) {
  return __ldg(address);
}
template <>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Eigen::half loadConstant(const Eigen::half* address) {
  return Eigen::half(half_impl::raw_uint16_to_half(__ldg(&address->x)));
}
#endif

}  // namespace internal

// Default evaluator for rvalues
TensorEvaluator<const Derived, Device>;

// -------------------- CwiseNullaryOp --------------------

TensorEvaluator<const TensorCwiseNullaryOp<NullaryOp, ArgType>, Device>;

// -------------------- CwiseUnaryOp --------------------

TensorEvaluator<const TensorCwiseUnaryOp<UnaryOp, ArgType>, Device>;

// -------------------- CwiseBinaryOp --------------------

TensorEvaluator<const TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>;

// -------------------- CwiseTernaryOp --------------------

TensorEvaluator<const TensorCwiseTernaryOp<TernaryOp, Arg1Type, Arg2Type, Arg3Type>, Device>;

// -------------------- SelectOp --------------------

TensorEvaluator<const TensorSelectOp<IfArgType, ThenArgType, ElseArgType>, Device>;

}  // end namespace Eigen

#if defined(EIGEN_USE_SYCL) && defined(SYCL_COMPILER_IS_DPCPP)
template <typename Derived, typename Device>
struct cl::sycl::is_device_copyable<
    Eigen::TensorEvaluator<Derived, Device>,
    std::enable_if_t<!std::is_trivially_copyable<Eigen::TensorEvaluator<Derived, Device>>::value>> : std::true_type {};
#endif

#endif  // EIGEN_CXX11_TENSOR_TENSOR_EVALUATOR_H