Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Version 2.1 development #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d214a48
Add benchmark files and exclude from the repo for now
ikorotkin Dec 10, 2024
b36cec5
Update autodiff to v1.1.2
ikorotkin Dec 10, 2024
351e4c3
Update Eigen to the max possible version (commit d26e from 28 Mar 202…
ikorotkin Dec 10, 2024
70c3247
Update gtest to 1.15.2
ikorotkin Dec 10, 2024
9fff106
Add new vector function and Jacobian classes for automatic differenti…
ikorotkin Dec 15, 2024
5252c3f
Update version to 2.1.0
ikorotkin Dec 15, 2024
da98ac4
Add jacobian_matrix_shape example
ikorotkin Dec 15, 2024
bf135a1
Update jacobian_matrix_shape example
ikorotkin Dec 15, 2024
456a2fb
Update jacobian_matrix_shape example - move Jacobian shape definition…
ikorotkin Dec 16, 2024
592c263
Reserve memory for automatic Jacobian derived from the user-defined s…
ikorotkin Dec 16, 2024
3abdce1
Add references to the example
ikorotkin Dec 16, 2024
26b141d
Fix Windows compiler warning
ikorotkin Dec 16, 2024
f3e93c1
Add Jacobian matrix shape integration test
ikorotkin Dec 16, 2024
00593c5
Add inline because the functions are defined in a header
ikorotkin Dec 16, 2024
5f25e20
Remove unused variable
ikorotkin Dec 16, 2024
b0a9e41
Reserve memory for array of non-zero elements
ikorotkin Dec 16, 2024
9be6d75
Update output
ikorotkin Dec 17, 2024
55bdc49
Added helper class that compares user-defined Jacobian with automatic…
ikorotkin Dec 17, 2024
ea54f56
Update JacobianCompare class
ikorotkin Dec 17, 2024
0fa77eb
Add JacobianCompare to jacobian_matrix_shape example
ikorotkin Dec 17, 2024
799d9b5
Add JacobianCompare to the integration tests
ikorotkin Dec 17, 2024
4bdb936
Rename VectorFunctionJacobianShape to VectorFunctionElements
ikorotkin Dec 18, 2024
72d138c
Rename jacobian_shape example
ikorotkin Dec 18, 2024
d74f46d
Add jacobian_compare example
ikorotkin Dec 18, 2024
a842a17
Add jacobian-compare test
ikorotkin Dec 18, 2024
06593f6
Add VectorFunctionElements class test
ikorotkin Dec 18, 2024
e17a7ec
Fix warnings
ikorotkin Dec 18, 2024
b3f1489
Add jacobian-shape tests
ikorotkin Dec 18, 2024
cd0d2b1
Update jacobian-shape test
ikorotkin Dec 19, 2024
701969c
Update README
ikorotkin Dec 19, 2024
cac01aa
Fix typos in comments, remove unused variables
ikorotkin Dec 20, 2024
b33cd72
Time derivative optimisations
ikorotkin Dec 20, 2024
d22775d
Fix warnings in tests
ikorotkin Dec 20, 2024
0bc2057
Remove inline from the class method definitions
ikorotkin Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Executables and builds
build/
benchmark/
*.exe

# VS Code files
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)

######## Build examples ########

set(EXAMPLE_LIST "quick_start" "simple_dae" "perovskite_model" "flame_propagation")
set(EXAMPLE_LIST "quick_start" "simple_dae" "perovskite_model" "flame_propagation" "jacobian_shape" "jacobian_compare")

include_directories(${PROJECT_SOURCE_DIR})

Expand All @@ -28,7 +28,7 @@ set(PROJECT_TEST "dae-cpp-test")
include(CTest)
enable_testing()

