Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b5ded3d
Replace BOOST_MATH_CHECK_THROW with boost.test
mborland Jul 18, 2024
2a16fe3
Add additional configuration macros
mborland Jul 18, 2024
d04988c
Add additional macro for local static variables
mborland Jul 18, 2024
964d494
Add CUDA markers to binomial dist
mborland Jul 18, 2024
b42048c
Add CUDA markers to polynomial class
mborland Jul 18, 2024
f62b73a
Add cuda markers to arcsine distribution
mborland Jul 18, 2024
977ccbf
Add CUDA definition of force inline ignoring that of the host compiler
mborland Jul 18, 2024
980a10c
Add config option to return NANs
mborland Jul 18, 2024
ec3d237
First cut at CUDA allowed policies
mborland Jul 18, 2024
96921da
Add new definitions of classification functions
mborland Jul 19, 2024
fbf5a7f
Replace use of std::string with char*
mborland Jul 19, 2024
bb0716d
Mark constants as CUDA
mborland Jul 19, 2024
2481c0d
Disable exceptions for device code
mborland Jul 19, 2024
301637c
Specialize epsilon functions
mborland Jul 19, 2024
d3e93ad
Add sycl configuration options
mborland Jul 19, 2024
dee1c40
Rename GPU macros
mborland Jul 19, 2024
14d5b3b
Refactor macros for SYCL limited support
mborland Jul 19, 2024
1d6c576
Limit binomial distribution to CUDA
mborland Jul 19, 2024
2bb07f2
Disable calls to errno with SYCL
mborland Jul 19, 2024
235f5c9
Replace static const char* with constexpr auto
mborland Jul 19, 2024
8594af7
Update polynomial and rationals
mborland Jul 22, 2024
04c33f8
Add additional overflow error overloads
mborland Jul 22, 2024
282a401
Add GPU safe max, min, and swap function macros
mborland Jul 22, 2024
b39f01d
Add log1p GPU support
mborland Jul 22, 2024
23b6d28
Add precision helper functions
mborland Jul 22, 2024
d9c4fab
Markup big_constant
mborland Jul 22, 2024
9107750
Add support for lanczos and change storage duration
mborland Jul 22, 2024
50d01bf
Apply GPU to rationals and series evaluations
mborland Jul 22, 2024
15bade2
Allow beta to be used on GPU
mborland Jul 22, 2024
4f55575
Disable SSE2 lanczos on GPU
mborland Jul 22, 2024
47282d3
Changes to allow beta on SYCL
mborland Jul 22, 2024
308bf4d
Fix cauchy linker errror
mborland Jul 23, 2024
38596e2
Reactivate domain error for beta
mborland Jul 23, 2024
548d6f5
Ignore float too small errors
mborland Jul 23, 2024
7c9c761
Remove SYCL macros from errno calls
mborland Jul 23, 2024
f3f03c8
Adjust default policy for GPU cases
mborland Jul 23, 2024
32b909d
Adjust CML for sycl
mborland Jul 23, 2024
2148185
Add sycl compatible simple test
mborland Jul 23, 2024
b293df0
Add sycl cmake testing
mborland Jul 23, 2024
fcf7ba8
Small CML fixes
mborland Jul 23, 2024
dbee257
Port fixes to run SYCL on test_arcsine
mborland Jul 23, 2024
9ed0f2b
More SYCL workarounds
mborland Jul 23, 2024
b35b4de
Add cuda files
mborland Jul 23, 2024
19d0d5b
Add compile only cmake testing
mborland Jul 23, 2024
d60d5d6
Add test helper headers
mborland Jul 23, 2024
3bfd85c
Fix line endings
mborland Jul 23, 2024
f17946b
Remove duplicate test from compile only battery
mborland Jul 23, 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
12 changes: 6 additions & 6 deletions include/boost/math/constants/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ namespace boost{ namespace math
constant_initializer<T, & BOOST_MATH_JOIN(constant_, name)<T>::get_from_string >::force_instantiate();\
return get_from_string();\
}\
static inline constexpr T get(const std::integral_constant<int, construct_from_float>) noexcept\
BOOST_MATH_GPU_ENABLED static inline constexpr T get(const std::integral_constant<int, construct_from_float>) noexcept\
{ return BOOST_MATH_JOIN(x, F); }\
static inline constexpr T get(const std::integral_constant<int, construct_from_double>&) noexcept\
BOOST_MATH_GPU_ENABLED static inline constexpr T get(const std::integral_constant<int, construct_from_double>&) noexcept\
{ return x; }\
static inline constexpr T get(const std::integral_constant<int, construct_from_long_double>&) noexcept\
BOOST_MATH_GPU_ENABLED static inline constexpr T get(const std::integral_constant<int, construct_from_long_double>&) noexcept\
{ return BOOST_MATH_JOIN(x, L); }\
BOOST_MATH_FLOAT128_CONSTANT_OVERLOAD(x) \
template <int N> static inline const T& get(const std::integral_constant<int, N>&)\
Expand All @@ -231,9 +231,9 @@ namespace boost{ namespace math
\
\
/* The actual forwarding function: */ \
template <typename T, typename Policy> inline constexpr typename detail::constant_return<T, Policy>::type name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T) BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(Policy)) BOOST_MATH_NOEXCEPT(T)\
template <typename T, typename Policy> BOOST_MATH_GPU_ENABLED inline constexpr typename detail::constant_return<T, Policy>::type name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T) BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(Policy)) BOOST_MATH_NOEXCEPT(T)\
{ return detail:: BOOST_MATH_JOIN(constant_, name)<T>::get(typename construction_traits<T, Policy>::type()); }\
template <typename T> inline constexpr typename detail::constant_return<T>::type name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) BOOST_MATH_NOEXCEPT(T)\
template <typename T> BOOST_MATH_GPU_ENABLED inline constexpr typename detail::constant_return<T>::type name(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) BOOST_MATH_NOEXCEPT(T)\
{ return name<T, boost::math::policies::policy<> >(); }\
\
\
Expand Down Expand Up @@ -328,7 +328,7 @@ namespace boost{ namespace math
#endif

template <typename T>
inline constexpr T tau() { return two_pi<T>(); }
BOOST_MATH_GPU_ENABLED inline constexpr T tau() { return two_pi<T>(); }

} // namespace constants
} // namespace math
Expand Down
65 changes: 33 additions & 32 deletions include/boost/math/distributions/arcsine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define BOOST_MATH_DIST_ARCSINE_HPP

