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

GPU batch 3 #4

Merged
merged 37 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cb3701b
Add markers for log1p
mborland Jul 25, 2024
4df80c1
Add log1p CUDA testing
mborland Jul 25, 2024
78a8d32
Add SYCL testing for log1p and log1pmx
mborland Jul 25, 2024
428d666
Fix use of static const char* in log1pmx
mborland Jul 25, 2024
944f45e
Loosen tolerance
mborland Jul 25, 2024
2e77757
Add GPU support to digamma
mborland Jul 25, 2024
8c97086
Add digamma CUDA testing
mborland Jul 25, 2024
9fb4677
Add sycl test of digamma
mborland Jul 25, 2024
6c1e9d7
Begin adding our own definition of numeric_limits
mborland Jul 25, 2024
1629e75
Make pow GPU compatible
mborland Jul 25, 2024
c887a74
Make sin_pi GPU compatible
mborland Jul 25, 2024
5f4ab0d
Make trigamma GPU compatible
mborland Jul 25, 2024
525b18c
Add trigamma CUDA testing
mborland Jul 25, 2024
db7fb65
Rename dispatching function
mborland Jul 25, 2024
c049fab
Eliminate recursion in sin_pi for SYCL
mborland Jul 25, 2024
cfc1ad0
Remove recursion from trigamma
mborland Jul 25, 2024
0fe35eb
Add trigamma SYCL testing
mborland Jul 25, 2024
48f8734
Add sycl testing of pow
mborland Jul 25, 2024
b51d312
Add CUDA sin_pi testing
mborland Jul 25, 2024
e4519a7
Pass integral_constant directly instead of creating pointer
mborland Jul 25, 2024
20f17d4
Add missing include guards for numeric limits
mborland Jul 25, 2024
85e2e4c
Make cos_pi GPU capable
mborland Jul 25, 2024
3c598df
Add cos_pi CUDA testing
mborland Jul 25, 2024
502f04f
Add all the integer types to numeric limits
mborland Jul 25, 2024
8a5796a
Simplify error handling using the new numeric limits
mborland Jul 25, 2024
0210fa3
Add GPU support to derived accessors
mborland Jul 25, 2024
226e42e
Add GPU support to complement distributions
mborland Jul 25, 2024
fcbcf04
Add GPU support to the bernoulli distribution
mborland Jul 25, 2024
6bf19ff
Add SYCL testing of bernoulli distribution
mborland Jul 25, 2024
0e7ab64
Add bernoulli cdf CUDA testing
mborland Jul 25, 2024
044f164
Add bernoulli pdf CUDA testing
mborland Jul 25, 2024
8e696df
Add bool to numeric limits for completeness
mborland Jul 26, 2024
f8a0f54
Fix test poisson ambiguity with numeric_limits
mborland Jul 26, 2024
746f939
Fix header paths
mborland Jul 26, 2024
2eaca5f
Fix invalid constexpr variables
mborland Jul 26, 2024
480df5f
Fix new trigamma dispatch function and illegal constexpr
mborland Jul 26, 2024
bdc7c25
Speed up CI builds
mborland Jul 26, 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
4 changes: 2 additions & 2 deletions .github/workflows/cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Build tests
run: |
cd ../boost-root/__build__
cmake --build . --target tests
cmake --build . --target tests -j $(nproc)
- name: Run tests
run: |
cd ../boost-root/__build__
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
- name: Build tests
run: |
cd ../boost-root/__build__
cmake --build . --target tests
cmake --build . --target tests -j $(nproc)
- name: Run tests
run: |
cd ../boost-root/__build__
Expand Down
43 changes: 22 additions & 21 deletions include/boost/math/distributions/bernoulli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// Copyright John Maddock 2006.
// Copyright Paul A. Bristow 2007.
// Copyright Matt Borland 2024.

// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
Expand Down Expand Up @@ -43,7 +44,7 @@ namespace boost
{
// Common error checking routines for bernoulli distribution functions:
template <class RealType, class Policy>
inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& /* pol */)
BOOST_MATH_GPU_ENABLED inline bool check_success_fraction(const char* function, const RealType& p, RealType* result, const Policy& /* pol */)
{
if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
{
Expand All @@ -55,23 +56,23 @@ namespace boost
return true;
}
template <class RealType, class Policy>
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 std::true_type&)
{
return check_success_fraction(function, p, result, Policy());
}
template <class RealType, class Policy>
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 std::false_type&)
{
return true;
}
template <class RealType, class Policy>
inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */)
BOOST_MATH_GPU_ENABLED inline bool check_dist(const char* function, const RealType& p, RealType* result, const Policy& /* pol */)
{
return check_dist(function, p, result, Policy(), typename policies::constructor_error_check<Policy>::type());
}

