Skip to content

Commit adf8abd

Browse files
committed
Apply GPU markers to ibeta_inv_ab
Remove NVRTC workaround Apply GPU markers to ibeta_inverse Apply GPU markers to t_dist_inv Fix warning suppression Add dispatch function and remove workaround Move disabling block Make binomial GPU enabled Add SYCL testing of ibeta Add SYCL testing of ibeta_inv Add SYCL testing of ibeta_inv_ab Add SYCL testing of full beta suite Add makers to fwd decls Add special forward decls for NVRTC Add betac nvrtc testing Add betac CUDA testing Add ibeta CUDA testing Add ibeta NVRTC testing Add ibetac NVRTC testing Add ibeta_derviative testing to nvrtc Add ibeta_derivative CUDA testing Add cbrt policy overload for NVRTC Fix NVRTC definition of BOOST_MATH_IF_CONSTEXPR Add ibeta_inv and ibetac_inv NVRTC testing Fix make pair helper on device Add CUDA testing of ibeta_inv* and ibetac_inv* Move location so that it also works on NVRTC Add NVRTC testing of ibeta_inv* and ibetac_inv* Fixup test sets since they ignore the policy Make the beta dist GPU compatible Add beta dist SYCL testing Add beta dist CUDA testing Add beta dist NVRTC testing
1 parent 0002de0 commit adf8abd

File tree

85 files changed

+9093
-238
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+9093
-238
lines changed

include/boost/math/distributions/beta.hpp

+44-43
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,22 @@
2525
#ifndef BOOST_MATH_DIST_BETA_HPP
2626
#define BOOST_MATH_DIST_BETA_HPP
2727

28+
#include <boost/math/tools/config.hpp>
29+
#include <boost/math/tools/tuple.hpp>
2830
#include <boost/math/distributions/fwd.hpp>
2931
#include <boost/math/special_functions/beta.hpp> // for beta.
3032
#include <boost/math/distributions/complement.hpp> // complements.
3133
#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks
3234
#include <boost/math/special_functions/fpclassify.hpp> // isnan.
3335
#include <boost/math/tools/roots.hpp> // for root finding.
36+
#include <boost/math/policies/error_handling.hpp>
3437

3538
#if defined (BOOST_MSVC)
3639
# pragma warning(push)
3740
# pragma warning(disable: 4702) // unreachable code
3841
// in domain_error_imp in error_handling
3942
#endif
4043