#include <cmath>
#include <boost/math/tools/config.hpp>
#include <boost/math/distributions/fwd.hpp>
#include <boost/math/distributions/complement.hpp> // complements.
#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks.
Expand All @@ -55,7 +56,7 @@ namespace boost
// Common error checking routines for arcsine distribution functions:
// Duplicating for x_min and x_max provides specific error messages.
template <class RealType, class Policy>
inline bool check_x_min(const char* function, const RealType& x, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_x_min(const char* function, const RealType& x, RealType* result, const Policy& pol)
{
if (!(boost::math::isfinite)(x))
{
Expand All @@ -68,7 +69,7 @@ namespace boost
} // bool check_x_min

template <class RealType, class Policy>
inline bool check_x_max(const char* function, const RealType& x, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_x_max(const char* function, const RealType& x, RealType* result, const Policy& pol)
{
if (!(boost::math::isfinite)(x))
{
Expand All @@ -82,14 +83,14 @@ namespace boost


template <class RealType, class Policy>
inline bool check_x_minmax(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_x_minmax(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
{ // Check x_min < x_max
if (x_min >= x_max)
{
std::string msg = "x_max argument is %1%, but must be > x_min";
constexpr auto msg = "x_max argument is %1%, but must be > x_min";
*result = policies::raise_domain_error<RealType>(
function,
msg.c_str(), x_max, pol);
msg, x_max, pol);
// "x_max argument is %1%, but must be > x_min !", x_max, pol);
// "x_max argument is %1%, but must be > x_min %2!", x_max, x_min, pol); would be better.
// But would require replication of all helpers functions in /policies/error_handling.hpp for two values,
Expand All @@ -100,7 +101,7 @@ namespace boost
} // bool check_x_minmax

template <class RealType, class Policy>
inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
{
if ((p < 0) || (p > 1) || !(boost::math::isfinite)(p))
{
Expand All @@ -113,7 +114,7 @@ namespace boost
} // bool check_prob

template <class RealType, class Policy>
inline bool check_x(const char* function, const RealType& x_min, const RealType& x_max, const RealType& x, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_x(const char* function, const RealType& x_min, const RealType& x_max, const RealType& x, RealType* result, const Policy& pol)
{ // Check x finite and x_min < x < x_max.
if (!(boost::math::isfinite)(x))
{
Expand All @@ -137,22 +138,22 @@ namespace boost
} // bool check_x

template <class RealType, class Policy>
inline bool check_dist(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_dist(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
{ // Check both x_min and x_max finite, and x_min < x_max.
return check_x_min(function, x_min, result, pol)
&& check_x_max(function, x_max, result, pol)
&& check_x_minmax(function, x_min, x_max, result, pol);
} // bool check_dist

template <class RealType, class Policy>
inline bool check_dist_and_x(const char* function, const RealType& x_min, const RealType& x_max, RealType x, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_dist_and_x(const char* function, const RealType& x_min, const RealType& x_max, RealType x, RealType* result, const Policy& pol)
{
return check_dist(function, x_min, x_max, result, pol)
&& arcsine_detail::check_x(function, x_min, x_max, x, result, pol);
} // bool check_dist_and_x

template <class RealType, class Policy>
inline bool check_dist_and_prob(const char* function, const RealType& x_min, const RealType& x_max, RealType p, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_dist_and_prob(const char* function, const RealType& x_min, const RealType& x_max, RealType p, RealType* result, const Policy& pol)
{
return check_dist(function, x_min, x_max, result, pol)
&& check_prob(function, p, result, pol);
Expand All @@ -167,7 +168,7 @@ namespace boost
typedef RealType value_type;
typedef Policy policy_type;

arcsine_distribution(RealType x_min = 0, RealType x_max = 1) : m_x_min(x_min), m_x_max(x_max)
BOOST_MATH_GPU_ENABLED arcsine_distribution(RealType x_min = 0, RealType x_max = 1) : m_x_min(x_min), m_x_max(x_max)
{ // Default beta (alpha = beta = 0.5) is standard arcsine with x_min = 0, x_max = 1.
// Generalized to allow x_min and x_max to be specified.
RealType result;
Expand All @@ -178,11 +179,11 @@ namespace boost
&result, Policy());
} // arcsine_distribution constructor.
// Accessor functions:
RealType x_min() const
BOOST_MATH_GPU_ENABLED RealType x_min() const
{
return m_x_min;
}
RealType x_max() const
BOOST_MATH_GPU_ENABLED RealType x_max() const
{
return m_x_max;
}
Expand All @@ -203,21 +204,21 @@ namespace boost
#endif

template <class RealType, class Policy>
inline const std::pair<RealType, RealType> range(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline const std::pair<RealType, RealType> range(const arcsine_distribution<RealType, Policy>& dist)
{ // Range of permissible values for random variable x.
using boost::math::tools::max_value;
return std::pair<RealType, RealType>(static_cast<RealType>(dist.x_min()), static_cast<RealType>(dist.x_max()));
}

template <class RealType, class Policy>
inline const std::pair<RealType, RealType> support(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline const std::pair<RealType, RealType> support(const arcsine_distribution<RealType, Policy>& dist)
{ // Range of supported values for random variable x.
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
return std::pair<RealType, RealType>(static_cast<RealType>(dist.x_min()), static_cast<RealType>(dist.x_max()));
}

template <class RealType, class Policy>
inline RealType mean(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType mean(const arcsine_distribution<RealType, Policy>& dist)
{ // Mean of arcsine distribution .
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -236,7 +237,7 @@ namespace boost
} // mean

template <class RealType, class Policy>
inline RealType variance(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType variance(const arcsine_distribution<RealType, Policy>& dist)
{ // Variance of standard arcsine distribution = (1-0)/8 = 0.125.
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -254,7 +255,7 @@ namespace boost
} // variance

template <class RealType, class Policy>
inline RealType mode(const arcsine_distribution<RealType, Policy>& /* dist */)
BOOST_MATH_GPU_ENABLED inline RealType mode(const arcsine_distribution<RealType, Policy>& /* dist */)
{ //There are always [*two] values for the mode, at ['x_min] and at ['x_max], default 0 and 1,
// so instead we raise the exception domain_error.
return policies::raise_domain_error<RealType>(
Expand All @@ -265,7 +266,7 @@ namespace boost
} // mode

template <class RealType, class Policy>
inline RealType median(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType median(const arcsine_distribution<RealType, Policy>& dist)
{ // Median of arcsine distribution (a + b) / 2 == mean.
RealType x_min = dist.x_min();
RealType x_max = dist.x_max();
Expand All @@ -283,7 +284,7 @@ namespace boost
}

template <class RealType, class Policy>
inline RealType skewness(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType skewness(const arcsine_distribution<RealType, Policy>& dist)
{
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -302,7 +303,7 @@ namespace boost
} // skewness

template <class RealType, class Policy>
inline RealType kurtosis_excess(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess(const arcsine_distribution<RealType, Policy>& dist)
{
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -322,7 +323,7 @@ namespace boost
} // kurtosis_excess

template <class RealType, class Policy>
inline RealType kurtosis(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType kurtosis(const arcsine_distribution<RealType, Policy>& dist)
{
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -342,12 +343,12 @@ namespace boost
} // kurtosis

template <class RealType, class Policy>
inline RealType pdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& xx)
BOOST_MATH_GPU_ENABLED inline RealType pdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& xx)
{ // Probability Density/Mass Function arcsine.
BOOST_FPU_EXCEPTION_GUARD
BOOST_MATH_STD_USING // For ADL of std functions.

static const char* function = "boost::math::pdf(arcsine_distribution<%1%> const&, %1%)";
constexpr auto function = "boost::math::pdf(arcsine_distribution<%1%> const&, %1%)";

RealType lo = dist.x_min();
RealType hi = dist.x_max();
Expand All @@ -368,11 +369,11 @@ namespace boost
} // pdf

template <class RealType, class Policy>
inline RealType cdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& x)
BOOST_MATH_GPU_ENABLED inline RealType cdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& x)
{ // Cumulative Distribution Function arcsine.
BOOST_MATH_STD_USING // For ADL of std functions.

static const char* function = "boost::math::cdf(arcsine_distribution<%1%> const&, %1%)";
constexpr auto function = "boost::math::cdf(arcsine_distribution<%1%> const&, %1%)";

RealType x_min = dist.x_min();
RealType x_max = dist.x_max();
Expand Down Expand Up @@ -401,10 +402,10 @@ namespace boost
} // arcsine cdf

template <class RealType, class Policy>
inline RealType cdf(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_GPU_ENABLED inline RealType cdf(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
{ // Complemented Cumulative Distribution Function arcsine.
BOOST_MATH_STD_USING // For ADL of std functions.
static const char* function = "boost::math::cdf(arcsine_distribution<%1%> const&, %1%)";
constexpr auto function = "boost::math::cdf(arcsine_distribution<%1%> const&, %1%)";

RealType x = c.param;
arcsine_distribution<RealType, Policy> const& dist = c.dist;
Expand Down Expand Up @@ -437,7 +438,7 @@ namespace boost
} // arcsine ccdf

template <class RealType, class Policy>
inline RealType quantile(const arcsine_distribution<RealType, Policy>& dist, const RealType& p)
BOOST_MATH_GPU_ENABLED inline RealType quantile(const arcsine_distribution<RealType, Policy>& dist, const RealType& p)
{
// Quantile or Percent Point arcsine function or
// Inverse Cumulative probability distribution function CDF.
Expand All @@ -451,7 +452,7 @@ namespace boost

using boost::math::constants::half_pi;

static const char* function = "boost::math::quantile(arcsine_distribution<%1%> const&, %1%)";
constexpr auto function = "boost::math::quantile(arcsine_distribution<%1%> const&, %1%)";

RealType result = 0; // of argument checks:
RealType x_min = dist.x_min();
Expand Down Expand Up @@ -481,15 +482,15 @@ namespace boost
} // quantile

template <class RealType, class Policy>
inline RealType quantile(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_GPU_ENABLED inline RealType quantile(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
{
// Complement Quantile or Percent Point arcsine function.
// Return the number of expected x for a given
// complement of the probability q.
BOOST_MATH_STD_USING // For ADL of std functions.

using boost::math::constants::half_pi;
static const char* function = "boost::math::quantile(arcsine_distribution<%1%> const&, %1%)";
constexpr auto function = "boost::math::quantile(arcsine_distribution<%1%> const&, %1%)";

// Error checks:
RealType q = c.param;
Expand Down
Loading