FILE(GLOB SOURCES_TEST ${PROJECT_SOURCE_DIR}/tests/*.cpp)
FILE(GLOB SOURCES_TEST ${PROJECT_SOURCE_DIR}/tests/test_*.cpp)

add_executable(${PROJECT_TEST} ${SOURCES_TEST})

Expand Down
2 changes: 0 additions & 2 deletions Eigen/CholmodSupport
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

#include "src/Core/util/DisableStupidWarnings.h"

extern "C" {
#include <cholmod.h>
}

/** \ingroup Support_modules
* \defgroup CholmodSupport_Module CholmodSupport module
Expand Down
11 changes: 6 additions & 5 deletions Eigen/src/Core/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class Matrix : public PlainObjectBase<Matrix<Scalar_, Rows_, Cols_, Options_, Ma
*
* \callgraph
*/
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(const Matrix& other) { return Base::_set(other); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix& operator=(const Matrix& other) { return Base::_set(other); }

/** \internal
* \brief Copies the value of the expression \a other into \c *this with automatic resizing.
Expand Down Expand Up @@ -250,17 +250,18 @@ class Matrix : public PlainObjectBase<Matrix<Scalar_, Rows_, Cols_, Options_, Ma
*
* \sa resize(Index,Index)
*/
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix()
: Base(){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED}

// FIXME is it still needed
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit Matrix(internal::constructor_without_unaligned_array_assert)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr explicit Matrix(
internal::constructor_without_unaligned_array_assert)
: Base(internal::constructor_without_unaligned_array_assert()){EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED}

EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix(Matrix && other)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix(Matrix && other)
EIGEN_NOEXCEPT_IF(std::is_nothrow_move_constructible<Scalar>::value)
: Base(std::move(other)) {}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Matrix& operator=(Matrix&& other)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Matrix& operator=(Matrix&& other)
EIGEN_NOEXCEPT_IF(std::is_nothrow_move_assignable<Scalar>::value) {
Base::operator=(std::move(other));
return *this;
Expand Down
19 changes: 11 additions & 8 deletions Eigen/src/Core/PlainObjectBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
/** This is a special case of the templated operator=. Its purpose is to
* prevent a default operator= from hiding the templated operator=.
*/
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(const PlainObjectBase& other) { return _set(other); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Derived& operator=(const PlainObjectBase& other) {
return _set(other);
}

/** \sa MatrixBase::lazyAssign() */
template <typename OtherDerived>
Expand All @@ -470,28 +472,29 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
// Prevent user from trying to instantiate PlainObjectBase objects
// by making all its constructor protected. See bug 1074.
protected:
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase() : m_storage() {
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr PlainObjectBase() : m_storage() {
// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
}

#ifndef EIGEN_PARSED_BY_DOXYGEN
// FIXME is it still needed ?
/** \internal */
EIGEN_DEVICE_FUNC explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert)
EIGEN_DEVICE_FUNC constexpr explicit PlainObjectBase(internal::constructor_without_unaligned_array_assert)
: m_storage(internal::constructor_without_unaligned_array_assert()) {
// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
}
#endif

EIGEN_DEVICE_FUNC PlainObjectBase(PlainObjectBase&& other) EIGEN_NOEXCEPT : m_storage(std::move(other.m_storage)) {}
EIGEN_DEVICE_FUNC constexpr PlainObjectBase(PlainObjectBase&& other) EIGEN_NOEXCEPT
: m_storage(std::move(other.m_storage)) {}

EIGEN_DEVICE_FUNC PlainObjectBase& operator=(PlainObjectBase&& other) EIGEN_NOEXCEPT {
EIGEN_DEVICE_FUNC constexpr PlainObjectBase& operator=(PlainObjectBase&& other) EIGEN_NOEXCEPT {
m_storage = std::move(other.m_storage);
return *this;
}

/** Copy constructor */
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(const PlainObjectBase& other)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr PlainObjectBase(const PlainObjectBase& other)
: Base(), m_storage(other.m_storage) {}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PlainObjectBase(Index size, Index rows, Index cols)
: m_storage(size, rows, cols) {
Expand Down Expand Up @@ -749,7 +752,7 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
// aliasing is dealt once in internal::call_assignment
// so at this stage we have to assume aliasing... and resising has to be done later.
template <typename OtherDerived>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& _set(const DenseBase<OtherDerived>& other) {
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Derived& _set(const DenseBase<OtherDerived>& other) {
internal::call_assignment(this->derived(), other.derived());
return this->derived();
}
Expand All @@ -760,7 +763,7 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
* \sa operator=(const MatrixBase<OtherDerived>&), _set()
*/
template <typename OtherDerived>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& _set_noalias(const DenseBase<OtherDerived>& other) {
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr Derived& _set_noalias(const DenseBase<OtherDerived>& other) {
// I don't think we need this resize call since the lazyAssign will anyways resize
// and lazyAssign will be called by the assign selector.
//_resize_to_match(other);
Expand Down
31 changes: 15 additions & 16 deletions Eigen/src/Core/arch/AVX/PacketMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ struct packet_traits<uint32_t> : default_packet_traits {
template <>
struct packet_traits<int64_t> : default_packet_traits {
typedef Packet4l type;
// There is no half-size packet for current Packet4l.
// TODO: support as SSE path.
typedef Packet4l half;
typedef Packet2l half;
enum { Vectorizable = 1, AlignedOnScalar = 1, HasCmp = 1, size = 4 };
};
template <>
Expand Down Expand Up @@ -332,6 +330,7 @@ template <>
struct unpacket_traits<Packet4d> {
typedef double type;
typedef Packet2d half;
typedef Packet4l integer_packet;
enum {
size = 4,
alignment = Aligned32,
Expand Down Expand Up @@ -368,7 +367,7 @@ struct unpacket_traits<Packet8ui> {
template <>
struct unpacket_traits<Packet4l> {
typedef int64_t type;
typedef Packet4l half;
typedef Packet2l half;
enum {
size = 4,
alignment = Aligned32,
Expand Down Expand Up @@ -623,22 +622,22 @@ EIGEN_DEVICE_FUNC inline Packet4ul pgather<uint64_t, Packet4ul>(const uint64_t*
template <>
EIGEN_DEVICE_FUNC inline void pscatter<int64_t, Packet4l>(int64_t* to, const Packet4l& from, Index stride) {
__m128i low = _mm256_extractf128_si256(from, 0);
to[stride * 0] = _mm_extract_epi64(low, 0);
to[stride * 1] = _mm_extract_epi64(low, 1);
to[stride * 0] = _mm_extract_epi64_0(low);
to[stride * 1] = _mm_extract_epi64_1(low);

__m128i high = _mm256_extractf128_si256(from, 1);
to[stride * 2] = _mm_extract_epi64(high, 0);
to[stride * 3] = _mm_extract_epi64(high, 1);
to[stride * 2] = _mm_extract_epi64_0(high);
to[stride * 3] = _mm_extract_epi64_1(high);
}
template <>
EIGEN_DEVICE_FUNC inline void pscatter<uint64_t, Packet4ul>(uint64_t* to, const Packet4ul& from, Index stride) {
__m128i low = _mm256_extractf128_si256(from, 0);
to[stride * 0] = _mm_extract_epi64(low, 0);
to[stride * 1] = _mm_extract_epi64(low, 1);
to[stride * 0] = _mm_extract_epi64_0(low);
to[stride * 1] = _mm_extract_epi64_1(low);

__m128i high = _mm256_extractf128_si256(from, 1);
to[stride * 2] = _mm_extract_epi64(high, 0);
to[stride * 3] = _mm_extract_epi64(high, 1);
to[stride * 2] = _mm_extract_epi64_0(high);
to[stride * 3] = _mm_extract_epi64_1(high);
}
template <>
EIGEN_STRONG_INLINE void pstore1<Packet4l>(int64_t* to, const int64_t& a) {
Expand All @@ -652,21 +651,21 @@ EIGEN_STRONG_INLINE void pstore1<Packet4ul>(uint64_t* to, const uint64_t& a) {
}
template <>
EIGEN_STRONG_INLINE int64_t pfirst<Packet4l>(const Packet4l& a) {
return _mm_cvtsi128_si64(_mm256_castsi256_si128(a));
return _mm_extract_epi64_0(_mm256_castsi256_si128(a));
}
template <>
EIGEN_STRONG_INLINE uint64_t pfirst<Packet4ul>(const Packet4ul& a) {
return _mm_cvtsi128_si64(_mm256_castsi256_si128(a));
return _mm_extract_epi64_0(_mm256_castsi256_si128(a));
}
template <>
EIGEN_STRONG_INLINE int64_t predux<Packet4l>(const Packet4l& a) {
__m128i r = _mm_add_epi64(_mm256_castsi256_si128(a), _mm256_extractf128_si256(a, 1));
return _mm_extract_epi64(r, 0) + _mm_extract_epi64(r, 1);
return _mm_extract_epi64_0(r) + _mm_extract_epi64_1(r);
}
template <>
EIGEN_STRONG_INLINE uint64_t predux<Packet4ul>(const Packet4ul& a) {
__m128i r = _mm_add_epi64(_mm256_castsi256_si128(a), _mm256_extractf128_si256(a, 1));
return numext::bit_cast<uint64_t>(_mm_extract_epi64(r, 0) + _mm_extract_epi64(r, 1));
return numext::bit_cast<uint64_t>(_mm_extract_epi64_0(r) + _mm_extract_epi64_1(r));
}
#define MM256_SHUFFLE_EPI64(A, B, M) _mm256_shuffle_pd(_mm256_castsi256_pd(A), _mm256_castsi256_pd(B), M)
EIGEN_DEVICE_FUNC inline void ptranspose(PacketBlock<Packet4l, 4>& kernel) {
Expand Down
51 changes: 51 additions & 0 deletions Eigen/src/Core/arch/AVX/TypeCasting.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ template <>
struct type_casting_traits<bfloat16, float> : vectorized_type_casting_traits<bfloat16, float> {};
template <>
struct type_casting_traits<float, bfloat16> : vectorized_type_casting_traits<float, bfloat16> {};

#ifdef EIGEN_VECTORIZE_AVX2
template <>
struct type_casting_traits<double, int64_t> : vectorized_type_casting_traits<double, int64_t> {};
template <>
struct type_casting_traits<int64_t, double> : vectorized_type_casting_traits<int64_t, double> {};
#endif
#endif

template <>
Expand Down Expand Up @@ -188,6 +195,35 @@ EIGEN_STRONG_INLINE Packet4ui preinterpret<Packet4ui, Packet8ui>(const Packet8ui
}

#ifdef EIGEN_VECTORIZE_AVX2
template <>
EIGEN_STRONG_INLINE Packet4l pcast<Packet4d, Packet4l>(const Packet4d& a) {
#if defined(EIGEN_VECTORIZE_AVX512DQ) && defined(EIGEN_VECTORIZE_AVS512VL)
return _mm256_cvttpd_epi64(a);
#else
EIGEN_ALIGN16 double aux[4];
pstore(aux, a);
return _mm256_set_epi64x(static_cast<int64_t>(aux[3]), static_cast<int64_t>(aux[2]), static_cast<int64_t>(aux[1]),
static_cast<int64_t>(aux[0]));
#endif
}

template <>
EIGEN_STRONG_INLINE Packet4d pcast<Packet4l, Packet4d>(const Packet4l& a) {
#if defined(EIGEN_VECTORIZE_AVX512DQ) && defined(EIGEN_VECTORIZE_AVS512VL)
return _mm256_cvtepi64_pd(a);
#else
EIGEN_ALIGN16 int64_t aux[4];
pstore(aux, a);
return _mm256_set_pd(static_cast<double>(aux[3]), static_cast<double>(aux[2]), static_cast<double>(aux[1]),
static_cast<double>(aux[0]));
#endif
}

template <>
EIGEN_STRONG_INLINE Packet4d pcast<Packet2l, Packet4d>(const Packet2l& a, const Packet2l& b) {
return _mm256_set_m128d((pcast<Packet2l, Packet2d>(b)), (pcast<Packet2l, Packet2d>(a)));
}

template <>
EIGEN_STRONG_INLINE Packet4ul preinterpret<Packet4ul, Packet4l>(const Packet4l& a) {
return Packet4ul(a);
Expand All @@ -198,6 +234,21 @@ EIGEN_STRONG_INLINE Packet4l preinterpret<Packet4l, Packet4ul>(const Packet4ul&
return Packet4l(a);
}

template <>
EIGEN_STRONG_INLINE Packet4l preinterpret<Packet4l, Packet4d>(const Packet4d& a) {
return _mm256_castpd_si256(a);
}

template <>
EIGEN_STRONG_INLINE Packet4d preinterpret<Packet4d, Packet4l>(const Packet4l& a) {
return _mm256_castsi256_pd(a);
}

// truncation operations
template <>
EIGEN_STRONG_INLINE Packet2l preinterpret<Packet2l, Packet4l>(const Packet4l& a) {
return _mm256_castsi256_si128(a);
}
#endif

template <>
Expand Down
1 change: 1 addition & 0 deletions Eigen/src/Core/arch/AVX512/PacketMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace internal {
typedef __m512 Packet16f;
typedef __m512i Packet16i;
typedef __m512d Packet8d;
// TODO(rmlarsen): Add support for Packet8l.
#ifndef EIGEN_VECTORIZE_AVX512FP16
typedef eigen_packet_wrapper<__m256i, 1> Packet16h;
#endif
Expand Down
27 changes: 24 additions & 3 deletions Eigen/src/Core/arch/SSE/PacketMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ EIGEN_STRONG_INLINE Packet2d vec2d_unpackhi(const Packet2d& a, const Packet2d& b

#define EIGEN_DECLARE_CONST_Packet4ui(NAME, X) const Packet4ui p4ui_##NAME = pset1<Packet4ui>(X)

// Work around lack of extract/cvt for epi64 when compiling for 32-bit.
#if EIGEN_ARCH_x86_64
EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_0(const __m128i& a) { return _mm_cvtsi128_si64(a); }
#ifdef EIGEN_VECTORIZE_SSE4_1
EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_1(const __m128i& a) { return _mm_extract_epi64(a, 1); }
#else
EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_1(const __m128i& a) {
return _mm_cvtsi128_si64(_mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(a), _mm_castsi128_pd(a), 0x1)));
}
#endif
#else
// epi64 instructions are not available. The following seems to generate the same instructions
// with -O2 in GCC/Clang.
EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_0(const __m128i& a) {
return numext::bit_cast<int64_t>(_mm_cvtsd_f64(_mm_castsi128_pd(a)));
}
EIGEN_ALWAYS_INLINE int64_t _mm_extract_epi64_1(const __m128i& a) {
return numext::bit_cast<int64_t>(_mm_cvtsd_f64(_mm_shuffle_pd(_mm_castsi128_pd(a), _mm_castsi128_pd(a), 0x1)));
}
#endif

// Use the packet_traits defined in AVX/PacketMath.h instead if we're going
// to leverage AVX instructions.
#ifndef EIGEN_VECTORIZE_AVX
Expand Down Expand Up @@ -1610,7 +1631,7 @@ EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) {
}
template <>
EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(const Packet2l& a) {
int64_t x = _mm_cvtsi128_si64(a);
int64_t x = _mm_extract_epi64_0(a);
return x;
}
template <>
Expand All @@ -1637,7 +1658,7 @@ EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) {
}
template <>
EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(const Packet2l& a) {
int64_t x = _mm_cvtsi128_si64(a);
int64_t x = _mm_extract_epi64_0(a);
return x;
}
template <>
Expand All @@ -1661,7 +1682,7 @@ EIGEN_STRONG_INLINE double pfirst<Packet2d>(const Packet2d& a) {
}
template <>
EIGEN_STRONG_INLINE int64_t pfirst<Packet2l>(const Packet2l& a) {
return _mm_cvtsi128_si64(a);
return _mm_extract_epi64_0(a);
}
template <>
EIGEN_STRONG_INLINE int pfirst<Packet4i>(const Packet4i& a) {
Expand Down
Loading
Loading