2012-06-22 09:39:35 +02:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
|
// for linear algebra.
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2014-06-23 10:40:03 +02:00
|
|
|
// Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2012-06-28 15:25:25 +01:00
|
|
|
// Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
|
2012-06-22 09:39:35 +02:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// 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/.
|
2012-06-22 09:39:35 +02:00
|
|
|
|
|
|
|
|
#ifndef EIGEN_ASSIGN_EVALUATOR_H
|
|
|
|
|
#define EIGEN_ASSIGN_EVALUATOR_H
|
|
|
|
|
|
2023-08-21 16:25:22 +00:00
|
|
|
// IWYU pragma: private
|
2021-09-10 19:12:26 +00:00
|
|
|
#include "./InternalHeaderCheck.h"
|
|
|
|
|
|
2012-06-22 16:35:20 +02:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
// This implementation is based on Assign.h
|
|
|
|
|
|
|
|
|
|
namespace internal {
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Part 1 : the logic deciding a strategy for traversal and unrolling *
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
// copy_using_evaluator_traits is based on assign_traits
|
|
|
|
|
|
2018-11-13 16:15:08 +01:00
|
|
|
template <typename DstEvaluator, typename SrcEvaluator, typename AssignFunc, int MaxPacketSize = -1>
|
2012-06-22 09:39:35 +02:00
|
|
|
struct copy_using_evaluator_traits {
|
2025-02-15 00:39:41 +00:00
|
|
|
using Src = typename SrcEvaluator::XprType;
|
|
|
|
|
using Dst = typename DstEvaluator::XprType;
|
|
|
|
|
using DstScalar = typename Dst::Scalar;
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int DstFlags = DstEvaluator::Flags;
|
|
|
|
|
static constexpr int SrcFlags = SrcEvaluator::Flags;
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
public:
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int DstAlignment = DstEvaluator::Alignment;
|
|
|
|
|
static constexpr int SrcAlignment = SrcEvaluator::Alignment;
|
|
|
|
|
static constexpr int JointAlignment = plain_enum_min(DstAlignment, SrcAlignment);
|
|
|
|
|
static constexpr bool DstHasDirectAccess = bool(DstFlags & DirectAccessBit);
|
|
|
|
|
static constexpr bool SrcIsRowMajor = bool(SrcFlags & RowMajorBit);
|
|
|
|
|
static constexpr bool DstIsRowMajor = bool(DstFlags & RowMajorBit);
|
|
|
|
|
static constexpr bool IsVectorAtCompileTime = Dst::IsVectorAtCompileTime;
|
|
|
|
|
static constexpr int RowsAtCompileTime = Dst::RowsAtCompileTime;
|
|
|
|
|
static constexpr int ColsAtCompileTime = Dst::ColsAtCompileTime;
|
|
|
|
|
static constexpr int SizeAtCompileTime = Dst::SizeAtCompileTime;
|
|
|
|
|
static constexpr int MaxRowsAtCompileTime = Dst::MaxRowsAtCompileTime;
|
|
|
|
|
static constexpr int MaxColsAtCompileTime = Dst::MaxColsAtCompileTime;
|
|
|
|
|
static constexpr int MaxSizeAtCompileTime = Dst::MaxSizeAtCompileTime;
|
|
|
|
|
static constexpr int InnerSizeAtCompileTime = IsVectorAtCompileTime ? SizeAtCompileTime
|
|
|
|
|
: DstIsRowMajor ? ColsAtCompileTime
|
|
|
|
|
: RowsAtCompileTime;
|
|
|
|
|
static constexpr int MaxInnerSizeAtCompileTime = IsVectorAtCompileTime ? MaxSizeAtCompileTime
|
|
|
|
|
: DstIsRowMajor ? MaxColsAtCompileTime
|
|
|
|
|
: MaxRowsAtCompileTime;
|
|
|
|
|
static constexpr int RestrictedInnerSize = min_size_prefer_fixed(InnerSizeAtCompileTime, MaxPacketSize);
|
|
|
|
|
static constexpr int RestrictedLinearSize = min_size_prefer_fixed(SizeAtCompileTime, MaxPacketSize);
|
|
|
|
|
static constexpr int OuterStride = outer_stride_at_compile_time<Dst>::ret;
|
2016-04-13 18:15:49 +02:00
|
|
|
|
|
|
|
|
// TODO distinguish between linear traversal and inner-traversals
|
2025-02-15 00:39:41 +00:00
|
|
|
using LinearPacketType = typename find_best_packet<DstScalar, RestrictedLinearSize>::type;
|
|
|
|
|
using InnerPacketType = typename find_best_packet<DstScalar, RestrictedInnerSize>::type;
|
2016-04-13 18:15:49 +02:00
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int LinearPacketSize = unpacket_traits<LinearPacketType>::size;
|
|
|
|
|
static constexpr int InnerPacketSize = unpacket_traits<InnerPacketType>::size;
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2016-04-13 18:15:49 +02:00
|
|
|
public:
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int LinearRequiredAlignment = unpacket_traits<LinearPacketType>::alignment;
|
|
|
|
|
static constexpr int InnerRequiredAlignment = unpacket_traits<InnerPacketType>::alignment;
|
2016-04-13 18:15:49 +02:00
|
|
|
|
|
|
|
|
private:
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr bool StorageOrdersAgree = DstIsRowMajor == SrcIsRowMajor;
|
|
|
|
|
static constexpr bool MightVectorize = StorageOrdersAgree && bool(DstFlags & SrcFlags & ActualPacketAccessBit) &&
|
|
|
|
|
bool(functor_traits<AssignFunc>::PacketAccess);
|
|
|
|
|
static constexpr bool MayInnerVectorize = MightVectorize && (InnerSizeAtCompileTime != Dynamic) &&
|
|
|
|
|
(InnerSizeAtCompileTime % InnerPacketSize == 0) &&
|
|
|
|
|
(OuterStride != Dynamic) && (OuterStride % InnerPacketSize == 0) &&
|
|
|
|
|
(EIGEN_UNALIGNED_VECTORIZE || JointAlignment >= InnerRequiredAlignment),
|
|
|
|
|
MayLinearize = StorageOrdersAgree && (DstFlags & SrcFlags & LinearAccessBit),
|
|
|
|
|
MayLinearVectorize = MightVectorize && MayLinearize && DstHasDirectAccess &&
|
|
|
|
|
(EIGEN_UNALIGNED_VECTORIZE || (DstAlignment >= LinearRequiredAlignment) ||
|
|
|
|
|
MaxSizeAtCompileTime == Dynamic);
|
|
|
|
|
/* If the destination isn't aligned, we have to do runtime checks and we don't unroll,
|
|
|
|
|
so it's only good for large enough sizes. */
|
|
|
|
|
static constexpr bool MaySliceVectorize =
|
|
|
|
|
MightVectorize && DstHasDirectAccess &&
|
|
|
|
|
(MaxInnerSizeAtCompileTime == Dynamic ||
|
|
|
|
|
MaxInnerSizeAtCompileTime >= (EIGEN_UNALIGNED_VECTORIZE ? InnerPacketSize : (3 * InnerPacketSize)));
|
|
|
|
|
/* slice vectorization can be slow, so we only want it if the slices are big, which is
|
|
|
|
|
indicated by InnerMaxSize rather than InnerSize, think of the case of a dynamic block
|
|
|
|
|
in a fixed-size matrix
|
|
|
|
|
However, with EIGEN_UNALIGNED_VECTORIZE and unrolling, slice vectorization is still worth it */
|
2012-06-22 09:39:35 +02:00
|
|
|
|
|
|
|
|
public:
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int Traversal = SizeAtCompileTime == 0 ? AllAtOnceTraversal
|
|
|
|
|
: (MayLinearVectorize && (LinearPacketSize > InnerPacketSize))
|
|
|
|
|
? LinearVectorizedTraversal
|
|
|
|
|
: MayInnerVectorize ? InnerVectorizedTraversal
|
|
|
|
|
: MayLinearVectorize ? LinearVectorizedTraversal
|
|
|
|
|
: MaySliceVectorize ? SliceVectorizedTraversal
|
|
|
|
|
: MayLinearize ? LinearTraversal
|
|
|
|
|
: DefaultTraversal;
|
|
|
|
|
static constexpr bool Vectorized = Traversal == InnerVectorizedTraversal || Traversal == LinearVectorizedTraversal ||
|
|
|
|
|
Traversal == SliceVectorizedTraversal;
|
|
|
|
|
|
|
|
|
|
using PacketType = std::conditional_t<Traversal == LinearVectorizedTraversal, LinearPacketType, InnerPacketType>;
|
2016-04-13 18:15:49 +02:00
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
private:
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int ActualPacketSize = Vectorized ? unpacket_traits<PacketType>::size : 1;
|
|
|
|
|
static constexpr int UnrollingLimit = EIGEN_UNROLLING_LIMIT * ActualPacketSize;
|
|
|
|
|
static constexpr int CoeffReadCost = int(DstEvaluator::CoeffReadCost) + int(SrcEvaluator::CoeffReadCost);
|
|
|
|
|
static constexpr bool MayUnrollCompletely =
|
|
|
|
|
(SizeAtCompileTime != Dynamic) && (SizeAtCompileTime * CoeffReadCost <= UnrollingLimit);
|
|
|
|
|
static constexpr bool MayUnrollInner =
|
|
|
|
|
(InnerSizeAtCompileTime != Dynamic) && (InnerSizeAtCompileTime * CoeffReadCost <= UnrollingLimit);
|
2012-06-22 09:39:35 +02:00
|
|
|
|
|
|
|
|
public:
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int Unrolling =
|
|
|
|
|
(Traversal == InnerVectorizedTraversal || Traversal == DefaultTraversal)
|
|
|
|
|
? (MayUnrollCompletely ? CompleteUnrolling
|
|
|
|
|
: MayUnrollInner ? InnerUnrolling
|
|
|
|
|
: NoUnrolling)
|
|
|
|
|
: Traversal == LinearVectorizedTraversal
|
|
|
|
|
? (MayUnrollCompletely && (EIGEN_UNALIGNED_VECTORIZE || (DstAlignment >= LinearRequiredAlignment))
|
|
|
|
|
? CompleteUnrolling
|
|
|
|
|
: NoUnrolling)
|
|
|
|
|
: Traversal == LinearTraversal ? (MayUnrollCompletely ? CompleteUnrolling : NoUnrolling)
|
2016-07-28 13:47:33 +02:00
|
|
|
#if EIGEN_UNALIGNED_VECTORIZE
|
2025-02-15 00:39:41 +00:00
|
|
|
: Traversal == SliceVectorizedTraversal ? (MayUnrollInner ? InnerUnrolling : NoUnrolling)
|
2016-07-28 13:47:33 +02:00
|
|
|
#endif
|
2025-02-15 00:39:41 +00:00
|
|
|
: NoUnrolling;
|
2012-06-22 09:39:35 +02:00
|
|
|
|
|
|
|
|
#ifdef EIGEN_DEBUG_ASSIGN
|
|
|
|
|
static void debug() {
|
2014-03-12 18:13:18 +01:00
|
|
|
std::cerr << "DstXpr: " << typeid(typename DstEvaluator::XprType).name() << std::endl;
|
|
|
|
|
std::cerr << "SrcXpr: " << typeid(typename SrcEvaluator::XprType).name() << std::endl;
|
|
|
|
|
std::cerr.setf(std::ios::hex, std::ios::basefield);
|
2015-10-27 10:38:49 +01:00
|
|
|
std::cerr << "DstFlags"
|
|
|
|
|
<< " = " << DstFlags << " (" << demangle_flags(DstFlags) << " )" << std::endl;
|
|
|
|
|
std::cerr << "SrcFlags"
|
|
|
|
|
<< " = " << SrcFlags << " (" << demangle_flags(SrcFlags) << " )" << std::endl;
|
2014-03-12 18:13:18 +01:00
|
|
|
std::cerr.unsetf(std::ios::hex);
|
First part of a big refactoring of alignment control to enable the handling of arbitrarily aligned buffers. It includes:
- AlignedBit flag is deprecated. Alignment is now specified by the evaluator through the 'Alignment' enum, e.g., evaluator<Xpr>::Alignment. Its value is in Bytes.
- Add several enums to specify alignment: Aligned8, Aligned16, Aligned32, Aligned64, Aligned128. AlignedMax corresponds to EIGEN_MAX_ALIGN_BYTES. Such enums are used to define the above Alignment value, and as the 'Options' template parameter of Map<> and Ref<>.
- The Aligned enum is now deprecated. It is now an alias for Aligned16.
- Currently, traits<Matrix<>>, traits<Array<>>, traits<Ref<>>, traits<Map<>>, and traits<Block<>> also expose the Alignment enum.
2015-08-06 15:31:07 +02:00
|
|
|
EIGEN_DEBUG_VAR(DstAlignment)
|
|
|
|
|
EIGEN_DEBUG_VAR(SrcAlignment)
|
2016-04-13 18:15:49 +02:00
|
|
|
EIGEN_DEBUG_VAR(LinearRequiredAlignment)
|
|
|
|
|
EIGEN_DEBUG_VAR(InnerRequiredAlignment)
|
2012-06-22 09:39:35 +02:00
|
|
|
EIGEN_DEBUG_VAR(JointAlignment)
|
2025-02-15 00:39:41 +00:00
|
|
|
EIGEN_DEBUG_VAR(InnerSizeAtCompileTime)
|
|
|
|
|
EIGEN_DEBUG_VAR(MaxInnerSizeAtCompileTime)
|
2016-04-13 18:15:49 +02:00
|
|
|
EIGEN_DEBUG_VAR(LinearPacketSize)
|
|
|
|
|
EIGEN_DEBUG_VAR(InnerPacketSize)
|
2016-05-24 21:54:03 +02:00
|
|
|
EIGEN_DEBUG_VAR(ActualPacketSize)
|
2012-06-22 09:39:35 +02:00
|
|
|
EIGEN_DEBUG_VAR(StorageOrdersAgree)
|
|
|
|
|
EIGEN_DEBUG_VAR(MightVectorize)
|
|
|
|
|
EIGEN_DEBUG_VAR(MayLinearize)
|
|
|
|
|
EIGEN_DEBUG_VAR(MayInnerVectorize)
|
|
|
|
|
EIGEN_DEBUG_VAR(MayLinearVectorize)
|
|
|
|
|
EIGEN_DEBUG_VAR(MaySliceVectorize)
|
2015-10-27 10:38:49 +01:00
|
|
|
std::cerr << "Traversal"
|
|
|
|
|
<< " = " << Traversal << " (" << demangle_traversal(Traversal) << ")" << std::endl;
|
2016-07-06 22:27:15 +02:00
|
|
|
EIGEN_DEBUG_VAR(SrcEvaluator::CoeffReadCost)
|
2018-09-21 14:32:39 +02:00
|
|
|
EIGEN_DEBUG_VAR(DstEvaluator::CoeffReadCost)
|
|
|
|
|
EIGEN_DEBUG_VAR(Dst::SizeAtCompileTime)
|
2012-06-22 09:39:35 +02:00
|
|
|
EIGEN_DEBUG_VAR(UnrollingLimit)
|
|
|
|
|
EIGEN_DEBUG_VAR(MayUnrollCompletely)
|
|
|
|
|
EIGEN_DEBUG_VAR(MayUnrollInner)
|
2015-10-27 10:38:49 +01:00
|
|
|
std::cerr << "Unrolling"
|
|
|
|
|
<< " = " << Unrolling << " (" << demangle_unrolling(Unrolling) << ")" << std::endl;
|
2014-03-12 18:13:18 +01:00
|
|
|
std::cerr << std::endl;
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
* Part 2 : meta-unrollers
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
/************************
|
|
|
|
|
*** Default traversal ***
|
|
|
|
|
************************/
|
|
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
template <typename Kernel, int Index_, int Stop>
|
2012-06-22 09:39:35 +02:00
|
|
|
struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling {
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int Outer = Index_ / Kernel::AssignmentTraits::InnerSizeAtCompileTime;
|
|
|
|
|
static constexpr int Inner = Index_ % Kernel::AssignmentTraits::InnerSizeAtCompileTime;
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2025-02-15 00:39:41 +00:00
|
|
|
kernel.assignCoeffByOuterInner(Outer, Inner);
|
|
|
|
|
copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Index_ + 1, Stop>::run(kernel);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel, int Stop>
|
|
|
|
|
struct copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, Stop, Stop> {
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) {}
|
2012-06-22 09:39:35 +02:00
|
|
|
};
|
|
|
|
|
|
2014-12-04 22:48:53 +01:00
|
|
|
template <typename Kernel, int Index_, int Stop>
|
2012-06-22 09:39:35 +02:00
|
|
|
struct copy_using_evaluator_DefaultTraversal_InnerUnrolling {
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel, Index outer) {
|
2014-12-04 22:48:53 +01:00
|
|
|
kernel.assignCoeffByOuterInner(outer, Index_);
|
|
|
|
|
copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Index_ + 1, Stop>::run(kernel, outer);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel, int Stop>
|
|
|
|
|
struct copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, Stop, Stop> {
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index) {}
|
2012-06-22 09:39:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
|
*** Linear traversal ***
|
|
|
|
|
***********************/
|
|
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
template <typename Kernel, int Index_, int Stop>
|
2012-06-22 09:39:35 +02:00
|
|
|
struct copy_using_evaluator_LinearTraversal_CompleteUnrolling {
|
2014-10-13 17:18:26 +02:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2025-02-15 00:39:41 +00:00
|
|
|
kernel.assignCoeff(Index_);
|
|
|
|
|
copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Index_ + 1, Stop>::run(kernel);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel, int Stop>
|
|
|
|
|
struct copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, Stop, Stop> {
|
2014-10-13 17:18:26 +02:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&) {}
|
2012-06-22 09:39:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**************************
|
|
|
|
|
*** Inner vectorization ***
|
|
|
|
|
**************************/
|
|
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
template <typename Kernel, int Index_, int Stop>
|
2012-06-22 09:39:35 +02:00
|
|
|
struct copy_using_evaluator_innervec_CompleteUnrolling {
|
2025-02-15 00:39:41 +00:00
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int Outer = Index_ / Kernel::AssignmentTraits::InnerSizeAtCompileTime;
|
|
|
|
|
static constexpr int Inner = Index_ % Kernel::AssignmentTraits::InnerSizeAtCompileTime;
|
|
|
|
|
static constexpr int NextIndex = Index_ + unpacket_traits<PacketType>::size;
|
|
|
|
|
static constexpr int SrcAlignment = Kernel::AssignmentTraits::SrcAlignment;
|
|
|
|
|
static constexpr int DstAlignment = Kernel::AssignmentTraits::DstAlignment;
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2025-02-15 00:39:41 +00:00
|
|
|
kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(Outer, Inner);
|
2013-11-07 12:03:12 +01:00
|
|
|
copy_using_evaluator_innervec_CompleteUnrolling<Kernel, NextIndex, Stop>::run(kernel);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel, int Stop>
|
|
|
|
|
struct copy_using_evaluator_innervec_CompleteUnrolling<Kernel, Stop, Stop> {
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) {}
|
2012-06-22 09:39:35 +02:00
|
|
|
};
|
|
|
|
|
|
2016-07-28 13:47:33 +02:00
|
|
|
template <typename Kernel, int Index_, int Stop, int SrcAlignment, int DstAlignment>
|
2012-06-22 09:39:35 +02:00
|
|
|
struct copy_using_evaluator_innervec_InnerUnrolling {
|
2025-02-15 00:39:41 +00:00
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int NextIndex = Index_ + unpacket_traits<PacketType>::size;
|
|
|
|
|
|
2014-12-04 22:48:53 +01:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel, Index outer) {
|
2016-05-24 17:12:12 +02:00
|
|
|
kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, Index_);
|
2016-07-28 13:47:33 +02:00
|
|
|
copy_using_evaluator_innervec_InnerUnrolling<Kernel, NextIndex, Stop, SrcAlignment, DstAlignment>::run(kernel,
|
|
|
|
|
outer);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-28 13:47:33 +02:00
|
|
|
template <typename Kernel, int Stop, int SrcAlignment, int DstAlignment>
|
|
|
|
|
struct copy_using_evaluator_innervec_InnerUnrolling<Kernel, Stop, Stop, SrcAlignment, DstAlignment> {
|
2014-12-04 22:48:53 +01:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel&, Index) {}
|
2012-06-22 09:39:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
* Part 3 : implementation of all cases
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
2013-11-06 18:17:59 +01:00
|
|
|
// dense_assignment_loop is based on assign_impl
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel, int Traversal = Kernel::AssignmentTraits::Traversal,
|
|
|
|
|
int Unrolling = Kernel::AssignmentTraits::Unrolling>
|
2013-11-06 18:17:59 +01:00
|
|
|
struct dense_assignment_loop;
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2020-12-07 08:27:03 -08:00
|
|
|
/************************
|
|
|
|
|
***** Special Cases *****
|
|
|
|
|
************************/
|
|
|
|
|
|
|
|
|
|
// Zero-sized assignment is a no-op.
|
|
|
|
|
template <typename Kernel, int Unrolling>
|
|
|
|
|
struct dense_assignment_loop<Kernel, AllAtOnceTraversal, Unrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int SizeAtCompileTime = Kernel::AssignmentTraits::SizeAtCompileTime;
|
|
|
|
|
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE EIGEN_CONSTEXPR run(Kernel& /*kernel*/) {
|
2025-02-15 00:39:41 +00:00
|
|
|
EIGEN_STATIC_ASSERT(SizeAtCompileTime == 0, EIGEN_INTERNAL_ERROR_PLEASE_FILE_A_BUG_REPORT)
|
2020-12-07 08:27:03 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
/************************
|
|
|
|
|
*** Default traversal ***
|
|
|
|
|
************************/
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, DefaultTraversal, NoUnrolling> {
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static void EIGEN_STRONG_INLINE run(Kernel& kernel) {
|
2013-11-07 12:03:12 +01:00
|
|
|
for (Index outer = 0; outer < kernel.outerSize(); ++outer) {
|
|
|
|
|
for (Index inner = 0; inner < kernel.innerSize(); ++inner) {
|
|
|
|
|
kernel.assignCoeffByOuterInner(outer, inner);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, DefaultTraversal, CompleteUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int SizeAtCompileTime = Kernel::AssignmentTraits::SizeAtCompileTime;
|
|
|
|
|
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2025-02-15 00:39:41 +00:00
|
|
|
copy_using_evaluator_DefaultTraversal_CompleteUnrolling<Kernel, 0, SizeAtCompileTime>::run(kernel);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, DefaultTraversal, InnerUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int InnerSizeAtCompileTime = Kernel::AssignmentTraits::InnerSizeAtCompileTime;
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2013-11-07 12:03:12 +01:00
|
|
|
const Index outerSize = kernel.outerSize();
|
2012-06-22 09:39:35 +02:00
|
|
|
for (Index outer = 0; outer < outerSize; ++outer)
|
2025-02-15 00:39:41 +00:00
|
|
|
copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, 0, InnerSizeAtCompileTime>::run(kernel, outer);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
|
*** Linear vectorization ***
|
|
|
|
|
***************************/
|
|
|
|
|
|
2013-11-06 18:17:59 +01:00
|
|
|
// The goal of unaligned_dense_assignment_loop is simply to factorize the handling
|
|
|
|
|
// of the non vectorizable beginning and ending parts
|
|
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
template <bool IsAligned = false>
|
2013-11-06 18:17:59 +01:00
|
|
|
struct unaligned_dense_assignment_loop {
|
2012-06-22 09:39:35 +02:00
|
|
|
// if IsAligned = true, then do nothing
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&, Index, Index) {}
|
2012-06-22 09:39:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
2013-11-06 18:17:59 +01:00
|
|
|
struct unaligned_dense_assignment_loop<false> {
|
2012-06-22 09:39:35 +02:00
|
|
|
// MSVC must not inline this functions. If it does, it fails to optimize the
|
|
|
|
|
// packet access path.
|
2013-11-06 18:17:59 +01:00
|
|
|
// FIXME check which version exhibits this issue
|
2014-11-04 21:58:52 +01:00
|
|
|
#if EIGEN_COMP_MSVC
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
static EIGEN_DONT_INLINE void run(Kernel& kernel, Index start, Index end)
|
2012-06-22 09:39:35 +02:00
|
|
|
#else
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel, Index start, Index end)
|
2012-06-22 09:39:35 +02:00
|
|
|
#endif
|
|
|
|
|
{
|
2014-12-04 22:48:53 +01:00
|
|
|
for (Index index = start; index < end; ++index) kernel.assignCoeff(index);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
template <typename Kernel, int Index_, int Stop>
|
2023-05-22 16:39:24 +00:00
|
|
|
struct copy_using_evaluator_linearvec_CompleteUnrolling {
|
2025-02-15 00:39:41 +00:00
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int SrcAlignment = Kernel::AssignmentTraits::SrcAlignment;
|
|
|
|
|
static constexpr int DstAlignment = Kernel::AssignmentTraits::DstAlignment;
|
|
|
|
|
static constexpr int NextIndex = Index_ + unpacket_traits<PacketType>::size;
|
2023-05-22 16:39:24 +00:00
|
|
|
|
|
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2025-02-15 00:39:41 +00:00
|
|
|
kernel.template assignPacket<DstAlignment, SrcAlignment, PacketType>(Index_);
|
2023-05-22 16:39:24 +00:00
|
|
|
copy_using_evaluator_linearvec_CompleteUnrolling<Kernel, NextIndex, Stop>::run(kernel);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename Kernel, int Stop>
|
|
|
|
|
struct copy_using_evaluator_linearvec_CompleteUnrolling<Kernel, Stop, Stop> {
|
|
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel&) {}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, NoUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
using Scalar = typename Kernel::Scalar;
|
|
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int PacketSize = unpacket_traits<PacketType>::size;
|
|
|
|
|
static constexpr int RequestedAlignment = Kernel::AssignmentTraits::LinearRequiredAlignment;
|
|
|
|
|
static constexpr bool DstIsAligned = Kernel::AssignmentTraits::DstAlignment >= RequestedAlignment;
|
|
|
|
|
static constexpr int SrcAlignment = Kernel::AssignmentTraits::JointAlignment;
|
|
|
|
|
static constexpr int DstAlignment =
|
|
|
|
|
packet_traits<Scalar>::AlignedOnScalar ? RequestedAlignment : Kernel::AssignmentTraits::DstAlignment;
|
|
|
|
|
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) {
|
2013-11-07 12:03:12 +01:00
|
|
|
const Index size = kernel.size();
|
2025-02-15 00:39:41 +00:00
|
|
|
const Index alignedStart = DstIsAligned ? 0 : first_aligned<RequestedAlignment>(kernel.dstDataPtr(), size);
|
|
|
|
|
const Index alignedEnd = alignedStart + numext::round_down(size - alignedStart, PacketSize);
|
|
|
|
|
|
|
|
|
|
unaligned_dense_assignment_loop<DstIsAligned>::run(kernel, 0, alignedStart);
|
|
|
|
|
|
|
|
|
|
for (Index index = alignedStart; index < alignedEnd; index += PacketSize)
|
|
|
|
|
kernel.template assignPacket<DstAlignment, SrcAlignment, PacketType>(index);
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
unaligned_dense_assignment_loop<>::run(kernel, alignedEnd, size);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, LinearVectorizedTraversal, CompleteUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int PacketSize = unpacket_traits<PacketType>::size;
|
|
|
|
|
static constexpr int Size = Kernel::AssignmentTraits::SizeAtCompileTime;
|
|
|
|
|
static constexpr int AlignedSize = numext::round_down(Size, PacketSize);
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) {
|
|
|
|
|
copy_using_evaluator_linearvec_CompleteUnrolling<Kernel, 0, AlignedSize>::run(kernel);
|
|
|
|
|
copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, AlignedSize, Size>::run(kernel);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**************************
|
|
|
|
|
*** Inner vectorization ***
|
|
|
|
|
**************************/
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, NoUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int PacketSize = unpacket_traits<PacketType>::size;
|
|
|
|
|
static constexpr int SrcAlignment = Kernel::AssignmentTraits::JointAlignment;
|
|
|
|
|
static constexpr int DstAlignment = Kernel::AssignmentTraits::DstAlignment;
|
|
|
|
|
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) {
|
2013-11-07 12:03:12 +01:00
|
|
|
const Index innerSize = kernel.innerSize();
|
|
|
|
|
const Index outerSize = kernel.outerSize();
|
2012-06-22 09:39:35 +02:00
|
|
|
for (Index outer = 0; outer < outerSize; ++outer)
|
2025-02-15 00:39:41 +00:00
|
|
|
for (Index inner = 0; inner < innerSize; inner += PacketSize)
|
2016-05-24 17:12:12 +02:00
|
|
|
kernel.template assignPacketByOuterInner<DstAlignment, SrcAlignment, PacketType>(outer, inner);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, CompleteUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int SizeAtCompileTime = Kernel::AssignmentTraits::SizeAtCompileTime;
|
|
|
|
|
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2025-02-15 00:39:41 +00:00
|
|
|
copy_using_evaluator_innervec_CompleteUnrolling<Kernel, 0, SizeAtCompileTime>::run(kernel);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, InnerVectorizedTraversal, InnerUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
static constexpr int InnerSize = Kernel::AssignmentTraits::InnerSizeAtCompileTime;
|
|
|
|
|
static constexpr int SrcAlignment = Kernel::AssignmentTraits::SrcAlignment;
|
|
|
|
|
static constexpr int DstAlignment = Kernel::AssignmentTraits::DstAlignment;
|
|
|
|
|
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel& kernel) {
|
2013-11-07 12:03:12 +01:00
|
|
|
const Index outerSize = kernel.outerSize();
|
2012-06-22 09:39:35 +02:00
|
|
|
for (Index outer = 0; outer < outerSize; ++outer)
|
2025-02-15 00:39:41 +00:00
|
|
|
copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, InnerSize, SrcAlignment, DstAlignment>::run(kernel,
|
|
|
|
|
outer);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***********************
|
|
|
|
|
*** Linear traversal ***
|
|
|
|
|
***********************/
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, LinearTraversal, NoUnrolling> {
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) {
|
2013-11-07 12:03:12 +01:00
|
|
|
const Index size = kernel.size();
|
2012-06-22 09:39:35 +02:00
|
|
|
for (Index i = 0; i < size; ++i) kernel.assignCoeff(i);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, LinearTraversal, CompleteUnrolling> {
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) {
|
2025-02-15 00:39:41 +00:00
|
|
|
copy_using_evaluator_LinearTraversal_CompleteUnrolling<Kernel, 0, Kernel::AssignmentTraits::SizeAtCompileTime>::run(
|
|
|
|
|
kernel);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**************************
|
|
|
|
|
*** Slice vectorization ***
|
|
|
|
|
***************************/
|
|
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, NoUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
using Scalar = typename Kernel::Scalar;
|
|
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int PacketSize = unpacket_traits<PacketType>::size;
|
|
|
|
|
static constexpr int RequestedAlignment = Kernel::AssignmentTraits::InnerRequiredAlignment;
|
|
|
|
|
static constexpr bool Alignable =
|
|
|
|
|
packet_traits<Scalar>::AlignedOnScalar || Kernel::AssignmentTraits::DstAlignment >= sizeof(Scalar);
|
|
|
|
|
static constexpr bool DstIsAligned = Kernel::AssignmentTraits::DstAlignment >= RequestedAlignment;
|
|
|
|
|
static constexpr int DstAlignment = Alignable ? RequestedAlignment : Kernel::AssignmentTraits::DstAlignment;
|
|
|
|
|
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) {
|
2016-12-05 15:08:09 +01:00
|
|
|
const Scalar* dst_ptr = kernel.dstDataPtr();
|
2025-02-15 00:39:41 +00:00
|
|
|
if ((!DstIsAligned) && (std::uintptr_t(dst_ptr) % sizeof(Scalar)) > 0) {
|
2018-11-14 14:43:18 +01:00
|
|
|
// the pointer is not aligned-on scalar, so alignment is not possible
|
2015-06-14 15:04:07 +02:00
|
|
|
return dense_assignment_loop<Kernel, DefaultTraversal, NoUnrolling>::run(kernel);
|
|
|
|
|
}
|
2013-11-07 12:03:12 +01:00
|
|
|
const Index innerSize = kernel.innerSize();
|
|
|
|
|
const Index outerSize = kernel.outerSize();
|
2025-02-15 00:39:41 +00:00
|
|
|
const Index alignedStep = Alignable ? (PacketSize - kernel.outerStride() % PacketSize) % PacketSize : 0;
|
2015-08-06 17:52:01 +02:00
|
|
|
Index alignedStart =
|
2025-02-15 00:39:41 +00:00
|
|
|
((!Alignable) || DstIsAligned) ? 0 : internal::first_aligned<RequestedAlignment>(dst_ptr, innerSize);
|
2012-06-22 09:39:35 +02:00
|
|
|
|
|
|
|
|
for (Index outer = 0; outer < outerSize; ++outer) {
|
2025-02-15 00:39:41 +00:00
|
|
|
const Index alignedEnd = alignedStart + numext::round_down(innerSize - alignedStart, PacketSize);
|
2012-06-22 09:39:35 +02:00
|
|
|
// do the non-vectorizable part of the assignment
|
2013-11-06 18:17:59 +01:00
|
|
|
for (Index inner = 0; inner < alignedStart; ++inner) kernel.assignCoeffByOuterInner(outer, inner);
|
2012-06-22 09:39:35 +02:00
|
|
|
|
|
|
|
|
// do the vectorizable part of the assignment
|
2025-02-15 00:39:41 +00:00
|
|
|
for (Index inner = alignedStart; inner < alignedEnd; inner += PacketSize)
|
|
|
|
|
kernel.template assignPacketByOuterInner<DstAlignment, Unaligned, PacketType>(outer, inner);
|
2012-06-22 09:39:35 +02:00
|
|
|
|
|
|
|
|
// do the non-vectorizable part of the assignment
|
2013-11-06 18:17:59 +01:00
|
|
|
for (Index inner = alignedEnd; inner < innerSize; ++inner) kernel.assignCoeffByOuterInner(outer, inner);
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
alignedStart = numext::mini((alignedStart + alignedStep) % PacketSize, innerSize);
|
2012-06-22 09:39:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-28 13:47:33 +02:00
|
|
|
#if EIGEN_UNALIGNED_VECTORIZE
|
|
|
|
|
template <typename Kernel>
|
|
|
|
|
struct dense_assignment_loop<Kernel, SliceVectorizedTraversal, InnerUnrolling> {
|
2025-02-15 00:39:41 +00:00
|
|
|
using PacketType = typename Kernel::PacketType;
|
|
|
|
|
static constexpr int PacketSize = unpacket_traits<PacketType>::size;
|
|
|
|
|
static constexpr int InnerSize = Kernel::AssignmentTraits::InnerSizeAtCompileTime;
|
|
|
|
|
static constexpr int VectorizableSize = numext::round_down(InnerSize, PacketSize);
|
2016-07-28 13:47:33 +02:00
|
|
|
|
2025-02-15 00:39:41 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void run(Kernel& kernel) {
|
2016-07-28 13:47:33 +02:00
|
|
|
for (Index outer = 0; outer < kernel.outerSize(); ++outer) {
|
2025-02-15 00:39:41 +00:00
|
|
|
copy_using_evaluator_innervec_InnerUnrolling<Kernel, 0, VectorizableSize, 0, 0>::run(kernel, outer);
|
|
|
|
|
copy_using_evaluator_DefaultTraversal_InnerUnrolling<Kernel, VectorizableSize, InnerSize>::run(kernel, outer);
|
2016-07-28 13:47:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
/***************************************************************************
|
2013-11-25 15:20:31 +01:00
|
|
|
* Part 4 : Generic dense assignment kernel
|
2013-11-06 18:17:59 +01:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
// This class generalize the assignment of a coefficient (or packet) from one dense evaluator
|
|
|
|
|
// to another dense writable evaluator.
|
2013-11-07 12:03:12 +01:00
|
|
|
// It is parametrized by the two evaluators, and the actual assignment functor.
|
|
|
|
|
// This abstraction level permits to keep the evaluation loops as simple and as generic as possible.
|
2013-11-06 18:17:59 +01:00
|
|
|
// One can customize the assignment using this generic dense_assignment_kernel with different
|
|
|
|
|
// functors, or by completely overloading it, by-passing a functor.
|
2013-12-02 14:44:13 +01:00
|
|
|
template <typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor, int Version = Specialized>
|
2013-11-07 12:03:12 +01:00
|
|
|
class generic_dense_assignment_kernel {
|
|
|
|
|
protected:
|
|
|
|
|
typedef typename DstEvaluatorTypeT::XprType DstXprType;
|
|
|
|
|
typedef typename SrcEvaluatorTypeT::XprType SrcXprType;
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2023-11-29 11:12:48 +00:00
|
|
|
public:
|
2013-11-07 12:03:12 +01:00
|
|
|
typedef DstEvaluatorTypeT DstEvaluatorType;
|
|
|
|
|
typedef SrcEvaluatorTypeT SrcEvaluatorType;
|
|
|
|
|
typedef typename DstEvaluatorType::Scalar Scalar;
|
2014-03-10 23:24:40 +01:00
|
|
|
typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor> AssignmentTraits;
|
2015-08-07 12:01:39 +02:00
|
|
|
typedef typename AssignmentTraits::PacketType PacketType;
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2019-02-15 16:35:35 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE generic_dense_assignment_kernel(DstEvaluatorType& dst,
|
|
|
|
|
const SrcEvaluatorType& src,
|
|
|
|
|
const Functor& func, DstXprType& dstExpr)
|
2013-11-07 12:03:12 +01:00
|
|
|
: m_dst(dst), m_src(src), m_functor(func), m_dstExpr(dstExpr) {
|
2014-03-10 23:24:40 +01:00
|
|
|
#ifdef EIGEN_DEBUG_ASSIGN
|
|
|
|
|
AssignmentTraits::debug();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2021-03-08 12:39:11 -05:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_dstExpr.size(); }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerSize() const EIGEN_NOEXCEPT { return m_dstExpr.innerSize(); }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerSize() const EIGEN_NOEXCEPT { return m_dstExpr.outerSize(); }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_dstExpr.rows(); }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_dstExpr.cols(); }
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const EIGEN_NOEXCEPT { return m_dstExpr.outerStride(); }
|
|
|
|
|
|
|
|
|
|
EIGEN_DEVICE_FUNC DstEvaluatorType& dstEvaluator() EIGEN_NOEXCEPT { return m_dst; }
|
|
|
|
|
EIGEN_DEVICE_FUNC const SrcEvaluatorType& srcEvaluator() const EIGEN_NOEXCEPT { return m_src; }
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-12-02 14:05:34 +01:00
|
|
|
/// Assign src(row,col) to dst(row,col) through the assignment functor.
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index row, Index col) {
|
2013-11-07 12:03:12 +01:00
|
|
|
m_functor.assignCoeff(m_dst.coeffRef(row, col), m_src.coeff(row, col));
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-12-02 14:05:34 +01:00
|
|
|
/// \sa assignCoeff(Index,Index)
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeff(Index index) {
|
2013-11-07 12:03:12 +01:00
|
|
|
m_functor.assignCoeff(m_dst.coeffRef(index), m_src.coeff(index));
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-12-02 14:05:34 +01:00
|
|
|
/// \sa assignCoeff(Index,Index)
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignCoeffByOuterInner(Index outer, Index inner) {
|
2020-12-07 08:27:03 -08:00
|
|
|
Index row = rowIndexByOuterInner(outer, inner);
|
|
|
|
|
Index col = colIndexByOuterInner(outer, inner);
|
2013-11-07 12:03:12 +01:00
|
|
|
assignCoeff(row, col);
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2023-05-22 16:39:24 +00:00
|
|
|
template <int StoreMode, int LoadMode, typename Packet>
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index row, Index col) {
|
2023-05-22 16:39:24 +00:00
|
|
|
m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(row, col),
|
|
|
|
|
m_src.template packet<LoadMode, Packet>(row, col));
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2023-05-22 16:39:24 +00:00
|
|
|
template <int StoreMode, int LoadMode, typename Packet>
|
2015-10-07 15:44:12 +02:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacket(Index index) {
|
2023-05-22 16:39:24 +00:00
|
|
|
m_functor.template assignPacket<StoreMode>(&m_dst.coeffRef(index), m_src.template packet<LoadMode, Packet>(index));
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2023-05-22 16:39:24 +00:00
|
|
|
template <int StoreMode, int LoadMode, typename Packet>
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void assignPacketByOuterInner(Index outer, Index inner) {
|
2020-12-07 08:27:03 -08:00
|
|
|
Index row = rowIndexByOuterInner(outer, inner);
|
2013-11-07 12:03:12 +01:00
|
|
|
Index col = colIndexByOuterInner(outer, inner);
|
2023-05-22 16:39:24 +00:00
|
|
|
assignPacket<StoreMode, LoadMode, Packet>(row, col);
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index rowIndexByOuterInner(Index outer, Index inner) {
|
2013-11-07 12:03:12 +01:00
|
|
|
typedef typename DstEvaluatorType::ExpressionTraits Traits;
|
2013-11-06 18:17:59 +01:00
|
|
|
return int(Traits::RowsAtCompileTime) == 1 ? 0
|
|
|
|
|
: int(Traits::ColsAtCompileTime) == 1 ? inner
|
2014-03-12 13:34:11 +01:00
|
|
|
: int(DstEvaluatorType::Flags) & RowMajorBit ? outer
|
2013-11-06 18:17:59 +01:00
|
|
|
: inner;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index colIndexByOuterInner(Index outer, Index inner) {
|
2013-11-07 12:03:12 +01:00
|
|
|
typedef typename DstEvaluatorType::ExpressionTraits Traits;
|
2013-11-06 18:17:59 +01:00
|
|
|
return int(Traits::ColsAtCompileTime) == 1 ? 0
|
|
|
|
|
: int(Traits::RowsAtCompileTime) == 1 ? inner
|
2014-03-12 13:34:11 +01:00
|
|
|
: int(DstEvaluatorType::Flags) & RowMajorBit ? inner
|
2013-11-06 18:17:59 +01:00
|
|
|
: outer;
|
|
|
|
|
}
|
2016-12-05 15:08:09 +01:00
|
|
|
|
|
|
|
|
EIGEN_DEVICE_FUNC const Scalar* dstDataPtr() const { return m_dstExpr.data(); }
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
protected:
|
|
|
|
|
DstEvaluatorType& m_dst;
|
|
|
|
|
const SrcEvaluatorType& m_src;
|
|
|
|
|
const Functor& m_functor;
|
|
|
|
|
// TODO find a way to avoid the needs of the original expression
|
|
|
|
|
DstXprType& m_dstExpr;
|
2013-11-06 18:17:59 +01:00
|
|
|
};
|
|
|
|
|
|
2018-10-12 15:20:21 +02:00
|
|
|
// Special kernel used when computing small products whose operands have dynamic dimensions. It ensures that the
|
|
|
|
|
// PacketSize used is no larger than 4, thereby increasing the chance that vectorized instructions will be used
|
|
|
|
|
// when computing the product.
|
|
|
|
|
|
|
|
|
|
template <typename DstEvaluatorTypeT, typename SrcEvaluatorTypeT, typename Functor>
|
|
|
|
|
class restricted_packet_dense_assignment_kernel
|
|
|
|
|
: public generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn> {
|
|
|
|
|
protected:
|
|
|
|
|
typedef generic_dense_assignment_kernel<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, BuiltIn> Base;
|
2023-11-29 11:12:48 +00:00
|
|
|
|
2018-10-12 15:20:21 +02:00
|
|
|
public:
|
|
|
|
|
typedef typename Base::Scalar Scalar;
|
|
|
|
|
typedef typename Base::DstXprType DstXprType;
|
2018-11-13 16:15:08 +01:00
|
|
|
typedef copy_using_evaluator_traits<DstEvaluatorTypeT, SrcEvaluatorTypeT, Functor, 4> AssignmentTraits;
|
|
|
|
|
typedef typename AssignmentTraits::PacketType PacketType;
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2018-10-12 15:20:21 +02:00
|
|
|
EIGEN_DEVICE_FUNC restricted_packet_dense_assignment_kernel(DstEvaluatorTypeT& dst, const SrcEvaluatorTypeT& src,
|
|
|
|
|
const Functor& func, DstXprType& dstExpr)
|
|
|
|
|
: Base(dst, src, func, dstExpr) {}
|
|
|
|
|
};
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-11-25 15:20:31 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
* Part 5 : Entry point for dense rectangular assignment
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
2017-01-23 22:06:08 +01:00
|
|
|
template <typename DstXprType, typename SrcXprType, typename Functor>
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize_if_allowed(DstXprType& dst, const SrcXprType& src,
|
|
|
|
|
const Functor& /*func*/) {
|
|
|
|
|
EIGEN_ONLY_USED_FOR_DEBUG(dst);
|
|
|
|
|
EIGEN_ONLY_USED_FOR_DEBUG(src);
|
|
|
|
|
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
2017-01-27 11:59:35 +01:00
|
|
|
}
|
2017-01-23 22:06:08 +01:00
|
|
|
|
|
|
|
|
template <typename DstXprType, typename SrcXprType, typename T1, typename T2>
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize_if_allowed(DstXprType& dst, const SrcXprType& src,
|
|
|
|
|
const internal::assign_op<T1, T2>& /*func*/) {
|
|
|
|
|
Index dstRows = src.rows();
|
|
|
|
|
Index dstCols = src.cols();
|
|
|
|
|
if (((dst.rows() != dstRows) || (dst.cols() != dstCols))) dst.resize(dstRows, dstCols);
|
|
|
|
|
eigen_assert(dst.rows() == dstRows && dst.cols() == dstCols);
|
2017-01-27 11:59:35 +01:00
|
|
|
}
|
2017-01-23 22:06:08 +01:00
|
|
|
|
2013-11-06 18:17:59 +01:00
|
|
|
template <typename DstXprType, typename SrcXprType, typename Functor>
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_dense_assignment_loop(DstXprType& dst,
|
|
|
|
|
const SrcXprType& src,
|
|
|
|
|
const Functor& func) {
|
2015-09-02 21:38:40 +02:00
|
|
|
typedef evaluator<DstXprType> DstEvaluatorType;
|
|
|
|
|
typedef evaluator<SrcXprType> SrcEvaluatorType;
|
2013-11-07 12:03:12 +01:00
|
|
|
|
|
|
|
|
SrcEvaluatorType srcEvaluator(src);
|
2016-10-26 22:50:41 +02:00
|
|
|
|
|
|
|
|
// NOTE To properly handle A = (A*A.transpose())/s with A rectangular,
|
|
|
|
|
// we need to resize the destination after the source evaluator has been created.
|
2017-01-23 22:06:08 +01:00
|
|
|
resize_if_allowed(dst, src, func);
|
2016-10-26 22:50:41 +02:00
|
|
|
|
|
|
|
|
DstEvaluatorType dstEvaluator(dst);
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
typedef generic_dense_assignment_kernel<DstEvaluatorType, SrcEvaluatorType, Functor> Kernel;
|
|
|
|
|
Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
|
2016-07-28 13:47:33 +02:00
|
|
|
|
2013-11-07 12:03:12 +01:00
|
|
|
dense_assignment_loop<Kernel>::run(kernel);
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename DstXprType, typename SrcXprType>
|
2016-10-26 22:50:41 +02:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_dense_assignment_loop(DstXprType& dst, const SrcXprType& src) {
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
call_dense_assignment_loop(dst, src, internal::assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>());
|
2013-11-06 18:17:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
2013-11-25 15:20:31 +01:00
|
|
|
* Part 6 : Generic assignment
|
2012-06-22 09:39:35 +02:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
2013-11-25 15:20:31 +01:00
|
|
|
// Based on the respective shapes of the destination and source,
|
|
|
|
|
// the class AssignmentKind determine the kind of assignment mechanism.
|
|
|
|
|
// AssignmentKind must define a Kind typedef.
|
2013-11-29 17:50:59 +01:00
|
|
|
template <typename DstShape, typename SrcShape>
|
|
|
|
|
struct AssignmentKind;
|
2012-06-29 13:54:09 +01:00
|
|
|
|
2018-03-11 10:01:44 -04:00
|
|
|
// Assignment kind defined in this file:
|
2013-12-02 14:05:34 +01:00
|
|
|
struct Dense2Dense {};
|
2014-06-25 17:23:52 +02:00
|
|
|
struct EigenBase2EigenBase {};
|
2012-06-29 13:54:09 +01:00
|
|
|
|
2014-06-25 17:23:52 +02:00
|
|
|
template <typename, typename>
|
|
|
|
|
struct AssignmentKind {
|
|
|
|
|
typedef EigenBase2EigenBase Kind;
|
|
|
|
|
};
|
2013-12-02 14:05:34 +01:00
|
|
|
template <>
|
|
|
|
|
struct AssignmentKind<DenseShape, DenseShape> {
|
|
|
|
|
typedef Dense2Dense Kind;
|
|
|
|
|
};
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-11-25 15:20:31 +01:00
|
|
|
// This is the main assignment class
|
|
|
|
|
template <typename DstXprType, typename SrcXprType, typename Functor,
|
2013-11-29 17:50:59 +01:00
|
|
|
typename Kind = typename AssignmentKind<typename evaluator_traits<DstXprType>::Shape,
|
|
|
|
|
typename evaluator_traits<SrcXprType>::Shape>::Kind,
|
2016-07-04 11:02:00 +02:00
|
|
|
typename EnableIf = void>
|
2013-11-25 15:20:31 +01:00
|
|
|
struct Assignment;
|
2012-06-29 13:24:04 +01:00
|
|
|
|
2016-01-09 08:30:38 +01:00
|
|
|
// The only purpose of this call_assignment() function is to deal with noalias() / "assume-aliasing" and automatic
|
|
|
|
|
// transposition. Indeed, I (Gael) think that this concept of "assume-aliasing" was a mistake, and it makes thing quite
|
|
|
|
|
// complicated. So this intermediate function removes everything related to "assume-aliasing" such that Assignment does
|
2013-11-25 15:20:31 +01:00
|
|
|
// not has to bother about these annoying details.
|
2013-11-06 18:17:59 +01:00
|
|
|
|
2014-02-17 16:11:55 +01:00
|
|
|
template <typename Dst, typename Src>
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(Dst& dst, const Src& src) {
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
call_assignment(dst, src, internal::assign_op<typename Dst::Scalar, typename Src::Scalar>());
|
2014-02-17 16:11:55 +01:00
|
|
|
}
|
|
|
|
|
template <typename Dst, typename Src>
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(const Dst& dst, const Src& src) {
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
call_assignment(dst, src, internal::assign_op<typename Dst::Scalar, typename Src::Scalar>());
|
2014-02-17 16:11:55 +01:00
|
|
|
}
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2016-01-09 08:30:38 +01:00
|
|
|
// Deal with "assume-aliasing"
|
2014-02-17 16:11:55 +01:00
|
|
|
template <typename Dst, typename Src, typename Func>
|
2022-09-09 03:41:45 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment(
|
2022-03-16 16:43:40 +00:00
|
|
|
Dst& dst, const Src& src, const Func& func, std::enable_if_t<evaluator_assume_aliasing<Src>::value, void*> = 0) {
|
2014-07-19 15:19:10 +02:00
|
|
|
typename plain_matrix_type<Src>::type tmp(src);
|
2014-02-18 10:53:14 +01:00
|
|
|
call_assignment_no_alias(dst, tmp, func);
|
2014-02-17 16:11:55 +01:00
|
|
|
}
|
|
|
|
|
|
2013-11-25 15:20:31 +01:00
|
|
|
template <typename Dst, typename Src, typename Func>
|
2022-09-16 21:14:29 +00:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(
|
2022-03-16 16:43:40 +00:00
|
|
|
Dst& dst, const Src& src, const Func& func, std::enable_if_t<!evaluator_assume_aliasing<Src>::value, void*> = 0) {
|
2014-02-18 10:53:14 +01:00
|
|
|
call_assignment_no_alias(dst, src, func);
|
2012-06-28 15:25:25 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-09 08:30:38 +01:00
|
|
|
// by-pass "assume-aliasing"
|
2014-02-18 10:53:14 +01:00
|
|
|
// When there is no aliasing, we require that 'dst' has been properly resized
|
2013-11-25 15:20:31 +01:00
|
|
|
template <typename Dst, template <typename> class StorageBase, typename Src, typename Func>
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment(NoAlias<Dst, StorageBase>& dst,
|
|
|
|
|
const Src& src, const Func& func) {
|
2014-02-18 10:53:14 +01:00
|
|
|
call_assignment_no_alias(dst.expression(), src, func);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Dst, typename Src, typename Func>
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias(Dst& dst, const Src& src,
|
|
|
|
|
const Func& func) {
|
2014-02-18 10:53:14 +01:00
|
|
|
enum {
|
2015-10-06 17:14:56 +02:00
|
|
|
NeedToTranspose = ((int(Dst::RowsAtCompileTime) == 1 && int(Src::ColsAtCompileTime) == 1) ||
|
|
|
|
|
(int(Dst::ColsAtCompileTime) == 1 && int(Src::RowsAtCompileTime) == 1)) &&
|
|
|
|
|
int(Dst::SizeAtCompileTime) != 1
|
2014-02-18 10:53:14 +01:00
|
|
|
};
|
2014-02-20 15:26:15 +01:00
|
|
|
|
2022-03-16 16:43:40 +00:00
|
|
|
typedef std::conditional_t<NeedToTranspose, Transpose<Dst>, Dst> ActualDstTypeCleaned;
|
|
|
|
|
typedef std::conditional_t<NeedToTranspose, Transpose<Dst>, Dst&> ActualDstType;
|
2014-02-18 10:53:14 +01:00
|
|
|
ActualDstType actualDst(dst);
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2014-02-19 16:30:17 +01:00
|
|
|
// TODO check whether this is the right place to perform these checks:
|
|
|
|
|
EIGEN_STATIC_ASSERT_LVALUE(Dst)
|
|
|
|
|
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned, Src)
|
2015-10-06 17:18:06 +02:00
|
|
|
EIGEN_CHECK_BINARY_COMPATIBILIY(Func, typename ActualDstTypeCleaned::Scalar, typename Src::Scalar);
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2014-02-18 10:53:14 +01:00
|
|
|
Assignment<ActualDstTypeCleaned, Src, Func>::run(actualDst, src, func);
|
2013-12-02 16:37:58 +01:00
|
|
|
}
|
2018-10-12 15:20:21 +02:00
|
|
|
|
|
|
|
|
template <typename Dst, typename Src, typename Func>
|
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_restricted_packet_assignment_no_alias(Dst& dst, const Src& src,
|
|
|
|
|
const Func& func) {
|
|
|
|
|
typedef evaluator<Dst> DstEvaluatorType;
|
|
|
|
|
typedef evaluator<Src> SrcEvaluatorType;
|
|
|
|
|
typedef restricted_packet_dense_assignment_kernel<DstEvaluatorType, SrcEvaluatorType, Func> Kernel;
|
|
|
|
|
|
|
|
|
|
EIGEN_STATIC_ASSERT_LVALUE(Dst)
|
|
|
|
|
EIGEN_CHECK_BINARY_COMPATIBILIY(Func, typename Dst::Scalar, typename Src::Scalar);
|
|
|
|
|
|
|
|
|
|
SrcEvaluatorType srcEvaluator(src);
|
|
|
|
|
resize_if_allowed(dst, src, func);
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2018-10-12 15:20:21 +02:00
|
|
|
DstEvaluatorType dstEvaluator(dst);
|
|
|
|
|
Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
|
|
|
|
|
|
|
|
|
|
dense_assignment_loop<Kernel>::run(kernel);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-21 15:22:08 +01:00
|
|
|
template <typename Dst, typename Src>
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias(Dst& dst, const Src& src) {
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
call_assignment_no_alias(dst, src, internal::assign_op<typename Dst::Scalar, typename Src::Scalar>());
|
2014-02-21 15:22:08 +01:00
|
|
|
}
|
2014-02-18 10:53:14 +01:00
|
|
|
|
2015-06-24 17:50:43 +02:00
|
|
|
template <typename Dst, typename Src, typename Func>
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias_no_transpose(Dst& dst,
|
|
|
|
|
const Src& src,
|
|
|
|
|
const Func& func) {
|
2015-06-24 17:50:43 +02:00
|
|
|
// TODO check whether this is the right place to perform these checks:
|
|
|
|
|
EIGEN_STATIC_ASSERT_LVALUE(Dst)
|
|
|
|
|
EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Dst, Src)
|
2016-10-26 22:50:41 +02:00
|
|
|
EIGEN_CHECK_BINARY_COMPATIBILIY(Func, typename Dst::Scalar, typename Src::Scalar);
|
|
|
|
|
|
2015-06-24 17:50:43 +02:00
|
|
|
Assignment<Dst, Src, Func>::run(dst, src, func);
|
|
|
|
|
}
|
|
|
|
|
template <typename Dst, typename Src>
|
2016-01-31 16:34:10 +01:00
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR void call_assignment_no_alias_no_transpose(Dst& dst,
|
|
|
|
|
const Src& src) {
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
call_assignment_no_alias_no_transpose(dst, src, internal::assign_op<typename Dst::Scalar, typename Src::Scalar>());
|
2015-06-24 17:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-13 17:18:26 +02:00
|
|
|
// forward declaration
|
2023-01-15 02:06:17 +00:00
|
|
|
template <typename Dst, typename Src>
|
|
|
|
|
EIGEN_DEVICE_FUNC void check_for_aliasing(const Dst& dst, const Src& src);
|
2014-09-14 19:06:08 +02:00
|
|
|
|
2013-11-25 15:20:31 +01:00
|
|
|
// Generic Dense to Dense assignment
|
2016-07-05 22:58:14 +02:00
|
|
|
// Note that the last template argument "Weak" is needed to make it possible to perform
|
|
|
|
|
// both partial specialization+SFINAE without ambiguous specialization
|
|
|
|
|
template <typename DstXprType, typename SrcXprType, typename Functor, typename Weak>
|
|
|
|
|
struct Assignment<DstXprType, SrcXprType, Functor, Dense2Dense, Weak> {
|
2016-04-11 15:06:20 +02:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src, const Functor& func) {
|
2014-09-14 19:06:08 +02:00
|
|
|
#ifndef EIGEN_NO_DEBUG
|
|
|
|
|
internal::check_for_aliasing(dst, src);
|
|
|
|
|
#endif
|
2020-12-07 08:27:03 -08:00
|
|
|
|
2013-11-25 15:20:31 +01:00
|
|
|
call_dense_assignment_loop(dst, src, func);
|
|
|
|
|
}
|
|
|
|
|
};
|
2012-06-22 09:39:35 +02:00
|
|
|
|
2024-12-14 14:25:04 +00:00
|
|
|
template <typename DstXprType, typename SrcPlainObject, typename Weak>
|
|
|
|
|
struct Assignment<DstXprType, CwiseNullaryOp<scalar_constant_op<typename DstXprType::Scalar>, SrcPlainObject>,
|
|
|
|
|
assign_op<typename DstXprType::Scalar, typename DstXprType::Scalar>, Dense2Dense, Weak> {
|
|
|
|
|
using Scalar = typename DstXprType::Scalar;
|
|
|
|
|
using NullaryOp = scalar_constant_op<Scalar>;
|
|
|
|
|
using SrcXprType = CwiseNullaryOp<NullaryOp, SrcPlainObject>;
|
|
|
|
|
using Functor = assign_op<Scalar, Scalar>;
|
|
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src,
|
|
|
|
|
const Functor& /*func*/) {
|
|
|
|
|
eigen_fill_impl<DstXprType>::run(dst, src);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename DstXprType, typename SrcPlainObject, typename Weak>
|
|
|
|
|
struct Assignment<DstXprType, CwiseNullaryOp<scalar_zero_op<typename DstXprType::Scalar>, SrcPlainObject>,
|
|
|
|
|
assign_op<typename DstXprType::Scalar, typename DstXprType::Scalar>, Dense2Dense, Weak> {
|
|
|
|
|
using Scalar = typename DstXprType::Scalar;
|
|
|
|
|
using NullaryOp = scalar_zero_op<Scalar>;
|
|
|
|
|
using SrcXprType = CwiseNullaryOp<NullaryOp, SrcPlainObject>;
|
|
|
|
|
using Functor = assign_op<Scalar, Scalar>;
|
|
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(DstXprType& dst, const SrcXprType& src,
|
|
|
|
|
const Functor& /*func*/) {
|
|
|
|
|
eigen_zero_impl<DstXprType>::run(dst, src);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-25 17:23:52 +02:00
|
|
|
// Generic assignment through evalTo.
|
|
|
|
|
// TODO: not sure we have to keep that one, but it helps porting current code to new evaluator mechanism.
|
2016-07-05 22:58:14 +02:00
|
|
|
// Note that the last template argument "Weak" is needed to make it possible to perform
|
|
|
|
|
// both partial specialization+SFINAE without ambiguous specialization
|
|
|
|
|
template <typename DstXprType, typename SrcXprType, typename Functor, typename Weak>
|
|
|
|
|
struct Assignment<DstXprType, SrcXprType, Functor, EigenBase2EigenBase, Weak> {
|
Relax mixing-type constraints for binary coefficient-wise operators:
- Replace internal::scalar_product_traits<A,B> by Eigen::ScalarBinaryOpTraits<A,B,OP>
- Remove the "functor_is_product_like" helper (was pretty ugly)
- Currently, OP is not used, but it is available to the user for fine grained tuning
- Currently, only the following operators have been generalized: *,/,+,-,=,*=,/=,+=,-=
- TODO: generalize all other binray operators (comparisons,pow,etc.)
- TODO: handle "scalar op array" operators (currently only * is handled)
- TODO: move the handling of the "void" scalar type to ScalarBinaryOpTraits
2016-06-06 15:11:41 +02:00
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(
|
|
|
|
|
DstXprType& dst, const SrcXprType& src,
|
|
|
|
|
const internal::assign_op<typename DstXprType::Scalar, typename SrcXprType::Scalar>& /*func*/) {
|
2016-10-26 22:50:41 +02:00
|
|
|
Index dstRows = src.rows();
|
|
|
|
|
Index dstCols = src.cols();
|
|
|
|
|
if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
|
|
|
|
|
|
2014-06-25 17:23:52 +02:00
|
|
|
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
|
|
|
|
src.evalTo(dst);
|
|
|
|
|
}
|
2016-11-18 10:17:34 +01:00
|
|
|
|
2018-03-11 10:01:44 -04:00
|
|
|
// NOTE The following two functions are templated to avoid their instantiation if not needed
|
2016-11-20 09:41:37 +01:00
|
|
|
// This is needed because some expressions supports evalTo only and/or have 'void' as scalar type.
|
|
|
|
|
template <typename SrcScalarType>
|
|
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(
|
|
|
|
|
DstXprType& dst, const SrcXprType& src,
|
|
|
|
|
const internal::add_assign_op<typename DstXprType::Scalar, SrcScalarType>& /*func*/) {
|
2016-11-18 10:17:34 +01:00
|
|
|
Index dstRows = src.rows();
|
|
|
|
|
Index dstCols = src.cols();
|
|
|
|
|
if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
|
|
|
|
|
|
|
|
|
|
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
|
|
|
|
src.addTo(dst);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-20 09:41:37 +01:00
|
|
|
template <typename SrcScalarType>
|
|
|
|
|
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(
|
|
|
|
|
DstXprType& dst, const SrcXprType& src,
|
|
|
|
|
const internal::sub_assign_op<typename DstXprType::Scalar, SrcScalarType>& /*func*/) {
|
2016-11-18 10:17:34 +01:00
|
|
|
Index dstRows = src.rows();
|
|
|
|
|
Index dstCols = src.cols();
|
|
|
|
|
if ((dst.rows() != dstRows) || (dst.cols() != dstCols)) dst.resize(dstRows, dstCols);
|
|
|
|
|
|
|
|
|
|
eigen_assert(dst.rows() == src.rows() && dst.cols() == src.cols());
|
|
|
|
|
src.subTo(dst);
|
|
|
|
|
}
|
2014-06-25 17:23:52 +02:00
|
|
|
};
|
|
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
} // namespace internal
|
|
|
|
|
|
2012-06-22 16:35:20 +02:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2012-06-22 09:39:35 +02:00
|
|
|
#endif // EIGEN_ASSIGN_EVALUATOR_H
|