Skip to content
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

Support for single-precision computations #363

Merged
merged 35 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
877d36e
Add support for float to the expression API.
bluescarni Nov 17, 2023
51b7a60
Add support for single precision in the SLEEF machinery.
bluescarni Nov 18, 2023
35cbfc9
Instantiate add_cfunc() for float.
bluescarni Nov 18, 2023
2c0d058
Single-precision testing for sin.
bluescarni Nov 18, 2023
deb9bc7
Attempt parallel build on Windows CI.
bluescarni Nov 18, 2023
bfe9c19
clang-tidy fix.
bluescarni Nov 18, 2023
ca1aea5
Single-precision testing for sinh().
bluescarni Nov 18, 2023
7870e25
Add support for float in recommended_simd_size().
bluescarni Nov 18, 2023
531ab16
Enable several Taylor-related specialisations for float.
bluescarni Nov 18, 2023
c734e75
Add a couple more explicit instantiations for float.
bluescarni Nov 18, 2023
e66980b
Enable single precision on a couple of Taylor jet tests.
bluescarni Nov 18, 2023
11c2406
Relax tolerance on test.
bluescarni Nov 18, 2023
1bf4edc
More missing specialisations for float.
bluescarni Nov 18, 2023
482ada3
Initial usages of float in the taylor adaptive tests.
bluescarni Nov 18, 2023
78b474f
Fix clang warning in test.
bluescarni Nov 18, 2023
fb12a31
More test fixes.
bluescarni Nov 18, 2023
0b1dfe4
Testing for cos and cosh.
bluescarni Nov 18, 2023
9da1fdd
Actually do the test.
bluescarni Nov 18, 2023
252b3c8
Enable single precision in the event tests and slightly adapt the code.
bluescarni Nov 19, 2023
c412b33
Enable float overloads in atan2().
bluescarni Nov 19, 2023
f20abea
Enable single-precision in more tests.
bluescarni Nov 19, 2023
c3e810f
Instantiate the ensemble_propagate() functions for single precision.
bluescarni Nov 19, 2023
540a2af
Another chunk of testing enablement.
bluescarni Nov 19, 2023
d2ee94d
Test fixes for autovec.
bluescarni Nov 19, 2023
8f20021
Try taking away the fmt pins in the CI.
bluescarni Nov 19, 2023
ef89618
Again test fixes.
bluescarni Nov 19, 2023
e8c3127
More progress on testing.
bluescarni Nov 19, 2023
cd29458
Another batch of test additions.
bluescarni Nov 19, 2023
f165a07
A first chunk of Taylor jet testing.
bluescarni Nov 19, 2023
6edd8e6
Finish up the Taylor testing.
bluescarni Nov 19, 2023
4f01e41
Add float overloads to multivariate functions in the expression system.
bluescarni Nov 19, 2023
55de116
Improved testing for expression ops with numbers, do constant folding…
bluescarni Nov 20, 2023
1c4dc37
Testing for the multivariate functions overloads.
bluescarni Nov 20, 2023
4ce3afb
Update changelog and docs for single-precision support.
bluescarni Nov 20, 2023
5d4a830
Small doc tweak.
bluescarni Nov 20, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/gha_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
mkdir build
cd build
cmake ../ -G "Visual Studio 16 2019" -A x64 -DHEYOKA_BUILD_TESTS=yes -DHEYOKA_WITH_MPPP=yes -DHEYOKA_BUILD_TUTORIALS=ON -DHEYOKA_ENABLE_IPO=yes -DBoost_NO_BOOST_CMAKE=ON -DHEYOKA_WITH_SLEEF=yes -DMPPP_GMP_INCLUDE_DIR=C:\Miniconda\envs\test\Library\include -DMPPP_GMP_LIBRARY=C:\Miniconda\envs\test\Library\lib\mpir.lib
cmake --build . --config Release
cmake --build . --config Release -j2
copy Release\heyoka.dll test\Release\
ctest -j4 -V -C Release
windows_2019_llvm13:
Expand All @@ -60,7 +60,7 @@ jobs:
mkdir build
cd build
cmake ../ -G "Visual Studio 16 2019" -A x64 -DHEYOKA_BUILD_TESTS=yes -DHEYOKA_WITH_MPPP=yes -DHEYOKA_BUILD_TUTORIALS=ON -DHEYOKA_ENABLE_IPO=yes -DBoost_NO_BOOST_CMAKE=ON -DHEYOKA_WITH_SLEEF=yes -DMPPP_GMP_INCLUDE_DIR=C:\Miniconda\envs\test\Library\include -DMPPP_GMP_LIBRARY=C:\Miniconda\envs\test\Library\lib\mpir.lib
cmake --build . --config Release
cmake --build . --config Release -j2
copy Release\heyoka.dll test\Release\
ctest -j4 -V -C Release
windows_2019_llvm14:
Expand All @@ -82,7 +82,7 @@ jobs:
mkdir build
cd build
cmake ../ -G "Visual Studio 16 2019" -A x64 -DHEYOKA_BUILD_TESTS=yes -DHEYOKA_WITH_MPPP=yes -DHEYOKA_BUILD_TUTORIALS=ON -DHEYOKA_ENABLE_IPO=yes -DBoost_NO_BOOST_CMAKE=ON -DHEYOKA_WITH_SLEEF=yes -DMPPP_GMP_INCLUDE_DIR=C:\Miniconda\envs\test\Library\include -DMPPP_GMP_LIBRARY=C:\Miniconda\envs\test\Library\lib\mpir.lib
cmake --build . --config Release
cmake --build . --config Release -j2
copy Release\heyoka.dll test\Release\
ctest -j4 -V -C Release
conda_release_static:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ heyoka is a C++ library for the integration of ordinary differential equations
(ODEs) via Taylor's method, based on automatic differentiation techniques and aggressive just-in-time
compilation via [LLVM](https://llvm.org/). Notable features include:

* support for double-precision, extended-precision (80-bit and 128-bit),
* support for single-precision, double-precision, extended-precision (80-bit and 128-bit),
and arbitrary-precision floating-point types,
* the ability to maintain machine precision accuracy over
tens of billions of timesteps,
Expand Down
2 changes: 2 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog
New
~~~

- Add support for single-precision computations
(`#363 <https://github.com/bluescarni/heyoka/pull/363>`__).
- Add model implementing the ELP2000 analytical lunar theory
(`#362 <https://github.com/bluescarni/heyoka/pull/362>`__).

Expand Down
4 changes: 2 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ heyoka is a C++ library for the integration of ordinary differential equations
on automatic differentiation techniques and aggressive just-in-time
compilation via `LLVM <https://llvm.org/>`__. Notable features include:

* support for double-precision, extended-precision (80-bit and 128-bit),
* support for single-precision, double-precision, extended-precision (80-bit and 128-bit),
and arbitrary-precision floating-point types,
* the ability to maintain machine precision accuracy over
tens of billions of timesteps,
Expand Down Expand Up @@ -110,7 +110,7 @@ license. The authors are Francesco Biscani and
Dario Izzo (European Space Agency).

.. toctree::
:maxdepth: 2
:maxdepth: 1

install.rst
basic_tutorials.rst
Expand Down
5 changes: 3 additions & 2 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ installing from source (the minimum required version is 3.18).
Support for extended precision
``````````````````````````````

Whereas in heyoka double-precision computations are always supported, support for extended-precision
Whereas in heyoka single-precision and double-precision computations are always supported via the
``float`` and ``double`` types respectively, support for extended-precision
computations varies depending on the software/hardware platform.

80-bit precision
Expand All @@ -81,7 +82,7 @@ heyoka (and all its dependencies) have been compiled with a compiler supporting
^^^^^^^^^^^^^^^^^

On platforms where ``long double`` is a quadruple-precision floating-point datatype (e.g., 64-bit ARM),
quadruple-precision integrations are always supported. Otherwise,
quadruple-precision integrations are always supported via ``long double``. Otherwise,
on platforms such as x86-64, quadruple-precision computations are supported if:

* the nonstandard ``__float128`` floating-point type is
Expand Down
2 changes: 1 addition & 1 deletion doc/tut_extended_precision.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Computations in extended precision
==================================

As hinted in the :ref:`installation instructions <ep_support>`, heyoka supports computations
not only in double precision, but also in extended precision. Specifically, heyoka currently supports:
not only in single and double precision, but also in extended precision. Specifically, heyoka currently supports:

* the 80-bit IEEE `extended-precision format <https://en.wikipedia.org/wiki/Extended_precision>`__ (~21 decimal digits),
* the 128-bit IEEE `quadruple-precision format <https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format>`__ (~36 decimal digits).
Expand Down
3 changes: 3 additions & 0 deletions include/heyoka/detail/event_detection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ inline T taylor_deduce_cooldown(T, T)
static_assert(always_false_v<T>, "Unhandled type");
}