41-
#include <utility>
42-
4344
namespace boost
4445
{
4546
namespace math
@@ -48,7 +49,7 @@ namespace boost
4849
{
4950
// Common error checking routines for beta distribution functions:
5051
template <class RealType, class Policy>
51-
inline bool check_alpha(const char* function, const RealType& alpha, RealType* result, const Policy& pol)
52+
BOOST_MATH_GPU_ENABLED inline bool check_alpha(const char* function, const RealType& alpha, RealType* result, const Policy& pol)
5253
{
5354
if(!(boost::math::isfinite)(alpha) || (alpha <= 0))
5455
{
@@ -61,7 +62,7 @@ namespace boost
6162
} // bool check_alpha
6263

6364
template <class RealType, class Policy>
64-
inline bool check_beta(const char* function, const RealType& beta, RealType* result, const Policy& pol)
65+
BOOST_MATH_GPU_ENABLED inline bool check_beta(const char* function, const RealType& beta, RealType* result, const Policy& pol)
6566
{
6667
if(!(boost::math::isfinite)(beta) || (beta <= 0))
6768
{
@@ -74,7 +75,7 @@ namespace boost
7475
} // bool check_beta
7576

7677
template <class RealType, class Policy>
77-
inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
78+
BOOST_MATH_GPU_ENABLED inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
7879
{
7980
if((p < 0) || (p > 1) || !(boost::math::isfinite)(p))
8081
{
@@ -87,7 +88,7 @@ namespace boost
8788
} // bool check_prob
8889

8990
template <class RealType, class Policy>
90-
inline bool check_x(const char* function, const RealType& x, RealType* result, const Policy& pol)
91+
BOOST_MATH_GPU_ENABLED inline bool check_x(const char* function, const RealType& x, RealType* result, const Policy& pol)
9192
{
9293
if(!(boost::math::isfinite)(x) || (x < 0) || (x > 1))
9394
{
@@ -100,28 +101,28 @@ namespace boost
100101
} // bool check_x
101102

102103
template <class RealType, class Policy>
103-
inline bool check_dist(const char* function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol)
104+
BOOST_MATH_GPU_ENABLED inline bool check_dist(const char* function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol)
104105
{ // Check both alpha and beta.
105106
return check_alpha(function, alpha, result, pol)
106107
&& check_beta(function, beta, result, pol);
107108
} // bool check_dist
108109

109110
template <class RealType, class Policy>
110-
inline bool check_dist_and_x(const char* function, const RealType& alpha, const RealType& beta, RealType x, RealType* result, const Policy& pol)
111+
BOOST_MATH_GPU_ENABLED inline bool check_dist_and_x(const char* function, const RealType& alpha, const RealType& beta, RealType x, RealType* result, const Policy& pol)
111112
{
112113
return check_dist(function, alpha, beta, result, pol)
113114
&& beta_detail::check_x(function, x, result, pol);
114115
} // bool check_dist_and_x
115116

116117
template <class RealType, class Policy>
117-
inline bool check_dist_and_prob(const char* function, const RealType& alpha, const RealType& beta, RealType p, RealType* result, const Policy& pol)
118+
BOOST_MATH_GPU_ENABLED inline bool check_dist_and_prob(const char* function, const RealType& alpha, const RealType& beta, RealType p, RealType* result, const Policy& pol)
118119
{
119120
return check_dist(function, alpha, beta, result, pol)
120121
&& check_prob(function, p, result, pol);
121122
} // bool check_dist_and_prob
122123

123124
template <class RealType, class Policy>
124-
inline bool check_mean(const char* function, const RealType& mean, RealType* result, const Policy& pol)
125+
BOOST_MATH_GPU_ENABLED inline bool check_mean(const char* function, const RealType& mean, RealType* result, const Policy& pol)
125126
{
126127
if(!(boost::math::isfinite)(mean) || (mean <= 0))
127128
{
@@ -133,7 +134,7 @@ namespace boost
133134
return true;
134135
} // bool check_mean
135136
template <class RealType, class Policy>
136-
inline bool check_variance(const char* function, const RealType& variance, RealType* result, const Policy& pol)
137+
BOOST_MATH_GPU_ENABLED inline bool check_variance(const char* function, const RealType& variance, RealType* result, const Policy& pol)
137138
{
138139
if(!(boost::math::isfinite)(variance) || (variance <= 0))
139140
{
@@ -157,7 +158,7 @@ namespace boost
157158
typedef RealType value_type;
158159
typedef Policy policy_type;
159160

160-
beta_distribution(RealType l_alpha = 1, RealType l_beta = 1) : m_alpha(l_alpha), m_beta(l_beta)
161+
BOOST_MATH_GPU_ENABLED beta_distribution(RealType l_alpha = 1, RealType l_beta = 1) : m_alpha(l_alpha), m_beta(l_beta)
161162
{
162163
RealType result;
163164
beta_detail::check_dist(
@@ -167,11 +168,11 @@ namespace boost
167168
&result, Policy());
168169
} // beta_distribution constructor.
169170
// Accessor functions:
170-
RealType alpha() const
171+
BOOST_MATH_GPU_ENABLED RealType alpha() const
171172
{
172173
return m_alpha;
173174
}
174-
RealType beta() const
175+
BOOST_MATH_GPU_ENABLED RealType beta() const
175176
{ // .
176177
return m_beta;
177178
}
@@ -183,11 +184,11 @@ namespace boost
183184
// http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm
184185
// http://www.epi.ucdavis.edu/diagnostictests/betabuster.html
185186

186-
static RealType find_alpha(
187+
BOOST_MATH_GPU_ENABLED static RealType find_alpha(
187188
RealType mean, // Expected value of mean.
188189
RealType variance) // Expected value of variance.
189190
{
190-
static const char* function = "boost::math::beta_distribution<%1%>::find_alpha";
191+
constexpr auto function = "boost::math::beta_distribution<%1%>::find_alpha";
191192
RealType result = 0; // of error checks.
192193
if(false ==
193194
(
@@ -201,11 +202,11 @@ namespace boost
201202
return mean * (( (mean * (1 - mean)) / variance)- 1);
202203
} // RealType find_alpha
203204

204-
static RealType find_beta(
205+
BOOST_MATH_GPU_ENABLED static RealType find_beta(
205206
RealType mean, // Expected value of mean.
206207
RealType variance) // Expected value of variance.
207208
{
208-
static const char* function = "boost::math::beta_distribution<%1%>::find_beta";
209+
constexpr auto function = "boost::math::beta_distribution<%1%>::find_beta";
209210
RealType result = 0; // of error checks.
210211
if(false ==
211212
(
@@ -223,12 +224,12 @@ namespace boost
223224
// Estimate alpha & beta from either alpha or beta, and x and probability.
224225
// Uses for these parameter estimators are unclear.
225226

226-
static RealType find_alpha(
227+
BOOST_MATH_GPU_ENABLED static RealType find_alpha(
227228
RealType beta, // from beta.
228229
RealType x, // x.
229230
RealType probability) // cdf
230231
{
231-
static const char* function = "boost::math::beta_distribution<%1%>::find_alpha";
232+
constexpr auto function = "boost::math::beta_distribution<%1%>::find_alpha";
232233
RealType result = 0; // of error checks.
233234
if(false ==
234235
(
@@ -245,13 +246,13 @@ namespace boost
245246
return static_cast<RealType>(ibeta_inva(beta, x, probability, Policy()));
246247
} // RealType find_alpha(beta, a, probability)
247248

248-
static RealType find_beta(
249+
BOOST_MATH_GPU_ENABLED static RealType find_beta(
249250
// ibeta_invb(T b, T x, T p); (alpha, x, cdf,)
250251
RealType alpha, // alpha.
251252
RealType x, // probability x.
252253
RealType probability) // probability cdf.
253254
{
254-
static const char* function = "boost::math::beta_distribution<%1%>::find_beta";
255+
constexpr auto function = "boost::math::beta_distribution<%1%>::find_beta";
255256
RealType result = 0; // of error checks.
256257
if(false ==
257258
(
@@ -281,37 +282,37 @@ namespace boost
281282
#endif
282283

283284
template <class RealType, class Policy>
284-
inline const std::pair<RealType, RealType> range(const beta_distribution<RealType, Policy>& /* dist */)
285+
BOOST_MATH_GPU_ENABLED inline const boost::math::pair<RealType, RealType> range(const beta_distribution<RealType, Policy>& /* dist */)
285286
{ // Range of permissible values for random variable x.
286287
using boost::math::tools::max_value;
287-
return std::pair<RealType, RealType>(static_cast<RealType>(0), static_cast<RealType>(1));
288+
return boost::math::pair<RealType, RealType>(static_cast<RealType>(0), static_cast<RealType>(1));
288289
}
289290

290291
template <class RealType, class Policy>
291-
inline const std::pair<RealType, RealType> support(const beta_distribution<RealType, Policy>& /* dist */)
292+
BOOST_MATH_GPU_ENABLED inline const boost::math::pair<RealType, RealType> support(const beta_distribution<RealType, Policy>& /* dist */)
292293
{ // Range of supported values for random variable x.
293294
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
294-
return std::pair<RealType, RealType>(static_cast<RealType>(0), static_cast<RealType>(1));
295+
return boost::math::pair<RealType, RealType>(static_cast<RealType>(0), static_cast<RealType>(1));
295296
}
296297

297298
template <class RealType, class Policy>
298-
inline RealType mean(const beta_distribution<RealType, Policy>& dist)
299+
BOOST_MATH_GPU_ENABLED inline RealType mean(const beta_distribution<RealType, Policy>& dist)
299300
{ // Mean of beta distribution = np.
300301
return dist.alpha() / (dist.alpha() + dist.beta());
301302
} // mean
302303

303304
template <class RealType, class Policy>
304-
inline RealType variance(const beta_distribution<RealType, Policy>& dist)
305+
BOOST_MATH_GPU_ENABLED inline RealType variance(const beta_distribution<RealType, Policy>& dist)
305306
{ // Variance of beta distribution = np(1-p).
306307
RealType a = dist.alpha();
307308
RealType b = dist.beta();
308309
return (a * b) / ((a + b ) * (a + b) * (a + b + 1));
309310
} // variance
310311

311312
template <class RealType, class Policy>
312-
inline RealType mode(const beta_distribution<RealType, Policy>& dist)
313+
BOOST_MATH_GPU_ENABLED inline RealType mode(const beta_distribution<RealType, Policy>& dist)
313314
{
314-
static const char* function = "boost::math::mode(beta_distribution<%1%> const&)";
315+
constexpr auto function = "boost::math::mode(beta_distribution<%1%> const&)";
315316

316317
RealType result;
317318
if ((dist.alpha() <= 1))
@@ -343,7 +344,7 @@ namespace boost
343344
//But WILL be provided by the derived accessor as quantile(0.5).
344345

345346
template <class RealType, class Policy>
346-
inline RealType skewness(const beta_distribution<RealType, Policy>& dist)
347+
BOOST_MATH_GPU_ENABLED inline RealType skewness(const beta_distribution<RealType, Policy>& dist)
347348
{
348349
BOOST_MATH_STD_USING // ADL of std functions.
349350
RealType a = dist.alpha();
@@ -352,7 +353,7 @@ namespace boost
352353
} // skewness
353354

354355
template <class RealType, class Policy>
355-
inline RealType kurtosis_excess(const beta_distribution<RealType, Policy>& dist)
356+
BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess(const beta_distribution<RealType, Policy>& dist)
356357
{
357358
RealType a = dist.alpha();
358359
RealType b = dist.beta();
@@ -363,17 +364,17 @@ namespace boost
363364
} // kurtosis_excess
364365

365366
template <class RealType, class Policy>
366-
inline RealType kurtosis(const beta_distribution<RealType, Policy>& dist)
367+
BOOST_MATH_GPU_ENABLED inline RealType kurtosis(const beta_distribution<RealType, Policy>& dist)
367368
{
368369
return 3 + kurtosis_excess(dist);
369370
} // kurtosis
370371

371372
template <class RealType, class Policy>
372-
inline RealType pdf(const beta_distribution<RealType, Policy>& dist, const RealType& x)
373+
BOOST_MATH_GPU_ENABLED inline RealType pdf(const beta_distribution<RealType, Policy>& dist, const RealType& x)
373374
{ // Probability Density/Mass Function.
374375
BOOST_FPU_EXCEPTION_GUARD
375376

376-
static const char* function = "boost::math::pdf(beta_distribution<%1%> const&, %1%)";
377+
constexpr auto function = "boost::math::pdf(beta_distribution<%1%> const&, %1%)";
377378

378379
BOOST_MATH_STD_USING // for ADL of std functions
379380

@@ -428,11 +429,11 @@ namespace boost
428429
} // pdf
429430

430431
template <class RealType, class Policy>
431-
inline RealType cdf(const beta_distribution<RealType, Policy>& dist, const RealType& x)
432+
BOOST_MATH_GPU_ENABLED inline RealType cdf(const beta_distribution<RealType, Policy>& dist, const RealType& x)
432433
{ // Cumulative Distribution Function beta.
433434
BOOST_MATH_STD_USING // for ADL of std functions
434435

435-
static const char* function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)";
436+
constexpr auto function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)";
436437

437438
RealType a = dist.alpha();
438439
RealType b = dist.beta();
@@ -459,12 +460,12 @@ namespace boost
459460
} // beta cdf
460461

461462
template <class RealType, class Policy>
462-
inline RealType cdf(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
463+
BOOST_MATH_GPU_ENABLED inline RealType cdf(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
463464
{ // Complemented Cumulative Distribution Function beta.
464465

465466
BOOST_MATH_STD_USING // for ADL of std functions
466467

467-
static const char* function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)";
468+
constexpr auto function = "boost::math::cdf(beta_distribution<%1%> const&, %1%)";
468469

469470
RealType const& x = c.param;
470471
beta_distribution<RealType, Policy> const& dist = c.dist;
@@ -495,7 +496,7 @@ namespace boost
495496
} // beta cdf
496497

497498
template <class RealType, class Policy>
498-
inline RealType quantile(const beta_distribution<RealType, Policy>& dist, const RealType& p)
499+
BOOST_MATH_GPU_ENABLED inline RealType quantile(const beta_distribution<RealType, Policy>& dist, const RealType& p)
499500
{ // Quantile or Percent Point beta function or
500501
// Inverse Cumulative probability distribution function CDF.
501502
// Return x (0 <= x <= 1),
@@ -505,7 +506,7 @@ namespace boost
505506
// will be less than or equal to that value
506507
// is whatever probability you supplied as an argument.
507508

508-
static const char* function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)";
509+
constexpr auto function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)";
509510

510511
RealType result = 0; // of argument checks:
511512
RealType a = dist.alpha();
@@ -530,12 +531,12 @@ namespace boost
530531
} // quantile
531532

532533
template <class RealType, class Policy>
533-
inline RealType quantile(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
534+
BOOST_MATH_GPU_ENABLED inline RealType quantile(const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
534535
{ // Complement Quantile or Percent Point beta function .
535536
// Return the number of expected x for a given
536537
// complement of the probability q.
537538

538-
static const char* function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)";
539+
constexpr auto function = "boost::math::quantile(beta_distribution<%1%> const&, %1%)";
539540

540541
//
541542
// Error checks:

include/boost/math/policies/error_handling.hpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <boost/math/tools/numeric_limits.hpp>
1313
#include <boost/math/tools/type_traits.hpp>
1414
#include <boost/math/tools/cstdint.hpp>
15+
#include <boost/math/tools/tuple.hpp>
1516

1617
#ifndef BOOST_MATH_HAS_NVRTC
1718

@@ -877,20 +878,6 @@ BOOST_MATH_GPU_ENABLED inline void check_root_iterations(const char* function, s
877878

878879
} //namespace policies
879880

880-
namespace detail{
881-
882-
//
883-
// Simple helper function to assist in returning a pair from a single value,
884-
// that value usually comes from one of the error handlers above:
885-
//
886-
template <class T>
887-
BOOST_MATH_GPU_ENABLED std::pair<T, T> pair_from_single(const T& val) BOOST_MATH_NOEXCEPT(T)
888-
{
889-
return std::make_pair(val, val);
890-
}
891-
892-
}
893-
894881
#ifdef _MSC_VER
895882
# pragma warning(pop)
896883
#endif
@@ -1039,7 +1026,21 @@ BOOST_MATH_GPU_ENABLED inline void check_root_iterations(const char* function, b
10391026
} // namespace math
10401027
} // namespace boost
10411028

1042-
#endif
1029+
#endif // BOOST_MATH_HAS_NVRTC
1030+
1031+
namespace boost { namespace math { namespace detail {
1032+
1033+
//
1034+
// Simple helper function to assist in returning a pair from a single value,
1035+
// that value usually comes from one of the error handlers above:
1036+
//
1037+
template <class T>
1038+
BOOST_MATH_GPU_ENABLED boost::math::pair<T, T> pair_from_single(const T& val) BOOST_MATH_NOEXCEPT(T)
1039+
{
1040+
return boost::math::make_pair(val, val);
1041+
}
1042+
1043+
}}} // boost::math::detail
10431044

10441045
#endif // BOOST_MATH_POLICY_ERROR_HANDLING_HPP
10451046

0 commit comments

Comments
 (0)