Skip to content

Commit

Permalink
Merge pull request #1178 from boostorg/NVRTC_3
Browse files Browse the repository at this point in the history
NVRTC batch 3
  • Loading branch information
mborland authored Aug 14, 2024
2 parents 2d864f4 + beeef9b commit bc5dc9c
Show file tree
Hide file tree
Showing 25 changed files with 2,367 additions and 132 deletions.
5 changes: 3 additions & 2 deletions include/boost/math/distributions/bernoulli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <boost/math/distributions/fwd.hpp>
#include <boost/math/tools/config.hpp>
#include <boost/math/tools/tuple.hpp>
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/distributions/complement.hpp> // complements
#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
#include <boost/math/special_functions/fpclassify.hpp> // isnan.
Expand All @@ -57,12 +58,12 @@ namespace boost
return true;
}
template <class RealType, class Policy>
BOOST_MATH_GPU_ENABLED inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */, const std::true_type&)
BOOST_MATH_GPU_ENABLED inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */, const boost::math::true_type&)
{
return check_success_fraction(function, p, result, Policy());
}
template <class RealType, class Policy>
BOOST_MATH_GPU_ENABLED inline bool check_dist(const char* , const RealType& , RealType* , const Policy& /* pol */, const std::false_type&)
BOOST_MATH_GPU_ENABLED inline bool check_dist(const char* , const RealType& , RealType* , const Policy& /* pol */, const boost::math::false_type&)
{
return true;
}
Expand Down
119 changes: 58 additions & 61 deletions include/boost/math/policies/policy.hpp

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions include/boost/math/special_functions/beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <boost/math/special_functions/math_fwd.hpp>
#include <boost/math/tools/config.hpp>
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <boost/math/special_functions/binomial.hpp>
#include <boost/math/special_functions/factorials.hpp>
Expand Down Expand Up @@ -1569,7 +1570,7 @@ BOOST_MATH_GPU_ENABLED T ibeta_derivative_imp(T a, T b, T x, const Policy& pol)
//
template <class RT1, class RT2, class Policy>
BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<RT1, RT2>::type
beta(RT1 a, RT2 b, const Policy&, const std::true_type*)
beta(RT1 a, RT2 b, const Policy&, const boost::math::true_type*)
{
BOOST_FPU_EXCEPTION_GUARD
typedef typename tools::promote_args<RT1, RT2>::type result_type;
Expand All @@ -1586,7 +1587,7 @@ BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<RT1, RT2>::type
}
template <class RT1, class RT2, class RT3>
BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<RT1, RT2, RT3>::type
beta(RT1 a, RT2 b, RT3 x, const std::false_type*)
beta(RT1 a, RT2 b, RT3 x, const boost::math::false_type*)
{
return boost::math::beta(a, b, x, policies::policy<>());
}
Expand Down
39 changes: 38 additions & 1 deletion include/boost/math/special_functions/expm1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
#pragma once
#endif

#include <boost/math/tools/config.hpp>

#ifndef BOOST_MATH_HAS_NVRTC

#include <cmath>
#include <cstdint>
#include <limits>
#include <boost/math/tools/config.hpp>
#include <boost/math/tools/series.hpp>
#include <boost/math/tools/precision.hpp>
#include <boost/math/tools/big_constant.hpp>
Expand Down Expand Up @@ -314,6 +317,40 @@ BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type expm1(T x)
} // namespace math
} // namespace boost

#else // Special handling for NVRTC

namespace boost {
namespace math {

template <typename T>
BOOST_MATH_GPU_ENABLED auto expm1(T x)
{
return ::expm1(x);
}

template <>
BOOST_MATH_GPU_ENABLED auto expm1(float x)
{
return ::expm1f(x);
}

template <typename T, typename Policy>
BOOST_MATH_GPU_ENABLED auto expm1(T x, const Policy&)
{
return ::expm1(x);
}

template <typename Policy>
BOOST_MATH_GPU_ENABLED auto expm1(float x, const Policy&)
{
return ::expm1f(x);
}

} // Namespace math
} // Namespace boost

#endif // BOOST_MATH_HAS_NVRTC

#endif // BOOST_MATH_HYPOT_INCLUDED


Expand Down
4 changes: 2 additions & 2 deletions include/boost/math/special_functions/fpclassify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <boost/math/tools/config.hpp>

#ifndef BOOST_MATH_NVRTC_ENABLED
#ifndef BOOST_MATH_HAS_NVRTC

#include <boost/math/tools/real_cast.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
Expand Down Expand Up @@ -791,7 +791,7 @@ inline BOOST_MATH_GPU_ENABLED int fpclassify(T x)
} // Namespace math
} // Namespace boost

#endif // BOOST_MATH_NVRTC_ENABLED
#endif // BOOST_MATH_HAS_NVRTC

#endif // BOOST_MATH_FPCLASSIFY_HPP