template <>
float taylor_deduce_cooldown(float, float);

template <>
double taylor_deduce_cooldown(double, double);

Expand Down
4 changes: 4 additions & 0 deletions include/heyoka/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ template <typename>
struct is_supported_fp : std::false_type {
};

template <>
struct is_supported_fp<float> : std::true_type {
};

template <>
struct is_supported_fp<double> : std::true_type {
};
Expand Down
16 changes: 16 additions & 0 deletions include/heyoka/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class HEYOKA_DLL_PUBLIC expression
public:
expression();

explicit expression(float);
explicit expression(double);
explicit expression(long double);
#if defined(HEYOKA_HAVE_REAL128)
Expand Down Expand Up @@ -125,6 +126,9 @@ HEYOKA_DLL_PUBLIC bool is_fixed(const expression &);
inline namespace literals
{

HEYOKA_DLL_PUBLIC expression operator""_flt(long double);
HEYOKA_DLL_PUBLIC expression operator""_flt(unsigned long long);

HEYOKA_DLL_PUBLIC expression operator""_dbl(long double);
HEYOKA_DLL_PUBLIC expression operator""_dbl(unsigned long long);

Expand Down Expand Up @@ -257,6 +261,7 @@ HEYOKA_DLL_PUBLIC expression operator+(expression);
HEYOKA_DLL_PUBLIC expression operator-(const expression &);

HEYOKA_DLL_PUBLIC expression operator+(const expression &, const expression &);
HEYOKA_DLL_PUBLIC expression operator+(const expression &, float);
HEYOKA_DLL_PUBLIC expression operator+(const expression &, double);
HEYOKA_DLL_PUBLIC expression operator+(const expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -265,6 +270,7 @@ HEYOKA_DLL_PUBLIC expression operator+(const expression &, mppp::real128);
#if defined(HEYOKA_HAVE_REAL)
HEYOKA_DLL_PUBLIC expression operator+(const expression &, mppp::real);
#endif
HEYOKA_DLL_PUBLIC expression operator+(float, const expression &);
HEYOKA_DLL_PUBLIC expression operator+(double, const expression &);
HEYOKA_DLL_PUBLIC expression operator+(long double, const expression &);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -276,13 +282,15 @@ HEYOKA_DLL_PUBLIC expression operator+(mppp::real, const expression &);

HEYOKA_DLL_PUBLIC expression operator-(const expression &, const expression &);
HEYOKA_DLL_PUBLIC expression operator-(const expression &, double);
HEYOKA_DLL_PUBLIC expression operator-(const expression &, float);
HEYOKA_DLL_PUBLIC expression operator-(const expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
HEYOKA_DLL_PUBLIC expression operator-(const expression &, mppp::real128);
#endif
#if defined(HEYOKA_HAVE_REAL)
HEYOKA_DLL_PUBLIC expression operator-(const expression &, mppp::real);
#endif
HEYOKA_DLL_PUBLIC expression operator-(float, const expression &);
HEYOKA_DLL_PUBLIC expression operator-(double, const expression &);
HEYOKA_DLL_PUBLIC expression operator-(long double, const expression &);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -294,13 +302,15 @@ HEYOKA_DLL_PUBLIC expression operator-(mppp::real, const expression &);

HEYOKA_DLL_PUBLIC expression operator*(const expression &, const expression &);
HEYOKA_DLL_PUBLIC expression operator*(const expression &, double);
HEYOKA_DLL_PUBLIC expression operator*(const expression &, float);
HEYOKA_DLL_PUBLIC expression operator*(const expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
HEYOKA_DLL_PUBLIC expression operator*(const expression &, mppp::real128);
#endif
#if defined(HEYOKA_HAVE_REAL)
HEYOKA_DLL_PUBLIC expression operator*(const expression &, mppp::real);
#endif
HEYOKA_DLL_PUBLIC expression operator*(float, const expression &);
HEYOKA_DLL_PUBLIC expression operator*(double, const expression &);
HEYOKA_DLL_PUBLIC expression operator*(long double, const expression &);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -311,6 +321,7 @@ HEYOKA_DLL_PUBLIC expression operator*(mppp::real, const expression &);
#endif

HEYOKA_DLL_PUBLIC expression operator/(const expression &, const expression &);
HEYOKA_DLL_PUBLIC expression operator/(const expression &, float);
HEYOKA_DLL_PUBLIC expression operator/(const expression &, double);
HEYOKA_DLL_PUBLIC expression operator/(const expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -319,6 +330,7 @@ HEYOKA_DLL_PUBLIC expression operator/(const expression &, mppp::real128);
#if defined(HEYOKA_HAVE_REAL)
HEYOKA_DLL_PUBLIC expression operator/(const expression &, mppp::real);
#endif
HEYOKA_DLL_PUBLIC expression operator/(float, const expression &);
HEYOKA_DLL_PUBLIC expression operator/(double, const expression &);
HEYOKA_DLL_PUBLIC expression operator/(long double, const expression &);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -329,6 +341,7 @@ HEYOKA_DLL_PUBLIC expression operator/(mppp::real, const expression &);
#endif

HEYOKA_DLL_PUBLIC expression &operator+=(expression &, const expression &);
HEYOKA_DLL_PUBLIC expression &operator+=(expression &, float);
HEYOKA_DLL_PUBLIC expression &operator+=(expression &, double);
HEYOKA_DLL_PUBLIC expression &operator+=(expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -339,6 +352,7 @@ HEYOKA_DLL_PUBLIC expression &operator+=(expression &, mppp::real);
#endif

HEYOKA_DLL_PUBLIC expression &operator-=(expression &, const expression &);
HEYOKA_DLL_PUBLIC expression &operator-=(expression &, float);
HEYOKA_DLL_PUBLIC expression &operator-=(expression &, double);
HEYOKA_DLL_PUBLIC expression &operator-=(expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -349,6 +363,7 @@ HEYOKA_DLL_PUBLIC expression &operator-=(expression &, mppp::real);
#endif

HEYOKA_DLL_PUBLIC expression &operator*=(expression &, const expression &);
HEYOKA_DLL_PUBLIC expression &operator*=(expression &, float);
HEYOKA_DLL_PUBLIC expression &operator*=(expression &, double);
HEYOKA_DLL_PUBLIC expression &operator*=(expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
Expand All @@ -359,6 +374,7 @@ HEYOKA_DLL_PUBLIC expression &operator*=(expression &, mppp::real);
#endif

HEYOKA_DLL_PUBLIC expression &operator/=(expression &, const expression &);
HEYOKA_DLL_PUBLIC expression &operator/=(expression &, float);
HEYOKA_DLL_PUBLIC expression &operator/=(expression &, double);
HEYOKA_DLL_PUBLIC expression &operator/=(expression &, long double);
#if defined(HEYOKA_HAVE_REAL128)
Expand Down
4 changes: 4 additions & 0 deletions include/heyoka/llvm_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct target_features {
bool vsx = false;
bool vsx3 = false;
// Recommended SIMD sizes.
std::uint32_t simd_size_flt = 1;
std::uint32_t simd_size_dbl = 1;
std::uint32_t simd_size_ldbl = 1;
#if defined(HEYOKA_HAVE_REAL128)
Expand Down Expand Up @@ -99,6 +100,9 @@ inline std::uint32_t recommended_simd_size()
return 0;
}

template <>
HEYOKA_DLL_PUBLIC std::uint32_t recommended_simd_size<float>();

template <>
HEYOKA_DLL_PUBLIC std::uint32_t recommended_simd_size<double>();

Expand Down
2 changes: 2 additions & 0 deletions include/heyoka/math/atan2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class HEYOKA_DLL_PUBLIC atan2_impl : public func_base

HEYOKA_DLL_PUBLIC expression atan2(expression, expression);

HEYOKA_DLL_PUBLIC expression atan2(expression, float);
HEYOKA_DLL_PUBLIC expression atan2(expression, double);
HEYOKA_DLL_PUBLIC expression atan2(expression, long double);

Expand All @@ -90,6 +91,7 @@ HEYOKA_DLL_PUBLIC expression atan2(expression, mppp::real);

#endif

HEYOKA_DLL_PUBLIC expression atan2(float, expression);
HEYOKA_DLL_PUBLIC expression atan2(double, expression);
HEYOKA_DLL_PUBLIC expression atan2(long double, expression);

Expand Down
1 change: 1 addition & 0 deletions include/heyoka/math/kepDE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ HEYOKA_DLL_PUBLIC expression kepDE(expression, expression, expression);
HEYOKA_DLL_PUBLIC expression kepDE(expression, type, expression); \
HEYOKA_DLL_PUBLIC expression kepDE(type, expression, expression)

HEYOKA_DECLARE_KEPDE_OVERLOADS(float);
HEYOKA_DECLARE_KEPDE_OVERLOADS(double);
HEYOKA_DECLARE_KEPDE_OVERLOADS(long double);

Expand Down
1 change: 1 addition & 0 deletions include/heyoka/math/kepE.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ HEYOKA_DLL_PUBLIC expression kepE(expression, expression);
HEYOKA_DLL_PUBLIC expression kepE(expression, type); \
HEYOKA_DLL_PUBLIC expression kepE(type, expression);

HEYOKA_DECLARE_KEPE_OVERLOADS(float);
HEYOKA_DECLARE_KEPE_OVERLOADS(double);
HEYOKA_DECLARE_KEPE_OVERLOADS(long double);

Expand Down
1 change: 1 addition & 0 deletions include/heyoka/math/kepF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ HEYOKA_DLL_PUBLIC expression kepF(expression, expression, expression);
HEYOKA_DLL_PUBLIC expression kepF(expression, type, expression); \
HEYOKA_DLL_PUBLIC expression kepF(type, expression, expression)

HEYOKA_DECLARE_KEPF_OVERLOADS(float);
HEYOKA_DECLARE_KEPF_OVERLOADS(double);
HEYOKA_DECLARE_KEPF_OVERLOADS(long double);

Expand Down
1 change: 1 addition & 0 deletions include/heyoka/math/pow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pow_eval_algo get_pow_eval_algo(const pow_impl &);
} // namespace detail

HEYOKA_DLL_PUBLIC expression pow(expression, expression);
HEYOKA_DLL_PUBLIC expression pow(expression, float);
HEYOKA_DLL_PUBLIC expression pow(expression, double);
HEYOKA_DLL_PUBLIC expression pow(expression, long double);

Expand Down
10 changes: 8 additions & 2 deletions include/heyoka/step_callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct HEYOKA_DLL_PUBLIC_INLINE_CLASS step_callback_inner final : step_callback_
void serialize(Archive &ar, unsigned)
{
ar &boost::serialization::base_object<step_callback_inner_base<TA>>(*this);
ar &m_value;
ar & m_value;
}
};

Expand All @@ -135,7 +135,7 @@ class HEYOKA_DLL_PUBLIC step_callback_impl
template <typename Archive>
void serialize(Archive &ar, unsigned)
{
ar &m_ptr;
ar & m_ptr;
}

// Meta-programming for the generic ctor.
Expand Down Expand Up @@ -226,6 +226,9 @@ using step_callback_batch = detail::step_callback_impl<taylor_adaptive_batch<T>>
HEYOKA_END_NAMESPACE

// Disable Boost.Serialization tracking for the implementation details of step_callback.
BOOST_CLASS_TRACKING(heyoka::detail::step_callback_inner_base<heyoka::taylor_adaptive<float>>,
boost::serialization::track_never)

BOOST_CLASS_TRACKING(heyoka::detail::step_callback_inner_base<heyoka::taylor_adaptive<double>>,
boost::serialization::track_never)

Expand All @@ -246,6 +249,9 @@ BOOST_CLASS_TRACKING(heyoka::detail::step_callback_inner_base<heyoka::taylor_ada

#endif

BOOST_CLASS_TRACKING(heyoka::detail::step_callback_inner_base<heyoka::taylor_adaptive_batch<float>>,
boost::serialization::track_never)

BOOST_CLASS_TRACKING(heyoka::detail::step_callback_inner_base<heyoka::taylor_adaptive_batch<double>>,
boost::serialization::track_never)

Expand Down
Loading
Loading