template <class RealType, class Policy>
inline bool check_dist_and_k(const char* function, const RealType& p, RealType k, RealType* result, const Policy& pol)
BOOST_MATH_GPU_ENABLED inline bool check_dist_and_k(const char* function, const RealType& p, RealType k, RealType* result, const Policy& pol)
{
if(check_dist(function, p, result, Policy(), typename policies::method_error_check<Policy>::type()) == false)
{
Expand All @@ -87,7 +88,7 @@ namespace boost
return true;
}
template <class RealType, class Policy>
inline bool check_dist_and_prob(const char* function, RealType p, RealType prob, RealType* result, const Policy& /* pol */)
BOOST_MATH_GPU_ENABLED inline bool check_dist_and_prob(const char* function, RealType p, RealType prob, RealType* result, const Policy& /* pol */)
{
if((check_dist(function, p, result, Policy(), typename policies::method_error_check<Policy>::type()) && detail::check_probability(function, prob, result, Policy())) == false)
{
Expand All @@ -105,7 +106,7 @@ namespace boost
typedef RealType value_type;
typedef Policy policy_type;

bernoulli_distribution(RealType p = 0.5) : m_p(p)
BOOST_MATH_GPU_ENABLED bernoulli_distribution(RealType p = 0.5) : m_p(p)
{ // Default probability = half suits 'fair' coin tossing
// where probability of heads == probability of tails.
RealType result; // of checks.
Expand All @@ -115,7 +116,7 @@ namespace boost
&result, Policy());
} // bernoulli_distribution constructor.

RealType success_fraction() const
BOOST_MATH_GPU_ENABLED RealType success_fraction() const
{ // Probability.
return m_p;
}
Expand All @@ -132,21 +133,21 @@ namespace boost
#endif

template <class RealType, class Policy>
inline const std::pair<RealType, RealType> range(const bernoulli_distribution<RealType, Policy>& /* dist */)
BOOST_MATH_GPU_ENABLED inline const std::pair<RealType, RealType> range(const bernoulli_distribution<RealType, Policy>& /* dist */)
{ // Range of permissible values for random variable k = {0, 1}.
using boost::math::tools::max_value;
return std::pair<RealType, RealType>(static_cast<RealType>(0), static_cast<RealType>(1));
}

template <class RealType, class Policy>
inline const std::pair<RealType, RealType> support(const bernoulli_distribution<RealType, Policy>& /* dist */)
BOOST_MATH_GPU_ENABLED inline const std::pair<RealType, RealType> support(const bernoulli_distribution<RealType, Policy>& /* dist */)
{ // Range of supported values for random variable k = {0, 1}.
// 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>(0), static_cast<RealType>(1));
}

template <class RealType, class Policy>
inline RealType mean(const bernoulli_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType mean(const bernoulli_distribution<RealType, Policy>& dist)
{ // Mean of bernoulli distribution = p (n = 1).
return dist.success_fraction();
} // mean
Expand All @@ -159,13 +160,13 @@ namespace boost
//} // median

template <class RealType, class Policy>
inline RealType variance(const bernoulli_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType variance(const bernoulli_distribution<RealType, Policy>& dist)
{ // Variance of bernoulli distribution =p * q.
return dist.success_fraction() * (1 - dist.success_fraction());
} // variance

template <class RealType, class Policy>
RealType pdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
BOOST_MATH_GPU_ENABLED RealType pdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
{ // Probability Density/Mass Function.
BOOST_FPU_EXCEPTION_GUARD
// Error check:
Expand All @@ -190,7 +191,7 @@ namespace boost
} // pdf

template <class RealType, class Policy>
inline RealType cdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
BOOST_MATH_GPU_ENABLED inline RealType cdf(const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
{ // Cumulative Distribution Function Bernoulli.
RealType p = dist.success_fraction();
// Error check:
Expand All @@ -214,7 +215,7 @@ namespace boost
} // bernoulli cdf

template <class RealType, class Policy>
inline RealType cdf(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_GPU_ENABLED inline RealType cdf(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
{ // Complemented Cumulative Distribution Function bernoulli.
RealType const& k = c.param;
bernoulli_distribution<RealType, Policy> const& dist = c.dist;
Expand All @@ -240,7 +241,7 @@ namespace boost
} // bernoulli cdf complement

template <class RealType, class Policy>
inline RealType quantile(const bernoulli_distribution<RealType, Policy>& dist, const RealType& p)
BOOST_MATH_GPU_ENABLED inline RealType quantile(const bernoulli_distribution<RealType, Policy>& dist, const RealType& p)
{ // Quantile or Percent Point Bernoulli function.
// Return the number of expected successes k either 0 or 1.
// for a given probability p.
Expand All @@ -265,7 +266,7 @@ namespace boost
} // quantile

template <class RealType, class Policy>
inline RealType quantile(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_GPU_ENABLED inline RealType quantile(const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
{ // Quantile or Percent Point bernoulli function.
// Return the number of expected successes k for a given
// complement of the probability q.
Expand Down Expand Up @@ -294,21 +295,21 @@ namespace boost
} // quantile complemented.

template <class RealType, class Policy>
inline RealType mode(const bernoulli_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType mode(const bernoulli_distribution<RealType, Policy>& dist)
{
return static_cast<RealType>((dist.success_fraction() <= 0.5) ? 0 : 1); // p = 0.5 can be 0 or 1
}

template <class RealType, class Policy>
inline RealType skewness(const bernoulli_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType skewness(const bernoulli_distribution<RealType, Policy>& dist)
{
BOOST_MATH_STD_USING; // Aid ADL for sqrt.
RealType p = dist.success_fraction();
return (1 - 2 * p) / sqrt(p * (1 - p));
}

template <class RealType, class Policy>
inline RealType kurtosis_excess(const bernoulli_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess(const bernoulli_distribution<RealType, Policy>& dist)
{
RealType p = dist.success_fraction();
// Note Wolfram says this is kurtosis in text, but gamma2 is the kurtosis excess,
Expand All @@ -319,7 +320,7 @@ namespace boost
}

template <class RealType, class Policy>
inline RealType kurtosis(const bernoulli_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType kurtosis(const bernoulli_distribution<RealType, Policy>& dist)
{
RealType p = dist.success_fraction();
return 1 / (1 - p) + 1/p -6 + 3;
Expand Down
27 changes: 15 additions & 12 deletions include/boost/math/distributions/complement.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// (C) Copyright John Maddock 2006.
// (C) Copyright Paul A. Bristow 2006.
// (C) Copyright Matt Borland 2024
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_STATS_COMPLEMENT_HPP
#define BOOST_STATS_COMPLEMENT_HPP

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

//
// This code really defines our own tuple type.
// It would be nice to reuse boost::math::tuple
Expand All @@ -19,7 +22,7 @@ namespace boost{ namespace math{
template <class Dist, class RealType>
struct complemented2_type
{
complemented2_type(
BOOST_MATH_GPU_ENABLED complemented2_type(
const Dist& d,
const RealType& p1)
: dist(d),
Expand All @@ -35,7 +38,7 @@ struct complemented2_type
template <class Dist, class RealType1, class RealType2>
struct complemented3_type
{
complemented3_type(
BOOST_MATH_GPU_ENABLED complemented3_type(
const Dist& d,
const RealType1& p1,
const RealType2& p2)
Expand All @@ -53,7 +56,7 @@ struct complemented3_type
template <class Dist, class RealType1, class RealType2, class RealType3>
struct complemented4_type
{
complemented4_type(
BOOST_MATH_GPU_ENABLED complemented4_type(
const Dist& d,
const RealType1& p1,
const RealType2& p2,
Expand All @@ -74,7 +77,7 @@ struct complemented4_type
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4>
struct complemented5_type
{
complemented5_type(
BOOST_MATH_GPU_ENABLED complemented5_type(
const Dist& d,
const RealType1& p1,
const RealType2& p2,
Expand All @@ -98,7 +101,7 @@ struct complemented5_type
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5>
struct complemented6_type
{
complemented6_type(
BOOST_MATH_GPU_ENABLED complemented6_type(
const Dist& d,
const RealType1& p1,
const RealType2& p2,
Expand All @@ -125,7 +128,7 @@ struct complemented6_type
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5, class RealType6>
struct complemented7_type
{
complemented7_type(
BOOST_MATH_GPU_ENABLED complemented7_type(
const Dist& d,
const RealType1& p1,
const RealType2& p2,
Expand Down Expand Up @@ -153,37 +156,37 @@ struct complemented7_type
};

template <class Dist, class RealType>
inline complemented2_type<Dist, RealType> complement(const Dist& d, const RealType& r)
BOOST_MATH_GPU_ENABLED inline complemented2_type<Dist, RealType> complement(const Dist& d, const RealType& r)
{
return complemented2_type<Dist, RealType>(d, r);
}

template <class Dist, class RealType1, class RealType2>
inline complemented3_type<Dist, RealType1, RealType2> complement(const Dist& d, const RealType1& r1, const RealType2& r2)
BOOST_MATH_GPU_ENABLED inline complemented3_type<Dist, RealType1, RealType2> complement(const Dist& d, const RealType1& r1, const RealType2& r2)
{
return complemented3_type<Dist, RealType1, RealType2>(d, r1, r2);
}

template <class Dist, class RealType1, class RealType2, class RealType3>
inline complemented4_type<Dist, RealType1, RealType2, RealType3> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3)
BOOST_MATH_GPU_ENABLED inline complemented4_type<Dist, RealType1, RealType2, RealType3> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3)
{
return complemented4_type<Dist, RealType1, RealType2, RealType3>(d, r1, r2, r3);
}

template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4>
inline complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4)
BOOST_MATH_GPU_ENABLED inline complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4)
{
return complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4>(d, r1, r2, r3, r4);
}

template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5>
inline complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5)
BOOST_MATH_GPU_ENABLED inline complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5)
{
return complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5>(d, r1, r2, r3, r4, r5);
}

template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5, class RealType6>
inline complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5, const RealType6& r6)
BOOST_MATH_GPU_ENABLED inline complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5, const RealType6& r6)
{
return complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6>(d, r1, r2, r3, r4, r5, r6);
}
Expand Down
Loading