9 changes: 5 additions & 4 deletions include/boost/math/special_functions/gamma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <boost/math/tools/fraction.hpp>
#include <boost/math/tools/precision.hpp>
#include <boost/math/tools/promotion.hpp>
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/tools/assert.hpp>
#include <boost/math/policies/error_handling.hpp>
#include <boost/math/constants/constants.hpp>
Expand Down Expand Up @@ -1875,7 +1876,7 @@ BOOST_MATH_GPU_ENABLED T gamma_p_derivative_imp(T a, T x, const Policy& pol)

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type
tgamma(T z, const Policy& /* pol */, const std::true_type)
tgamma(T z, const Policy& /* pol */, const boost::math::true_type)
{
BOOST_FPU_EXCEPTION_GUARD
typedef typename tools::promote_args<T>::type result_type;
Expand Down Expand Up @@ -1983,7 +1984,7 @@ const typename lgamma_initializer<T, Policy>::init lgamma_initializer<T, Policy>

template <class T1, class T2, class Policy>
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T1, T2>
tgamma(T1 a, T2 z, const Policy&, const std::false_type)
tgamma(T1 a, T2 z, const Policy&, const boost::math::false_type)
{
BOOST_FPU_EXCEPTION_GUARD
typedef tools::promote_args_t<T1, T2> result_type;
Expand All @@ -2006,7 +2007,7 @@ BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T1, T2>

template <class T1, class T2>
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T1, T2>
tgamma(T1 a, T2 z, const std::false_type& tag)
tgamma(T1 a, T2 z, const boost::math::false_type& tag)
{
return tgamma(a, z, policies::policy<>(), tag);
}
Expand Down Expand Up @@ -2107,7 +2108,7 @@ BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T1, T2>
tgamma(T1 a, T2 z, const Policy& pol)
{
using result_type = tools::promote_args_t<T1, T2>;
return static_cast<result_type>(detail::tgamma(a, z, pol, std::false_type()));
return static_cast<result_type>(detail::tgamma(a, z, pol, boost::math::false_type()));
}
//
// Full lower incomplete gamma:
Expand Down
39 changes: 38 additions & 1 deletion include/boost/math/special_functions/log1p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
#pragma warning(disable:4702) // Unreachable code (release mode only warning)
#endif

#include <boost/math/tools/config.hpp>

#ifndef BOOST_MATH_HAS_NVRTC

#include <cmath>
#include <cstdint>
#include <limits>
#include <boost/math/tools/config.hpp>
#include <boost/math/tools/series.hpp>
#include <boost/math/tools/rational.hpp>
#include <boost/math/tools/big_constant.hpp>
Expand Down Expand Up @@ -473,6 +476,40 @@ BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type log1pmx(T x)
} // namespace math
} // namespace boost

#else // Special handling for NVRTC platform

namespace boost {
namespace math {

template <typename T>
BOOST_MATH_GPU_ENABLED auto log1p(T x)
{
return ::log1p(x);
}

template <>
BOOST_MATH_GPU_ENABLED auto log1p(float x)
{
return ::log1pf(x);
}

template <typename T, typename Policy>
BOOST_MATH_GPU_ENABLED auto log1p(T x, const Policy&)
{
return ::log1p(x);
}

template <typename Policy>
BOOST_MATH_GPU_ENABLED auto log1p(float x, const Policy&)
{
return ::log1pf(x);
}

} // namespace math
} // namespace boost

#endif // BOOST_MATH_HAS_NVRTC

#ifdef _MSC_VER
#pragma warning(pop)
#endif
Expand Down
85 changes: 85 additions & 0 deletions include/boost/math/special_functions/round.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#endif

#include <boost/math/tools/config.hpp>

#ifndef BOOST_MATH_HAS_NVRTC

#include <boost/math/ccmath/detail/config.hpp>
#include <boost/math/policies/error_handling.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
Expand Down Expand Up @@ -241,4 +244,86 @@ BOOST_MATH_GPU_ENABLED inline long long llround(const T& v)

}} // namespaces

#else // Specialized NVRTC overloads

namespace boost {
namespace math {

template <typename T>
BOOST_MATH_GPU_ENABLED T round(T x)
{
return ::round(x);
}

template <>
BOOST_MATH_GPU_ENABLED float round(float x)
{
return ::roundf(x);
}

template <typename T, typename Policy>
BOOST_MATH_GPU_ENABLED T round(T x, const Policy&)
{
return ::round(x);
}

template <typename Policy>
BOOST_MATH_GPU_ENABLED float round(float x, const Policy&)
{
return ::roundf(x);
}

template <typename T>
BOOST_MATH_GPU_ENABLED long lround(T x)
{
return ::lround(x);
}

template <>
BOOST_MATH_GPU_ENABLED long lround(float x)
{
return ::lroundf(x);
}

template <typename T, typename Policy>
BOOST_MATH_GPU_ENABLED long lround(T x, const Policy&)
{
return ::lround(x);
}

template <typename Policy>
BOOST_MATH_GPU_ENABLED long lround(float x, const Policy&)
{
return ::lroundf(x);
}

template <typename T>
BOOST_MATH_GPU_ENABLED long long llround(T x)
{
return ::llround(x);
}

template <>
BOOST_MATH_GPU_ENABLED long long llround(float x)
{
return ::llroundf(x);
}

template <typename T, typename Policy>
BOOST_MATH_GPU_ENABLED long long llround(T x, const Policy&)
{
return ::llround(x);
}

template <typename Policy>
BOOST_MATH_GPU_ENABLED long long llround(float x, const Policy&)
{
return ::llroundf(x);
}

} // Namespace math
} // Namespace boost

#endif // BOOST_MATH_HAS_NVRTC

#endif // BOOST_MATH_ROUND_HPP
Loading

0 comments on commit bc5dc9c

Please sign in to comment.