1// This file is part of Eigen, a lightweight C++ template library 2// for linear algebra. 3// 4// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> 5// Copyright (C) 2007-2011 Benoit Jacob <jacob.benoit.1@gmail.com> 6// 7// This Source Code Form is subject to the terms of the Mozilla 8// Public License v. 2.0. If a copy of the MPL was not distributed 9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 10 11#ifndef EIGEN_CORE_H 12#define EIGEN_CORE_H 13 14#define Eigen itkeigen 15 16// first thing Eigen does: stop the compiler from committing suicide 17#include "src/Core/util/DisableStupidWarnings.h" 18 19#if defined(__CUDACC__) && !defined(EIGEN_NO_CUDA) 20 #define EIGEN_CUDACC __CUDACC__ 21#endif 22 23#if defined(__CUDA_ARCH__) && !defined(EIGEN_NO_CUDA) 24 #define EIGEN_CUDA_ARCH __CUDA_ARCH__ 25#endif 26 27#if defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ >= 9) 28#define EIGEN_CUDACC_VER ((__CUDACC_VER_MAJOR__ * 10000) + (__CUDACC_VER_MINOR__ * 100)) 29#elif defined(__CUDACC_VER__) 30#define EIGEN_CUDACC_VER __CUDACC_VER__ 31#else 32#define EIGEN_CUDACC_VER 0 33#endif 34 35// Handle NVCC/CUDA/SYCL 36#if defined(__CUDACC__) || defined(__SYCL_DEVICE_ONLY__) 37 // Do not try asserts on CUDA and SYCL! 38 #ifndef EIGEN_NO_DEBUG 39 #define EIGEN_NO_DEBUG 40 #endif 41 42 #ifdef EIGEN_INTERNAL_DEBUGGING 43 #undef EIGEN_INTERNAL_DEBUGGING 44 #endif 45 46 #ifdef EIGEN_EXCEPTIONS 47 #undef EIGEN_EXCEPTIONS 48 #endif 49 50 // All functions callable from CUDA code must be qualified with __device__ 51 #ifdef __CUDACC__ 52 // Do not try to vectorize on CUDA and SYCL! 53 #ifndef EIGEN_DONT_VECTORIZE 54 #define EIGEN_DONT_VECTORIZE 55 #endif 56 57 #define EIGEN_DEVICE_FUNC __host__ __device__ 58 // We need cuda_runtime.h to ensure that that EIGEN_USING_STD_MATH macro 59 // works properly on the device side 60 #include <cuda_runtime.h> 61 #else 62 #define EIGEN_DEVICE_FUNC 63 #endif 64 65#else 66 #define EIGEN_DEVICE_FUNC 67 68#endif 69 70// When compiling CUDA device code with NVCC, pull in math functions from the 71// global namespace. In host mode, and when device doee with clang, use the 72// std versions. 73#if defined(__CUDA_ARCH__) && defined(__NVCC__) 74 #define EIGEN_USING_STD_MATH(FUNC) using ::FUNC; 75#else 76 #define EIGEN_USING_STD_MATH(FUNC) using std::FUNC; 77#endif 78 79#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) && !defined(EIGEN_EXCEPTIONS) && !defined(EIGEN_USE_SYCL) 80 #define EIGEN_EXCEPTIONS 81#endif 82 83#ifdef EIGEN_EXCEPTIONS 84 #include <new> 85#endif 86 87// then include this file where all our macros are defined. It's really important to do it first because 88// it's where we do all the alignment settings (platform detection and honoring the user's will if he 89// defined e.g. EIGEN_DONT_ALIGN) so it needs to be done before we do anything with vectorization. 90#include "src/Core/util/Macros.h" 91 92// Disable the ipa-cp-clone optimization flag with MinGW 6.x or newer (enabled by default with -O3) 93// See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=556 for details. 94#if EIGEN_COMP_MINGW && EIGEN_GNUC_AT_LEAST(4,6) 95 #pragma GCC optimize ("-fno-ipa-cp-clone") 96#endif 97 98#include <complex> 99 100// this include file manages BLAS and MKL related macros 101// and inclusion of their respective header files 102#include "src/Core/util/MKL_support.h" 103 104// if alignment is disabled, then disable vectorization. Note: EIGEN_MAX_ALIGN_BYTES is the proper check, it takes into 105// account both the user's will (EIGEN_MAX_ALIGN_BYTES,EIGEN_DONT_ALIGN) and our own platform checks 106#if EIGEN_MAX_ALIGN_BYTES==0 107 #ifndef EIGEN_DONT_VECTORIZE 108 #define EIGEN_DONT_VECTORIZE 109 #endif 110#endif 111 112#if EIGEN_COMP_MSVC 113 #include <malloc.h> // for _aligned_malloc -- need it regardless of whether vectorization is enabled 114 #if (EIGEN_COMP_MSVC >= 1500) // 2008 or later 115 // Remember that usage of defined() in a #define is undefined by the standard. 116 // a user reported that in 64-bit mode, MSVC doesn't care to define _M_IX86_FP. 117 #if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || EIGEN_ARCH_x86_64 118 #define EIGEN_SSE2_ON_MSVC_2008_OR_LATER 119 #endif 120 #endif 121#else 122 // Remember that usage of defined() in a #define is undefined by the standard 123 #if (defined __SSE2__) && ( (!EIGEN_COMP_GNUC) || EIGEN_COMP_ICC || EIGEN_GNUC_AT_LEAST(4,2) ) 124 #define EIGEN_SSE2_ON_NON_MSVC_BUT_NOT_OLD_GCC 125 #endif 126#endif 127 128#ifndef EIGEN_DONT_VECTORIZE 129 130 #if defined (EIGEN_SSE2_ON_NON_MSVC_BUT_NOT_OLD_GCC) || defined(EIGEN_SSE2_ON_MSVC_2008_OR_LATER) 131 132 // Defines symbols for compile-time detection of which instructions are 133 // used. 134 // EIGEN_VECTORIZE_YY is defined if and only if the instruction set YY is used 135 #define EIGEN_VECTORIZE 136 #define EIGEN_VECTORIZE_SSE 137 #define EIGEN_VECTORIZE_SSE2 138 139 // Detect sse3/ssse3/sse4: 140 // gcc and icc defines __SSE3__, ... 141 // there is no way to know about this on msvc. You can define EIGEN_VECTORIZE_SSE* if you 142 // want to force the use of those instructions with msvc. 143 #ifdef __SSE3__ 144 #define EIGEN_VECTORIZE_SSE3 145 #endif 146 #ifdef __SSSE3__ 147 #define EIGEN_VECTORIZE_SSSE3 148 #endif 149 #ifdef __SSE4_1__ 150 #define EIGEN_VECTORIZE_SSE4_1 151 #endif 152 #ifdef __SSE4_2__ 153 #define EIGEN_VECTORIZE_SSE4_2 154 #endif 155 #ifdef __AVX__ 156 #define EIGEN_VECTORIZE_AVX 157 #define EIGEN_VECTORIZE_SSE3 158 #define EIGEN_VECTORIZE_SSSE3 159 #define EIGEN_VECTORIZE_SSE4_1 160 #define EIGEN_VECTORIZE_SSE4_2 161 #endif 162 #ifdef __AVX2__ 163 #define EIGEN_VECTORIZE_AVX2 164 #endif 165 #ifdef __FMA__ 166 #define EIGEN_VECTORIZE_FMA 167 #endif 168 #if defined(__AVX512F__) && defined(EIGEN_ENABLE_AVX512) 169 #define EIGEN_VECTORIZE_AVX512 170 #define EIGEN_VECTORIZE_AVX2 171 #define EIGEN_VECTORIZE_AVX 172 #define EIGEN_VECTORIZE_FMA 173 #ifdef __AVX512DQ__ 174 #define EIGEN_VECTORIZE_AVX512DQ 175 #endif 176 #ifdef __AVX512ER__ 177 #define EIGEN_VECTORIZE_AVX512ER 178 #endif 179 #endif 180 181 // include files 182 183 // This extern "C" works around a MINGW-w64 compilation issue 184 // https://sourceforge.net/tracker/index.php?func=detail&aid=3018394&group_id=202880&atid=983354 185 // In essence, intrin.h is included by windows.h and also declares intrinsics (just as emmintrin.h etc. below do). 186 // However, intrin.h uses an extern "C" declaration, and g++ thus complains of duplicate declarations 187 // with conflicting linkage. The linkage for intrinsics doesn't matter, but at that stage the compiler doesn't know; 188 // so, to avoid compile errors when windows.h is included after Eigen/Core, ensure intrinsics are extern "C" here too. 189 // notice that since these are C headers, the extern "C" is theoretically needed anyways. 190 extern "C" { 191 // In theory we should only include immintrin.h and not the other *mmintrin.h header files directly. 192 // Doing so triggers some issues with ICC. However old gcc versions seems to not have this file, thus: 193 #if EIGEN_COMP_ICC >= 1110 194 #include <immintrin.h> 195 #else 196 #include <mmintrin.h> 197 #include <emmintrin.h> 198 #include <xmmintrin.h> 199 #ifdef EIGEN_VECTORIZE_SSE3 200 #include <pmmintrin.h> 201 #endif 202 #ifdef EIGEN_VECTORIZE_SSSE3 203 #include <tmmintrin.h> 204 #endif 205 #ifdef EIGEN_VECTORIZE_SSE4_1 206 #include <smmintrin.h> 207 #endif 208 #ifdef EIGEN_VECTORIZE_SSE4_2 209 #include <nmmintrin.h> 210 #endif 211 #if defined(EIGEN_VECTORIZE_AVX) || defined(EIGEN_VECTORIZE_AVX512) 212 #include <immintrin.h> 213 #endif 214 #endif 215 } // end extern "C" 216 #elif defined __VSX__ 217 #define EIGEN_VECTORIZE 218 #define EIGEN_VECTORIZE_VSX 219 #include <altivec.h> 220 // We need to #undef all these ugly tokens defined in <altivec.h> 221 // => use __vector instead of vector 222 #undef bool 223 #undef vector 224 #undef pixel 225 #elif defined __ALTIVEC__ 226 #define EIGEN_VECTORIZE 227 #define EIGEN_VECTORIZE_ALTIVEC 228 #include <altivec.h> 229 // We need to #undef all these ugly tokens defined in <altivec.h> 230 // => use __vector instead of vector 231 #undef bool 232 #undef vector 233 #undef pixel 234 #elif (defined __ARM_NEON) || (defined __ARM_NEON__) 235 #define EIGEN_VECTORIZE 236 #define EIGEN_VECTORIZE_NEON 237 #include <arm_neon.h> 238 #elif (defined __s390x__ && defined __VEC__) 239 #define EIGEN_VECTORIZE 240 #define EIGEN_VECTORIZE_ZVECTOR 241 #include <vecintrin.h> 242 #endif 243#endif 244 245#if defined(__F16C__) && !defined(EIGEN_COMP_CLANG) 246 // We can use the optimized fp16 to float and float to fp16 conversion routines 247 #define EIGEN_HAS_FP16_C 248#endif 249 250#if defined __CUDACC__ 251 #define EIGEN_VECTORIZE_CUDA 252 #include <vector_types.h> 253 #if EIGEN_CUDACC_VER >= 70500 254 #define EIGEN_HAS_CUDA_FP16 255 #endif 256#endif 257 258#if defined EIGEN_HAS_CUDA_FP16 259 #include <host_defines.h> 260 #include <cuda_fp16.h> 261#endif 262 263#if (defined _OPENMP) && (!defined EIGEN_DONT_PARALLELIZE) 264 #define EIGEN_HAS_OPENMP 265#endif 266 267#ifdef EIGEN_HAS_OPENMP 268#include <omp.h> 269#endif 270 271// MSVC for windows mobile does not have the errno.h file 272#if !(EIGEN_COMP_MSVC && EIGEN_OS_WINCE) && !EIGEN_COMP_ARM 273#define EIGEN_HAS_ERRNO 274#endif 275 276#ifdef EIGEN_HAS_ERRNO 277#include <cerrno> 278#endif 279#include <cstddef> 280#include <cstdlib> 281#include <cmath> 282#include <cassert> 283#include <functional> 284#include <iosfwd> 285#include <cstring> 286#include <string> 287#include <limits> 288#include <climits> // for CHAR_BIT 289// for min/max: 290#include <algorithm> 291 292// for std::is_nothrow_move_assignable 293#ifdef EIGEN_INCLUDE_TYPE_TRAITS 294#include <type_traits> 295#endif 296 297// for outputting debug info 298#ifdef EIGEN_DEBUG_ASSIGN 299#include <iostream> 300#endif 301 302// required for __cpuid, needs to be included after cmath 303#if EIGEN_COMP_MSVC && EIGEN_ARCH_i386_OR_x86_64 && !EIGEN_OS_WINCE 304 #include <intrin.h> 305#endif 306 307/** \brief Namespace containing all symbols from the %Eigen library. */ 308namespace Eigen { 309 310inline static const char *SimdInstructionSetsInUse(void) { 311#if defined(EIGEN_VECTORIZE_AVX512) 312 return "AVX512, FMA, AVX2, AVX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2"; 313#elif defined(EIGEN_VECTORIZE_AVX) 314 return "AVX SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2"; 315#elif defined(EIGEN_VECTORIZE_SSE4_2) 316 return "SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2"; 317#elif defined(EIGEN_VECTORIZE_SSE4_1) 318 return "SSE, SSE2, SSE3, SSSE3, SSE4.1"; 319#elif defined(EIGEN_VECTORIZE_SSSE3) 320 return "SSE, SSE2, SSE3, SSSE3"; 321#elif defined(EIGEN_VECTORIZE_SSE3) 322 return "SSE, SSE2, SSE3"; 323#elif defined(EIGEN_VECTORIZE_SSE2) 324 return "SSE, SSE2"; 325#elif defined(EIGEN_VECTORIZE_ALTIVEC) 326 return "AltiVec"; 327#elif defined(EIGEN_VECTORIZE_VSX) 328 return "VSX"; 329#elif defined(EIGEN_VECTORIZE_NEON) 330 return "ARM NEON"; 331#elif defined(EIGEN_VECTORIZE_ZVECTOR) 332 return "S390X ZVECTOR"; 333#else 334 return "None"; 335#endif 336} 337 338} // end namespace Eigen 339 340#if defined EIGEN2_SUPPORT_STAGE40_FULL_EIGEN3_STRICTNESS || defined EIGEN2_SUPPORT_STAGE30_FULL_EIGEN3_API || defined EIGEN2_SUPPORT_STAGE20_RESOLVE_API_CONFLICTS || defined EIGEN2_SUPPORT_STAGE10_FULL_EIGEN2_API || defined EIGEN2_SUPPORT 341// This will generate an error message: 342#error Eigen2-support is only available up to version 3.2. Please go to "http://eigen.tuxfamily.org/index.php?title=Eigen2" for further information 343#endif 344 345namespace Eigen { 346 347// we use size_t frequently and we'll never remember to prepend it with std:: everytime just to 348// ensure QNX/QCC support 349using std::size_t; 350// gcc 4.6.0 wants std:: for ptrdiff_t 351using std::ptrdiff_t; 352 353} 354 355/** \defgroup Core_Module Core module 356 * This is the main module of Eigen providing dense matrix and vector support 357 * (both fixed and dynamic size) with all the features corresponding to a BLAS library 358 * and much more... 359 * 360 * \code 361 * #include <Eigen/Core> 362 * \endcode 363 */ 364 365#include "src/Core/util/Constants.h" 366#include "src/Core/util/Meta.h" 367#include "src/Core/util/ForwardDeclarations.h" 368#include "src/Core/util/StaticAssert.h" 369#include "src/Core/util/XprHelper.h" 370#include "src/Core/util/Memory.h" 371 372#include "src/Core/NumTraits.h" 373#include "src/Core/MathFunctions.h" 374#include "src/Core/GenericPacketMath.h" 375#include "src/Core/MathFunctionsImpl.h" 376#include "src/Core/arch/Default/ConjHelper.h" 377 378#if defined EIGEN_VECTORIZE_AVX512 379 #include "src/Core/arch/SSE/PacketMath.h" 380 #include "src/Core/arch/AVX/PacketMath.h" 381 #include "src/Core/arch/AVX512/PacketMath.h" 382 #include "src/Core/arch/AVX512/MathFunctions.h" 383#elif defined EIGEN_VECTORIZE_AVX 384 // Use AVX for floats and doubles, SSE for integers 385 #include "src/Core/arch/SSE/PacketMath.h" 386 #include "src/Core/arch/SSE/Complex.h" 387 #include "src/Core/arch/SSE/MathFunctions.h" 388 #include "src/Core/arch/AVX/PacketMath.h" 389 #include "src/Core/arch/AVX/MathFunctions.h" 390 #include "src/Core/arch/AVX/Complex.h" 391 #include "src/Core/arch/AVX/TypeCasting.h" 392 #include "src/Core/arch/SSE/TypeCasting.h" 393#elif defined EIGEN_VECTORIZE_SSE 394 #include "src/Core/arch/SSE/PacketMath.h" 395 #include "src/Core/arch/SSE/MathFunctions.h" 396 #include "src/Core/arch/SSE/Complex.h" 397 #include "src/Core/arch/SSE/TypeCasting.h" 398#elif defined(EIGEN_VECTORIZE_ALTIVEC) || defined(EIGEN_VECTORIZE_VSX) 399 #include "src/Core/arch/AltiVec/PacketMath.h" 400 #include "src/Core/arch/AltiVec/MathFunctions.h" 401 #include "src/Core/arch/AltiVec/Complex.h" 402#elif defined EIGEN_VECTORIZE_NEON 403 #include "src/Core/arch/NEON/PacketMath.h" 404 #include "src/Core/arch/NEON/MathFunctions.h" 405 #include "src/Core/arch/NEON/Complex.h" 406#elif defined EIGEN_VECTORIZE_ZVECTOR 407 #include "src/Core/arch/ZVector/PacketMath.h" 408 #include "src/Core/arch/ZVector/MathFunctions.h" 409 #include "src/Core/arch/ZVector/Complex.h" 410#endif 411 412// Half float support 413#include "src/Core/arch/CUDA/Half.h" 414#include "src/Core/arch/CUDA/PacketMathHalf.h" 415#include "src/Core/arch/CUDA/TypeCasting.h" 416 417#if defined EIGEN_VECTORIZE_CUDA 418 #include "src/Core/arch/CUDA/PacketMath.h" 419 #include "src/Core/arch/CUDA/MathFunctions.h" 420#endif 421 422#include "src/Core/arch/Default/Settings.h" 423 424#include "src/Core/functors/TernaryFunctors.h" 425#include "src/Core/functors/BinaryFunctors.h" 426#include "src/Core/functors/UnaryFunctors.h" 427#include "src/Core/functors/NullaryFunctors.h" 428#include "src/Core/functors/StlFunctors.h" 429#include "src/Core/functors/AssignmentFunctors.h" 430 431// Specialized functors to enable the processing of complex numbers 432// on CUDA devices 433#include "src/Core/arch/CUDA/Complex.h" 434 435#include "src/Core/IO.h" 436#include "src/Core/DenseCoeffsBase.h" 437#include "src/Core/DenseBase.h" 438#include "src/Core/MatrixBase.h" 439#include "src/Core/EigenBase.h" 440 441#include "src/Core/Product.h" 442#include "src/Core/CoreEvaluators.h" 443#include "src/Core/AssignEvaluator.h" 444 445#ifndef EIGEN_PARSED_BY_DOXYGEN // work around Doxygen bug triggered by Assign.h r814874 446 // at least confirmed with Doxygen 1.5.5 and 1.5.6 447 #include "src/Core/Assign.h" 448#endif 449 450#include "src/Core/ArrayBase.h" 451#include "src/Core/util/BlasUtil.h" 452#include "src/Core/DenseStorage.h" 453#include "src/Core/NestByValue.h" 454 455// #include "src/Core/ForceAlignedAccess.h" 456 457#include "src/Core/ReturnByValue.h" 458#include "src/Core/NoAlias.h" 459#include "src/Core/PlainObjectBase.h" 460#include "src/Core/Matrix.h" 461#include "src/Core/Array.h" 462#include "src/Core/CwiseTernaryOp.h" 463#include "src/Core/CwiseBinaryOp.h" 464#include "src/Core/CwiseUnaryOp.h" 465#include "src/Core/CwiseNullaryOp.h" 466#include "src/Core/CwiseUnaryView.h" 467#include "src/Core/SelfCwiseBinaryOp.h" 468#include "src/Core/Dot.h" 469#include "src/Core/StableNorm.h" 470#include "src/Core/Stride.h" 471#include "src/Core/MapBase.h" 472#include "src/Core/Map.h" 473#include "src/Core/Ref.h" 474#include "src/Core/Block.h" 475#include "src/Core/VectorBlock.h" 476#include "src/Core/Transpose.h" 477#include "src/Core/DiagonalMatrix.h" 478#include "src/Core/Diagonal.h" 479#include "src/Core/DiagonalProduct.h" 480#include "src/Core/Redux.h" 481#include "src/Core/Visitor.h" 482#include "src/Core/Fuzzy.h" 483#include "src/Core/Swap.h" 484#include "src/Core/CommaInitializer.h" 485#include "src/Core/GeneralProduct.h" 486#include "src/Core/Solve.h" 487#include "src/Core/Inverse.h" 488#include "src/Core/SolverBase.h" 489#include "src/Core/PermutationMatrix.h" 490#include "src/Core/Transpositions.h" 491#include "src/Core/TriangularMatrix.h" 492#include "src/Core/SelfAdjointView.h" 493#include "src/Core/products/GeneralBlockPanelKernel.h" 494#include "src/Core/products/Parallelizer.h" 495#include "src/Core/ProductEvaluators.h" 496#include "src/Core/products/GeneralMatrixVector.h" 497#include "src/Core/products/GeneralMatrixMatrix.h" 498#include "src/Core/SolveTriangular.h" 499#include "src/Core/products/GeneralMatrixMatrixTriangular.h" 500#include "src/Core/products/SelfadjointMatrixVector.h" 501#include "src/Core/products/SelfadjointMatrixMatrix.h" 502#include "src/Core/products/SelfadjointProduct.h" 503#include "src/Core/products/SelfadjointRank2Update.h" 504#include "src/Core/products/TriangularMatrixVector.h" 505#include "src/Core/products/TriangularMatrixMatrix.h" 506#include "src/Core/products/TriangularSolverMatrix.h" 507#include "src/Core/products/TriangularSolverVector.h" 508#include "src/Core/BandMatrix.h" 509#include "src/Core/CoreIterators.h" 510#include "src/Core/ConditionEstimator.h" 511 512#include "src/Core/BooleanRedux.h" 513#include "src/Core/Select.h" 514#include "src/Core/VectorwiseOp.h" 515#include "src/Core/Random.h" 516#include "src/Core/Replicate.h" 517#include "src/Core/Reverse.h" 518#include "src/Core/ArrayWrapper.h" 519 520#ifdef EIGEN_USE_BLAS 521#include "src/Core/products/GeneralMatrixMatrix_BLAS.h" 522#include "src/Core/products/GeneralMatrixVector_BLAS.h" 523#include "src/Core/products/GeneralMatrixMatrixTriangular_BLAS.h" 524#include "src/Core/products/SelfadjointMatrixMatrix_BLAS.h" 525#include "src/Core/products/SelfadjointMatrixVector_BLAS.h" 526#include "src/Core/products/TriangularMatrixMatrix_BLAS.h" 527#include "src/Core/products/TriangularMatrixVector_BLAS.h" 528#include "src/Core/products/TriangularSolverMatrix_BLAS.h" 529#endif // EIGEN_USE_BLAS 530 531#ifdef EIGEN_USE_MKL_VML 532#include "src/Core/Assign_MKL.h" 533#endif 534 535#include "src/Core/GlobalFunctions.h" 536 537#include "src/Core/util/ReenableStupidWarnings.h" 538 539#endif // EIGEN_CORE_H 540