Skip to content

Commit

Permalink
Merge pull request #363 from bluescarni/pr/single_prec
Browse files Browse the repository at this point in the history
Support for single-precision computations
  • Loading branch information
bluescarni authored Nov 20, 2023
2 parents 22e2873 + 5d4a830 commit b4e152a
Show file tree
Hide file tree
Showing 120 changed files with 2,934 additions and 1,115 deletions.
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

0 comments on commit b4e152a

Please sign in to comment.