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 7.1 Testing #18

Merged
merged 40 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fff5aa6
Remove NVRTC workaround from log1p
mborland Aug 21, 2024
08895c7
Fix igamma_large support on device
mborland Aug 26, 2024
a2b568b
Add GPU support to toms748
mborland Aug 21, 2024
94ca4c8
Add GPU support to igamma_inv
mborland Aug 21, 2024
bbbf599
Add GPU markers to gamma_inva
mborland Aug 21, 2024
e5feb47
Add GPU Markers to lgamma_small
mborland Aug 26, 2024
4fa7d1c
Remove STL usage from gamma
mborland Aug 26, 2024
e7fd6bf
Remove NVRTC workaround
mborland Aug 26, 2024
c3fefdd
Fix fraction use of STL headers
mborland Aug 26, 2024
1deb121
Mark gamma functions in fwd
mborland Aug 26, 2024
5e8626f
Disable declval on all GPU platforms
mborland Aug 26, 2024
8c118c5
Disable more unneeded code on device
mborland Aug 26, 2024
e74868b
Add forward decl for NVRTC tgamma
mborland Aug 26, 2024
0342f48
Disable unneeded items for all GPU
mborland Aug 27, 2024
93963a4
Change workaround for missing overloads
mborland Aug 27, 2024
47420a5
Rearrange definition location
mborland Aug 27, 2024
77610af
Add include path to cuda now that workaround is removed
mborland Aug 27, 2024
3c28068
Fix NVRTC incompatibility with recursion and forward decls
mborland Aug 27, 2024
50cfb76
Add tgamma_ratio CUDA and NVRTC testing
mborland Aug 27, 2024
28bbccf
Fix NVRTC handling of gamma_p_derivative
mborland Aug 27, 2024
c1ffaf4
Add gamma_p_derivative CUDA and NVRTC testing
mborland Aug 27, 2024
a17a7db
Remove recursion from gamma_incomplete_imp
mborland Aug 27, 2024
8914b43
Add SYCL testing of igamma, igamma_inv, and igamma_inva
mborland Aug 27, 2024
009b62e
Ignore literal-range warnings
mborland Aug 27, 2024
13c3df7
Remove use of static const char* for function name
mborland Aug 27, 2024
e9f40ea
Fix missing CUDA header
mborland Aug 27, 2024
930e551
Remove calls under NVRTC to fwd decl
mborland Aug 27, 2024
4cf03c5
Add more nvrtc workarounds
mborland Aug 27, 2024
a0cfbd4
Use builtin erfc instead of header cycle
mborland Aug 27, 2024
1d6b97f
Add CUDA and NVRTC testing of gamma_p_inv
mborland Aug 27, 2024
51f9975
Adjust tolerances
mborland Aug 27, 2024
e218f32
Add GPU support to chi squared dist
mborland Aug 27, 2024
a8ecdc4
Fix static local variable
mborland Aug 27, 2024
8119593
Add chi squared dist SYCL testing
mborland Aug 27, 2024
90e201b
Add chi squared dist CUDA testing
mborland Aug 27, 2024
17cd533
Add chi squared dist NVRTC testing
mborland Aug 27, 2024
2199d55
Add GPU support to weibull dist
mborland Aug 27, 2024
8ff4b3a
Add weibull dist SYCL testing
mborland Aug 27, 2024
04a0449
Add weibull dist CUDA testing
mborland Aug 27, 2024
c5e7637
Add weibull dist NVRTC testing
mborland Aug 27, 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
71 changes: 37 additions & 34 deletions include/boost/math/distributions/chi_squared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@
#ifndef BOOST_MATH_DISTRIBUTIONS_CHI_SQUARED_HPP
#define BOOST_MATH_DISTRIBUTIONS_CHI_SQUARED_HPP

#include <boost/math/tools/config.hpp>
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/tools/numeric_limits.hpp>
#include <boost/math/tools/cstdint.hpp>
#include <boost/math/tools/toms748_solve.hpp>
#include <boost/math/distributions/fwd.hpp>
#include <boost/math/special_functions/gamma.hpp> // for incomplete beta.
#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>

#include <utility>

namespace boost{ namespace math{

template <class RealType = double, class Policy = policies::policy<> >
Expand All @@ -26,20 +29,20 @@ class chi_squared_distribution
using value_type = RealType;
using policy_type = Policy;

explicit chi_squared_distribution(RealType i) : m_df(i)
BOOST_MATH_GPU_ENABLED explicit chi_squared_distribution(RealType i) : m_df(i)
{
RealType result;
detail::check_df(
"boost::math::chi_squared_distribution<%1%>::chi_squared_distribution", m_df, &result, Policy());
} // chi_squared_distribution

RealType degrees_of_freedom()const
BOOST_MATH_GPU_ENABLED RealType degrees_of_freedom()const
{
return m_df;
}

// Parameter estimation:
static RealType find_degrees_of_freedom(
BOOST_MATH_GPU_ENABLED static RealType find_degrees_of_freedom(
RealType difference_from_variance,
RealType alpha,
RealType beta,
Expand All @@ -66,16 +69,16 @@ chi_squared_distribution(RealType)->chi_squared_distribution<typename boost::mat
#endif

template <class RealType, class Policy>
inline std::pair<RealType, RealType> range(const chi_squared_distribution<RealType, Policy>& /*dist*/)
BOOST_MATH_GPU_ENABLED inline boost::math::pair<RealType, RealType> range(const chi_squared_distribution<RealType, Policy>& /*dist*/)
{ // Range of permissible values for random variable x.
if (std::numeric_limits<RealType>::has_infinity)
BOOST_MATH_IF_CONSTEXPR (boost::math::numeric_limits<RealType>::has_infinity)
{
return std::pair<RealType, RealType>(static_cast<RealType>(0), std::numeric_limits<RealType>::infinity()); // 0 to + infinity.
return boost::math::pair<RealType, RealType>(static_cast<RealType>(0), boost::math::numeric_limits<RealType>::infinity()); // 0 to + infinity.
}
else
{
using boost::math::tools::max_value;
return std::pair<RealType, RealType>(static_cast<RealType>(0), max_value<RealType>()); // 0 to + max.
return boost::math::pair<RealType, RealType>(static_cast<RealType>(0), max_value<RealType>()); // 0 to + max.
}
}

Expand All @@ -84,21 +87,21 @@ inline std::pair<RealType, RealType> range(const chi_squared_distribution<RealTy
#endif

template <class RealType, class Policy>
inline std::pair<RealType, RealType> support(const chi_squared_distribution<RealType, Policy>& /*dist*/)
BOOST_MATH_GPU_ENABLED inline boost::math::pair<RealType, RealType> support(const chi_squared_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>(0), tools::max_value<RealType>()); // 0 to + infinity.
return boost::math::pair<RealType, RealType>(static_cast<RealType>(0), tools::max_value<RealType>()); // 0 to + infinity.
}

template <class RealType, class Policy>
RealType pdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square)
BOOST_MATH_GPU_ENABLED RealType pdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square)
{
BOOST_MATH_STD_USING // for ADL of std functions
RealType degrees_of_freedom = dist.degrees_of_freedom();
// Error check:
RealType error_result;

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

if(false == detail::check_df(
function, degrees_of_freedom, &error_result, Policy()))
Expand Down Expand Up @@ -132,12 +135,12 @@ RealType pdf(const chi_squared_distribution<RealType, Policy>& dist, const RealT
} // pdf

template <class RealType, class Policy>
inline RealType cdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square)
BOOST_MATH_GPU_ENABLED inline RealType cdf(const chi_squared_distribution<RealType, Policy>& dist, const RealType& chi_square)
{
RealType degrees_of_freedom = dist.degrees_of_freedom();
// Error check:
RealType error_result;
static const char* function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)";
constexpr auto function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)";

if(false == detail::check_df(
function, degrees_of_freedom, &error_result, Policy()))
Expand All @@ -153,10 +156,10 @@ inline RealType cdf(const chi_squared_distribution<RealType, Policy>& dist, cons
} // cdf

template <class RealType, class Policy>
inline RealType quantile(const chi_squared_distribution<RealType, Policy>& dist, const RealType& p)
BOOST_MATH_GPU_ENABLED inline RealType quantile(const chi_squared_distribution<RealType, Policy>& dist, const RealType& p)
{
RealType degrees_of_freedom = dist.degrees_of_freedom();
static const char* function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)";
constexpr auto function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)";
// Error check:
RealType error_result;
if(false ==
Expand All @@ -170,11 +173,11 @@ inline RealType quantile(const chi_squared_distribution<RealType, Policy>& dist,
} // quantile

template <class RealType, class Policy>
inline RealType cdf(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_GPU_ENABLED inline RealType cdf(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c)
{
RealType const& degrees_of_freedom = c.dist.degrees_of_freedom();
RealType const& chi_square = c.param;
static const char* function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)";
constexpr auto function = "boost::math::cdf(const chi_squared_distribution<%1%>&, %1%)";
// Error check:
RealType error_result;
if(false == detail::check_df(
Expand All @@ -191,11 +194,11 @@ inline RealType cdf(const complemented2_type<chi_squared_distribution<RealType,
}

template <class RealType, class Policy>
inline RealType quantile(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_GPU_ENABLED inline RealType quantile(const complemented2_type<chi_squared_distribution<RealType, Policy>, RealType>& c)
{
RealType const& degrees_of_freedom = c.dist.degrees_of_freedom();
RealType const& q = c.param;
static const char* function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)";
constexpr auto function = "boost::math::quantile(const chi_squared_distribution<%1%>&, %1%)";
// Error check:
RealType error_result;
if(false == (
Expand All @@ -208,22 +211,22 @@ inline RealType quantile(const complemented2_type<chi_squared_distribution<RealT
}

template <class RealType, class Policy>
inline RealType mean(const chi_squared_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType mean(const chi_squared_distribution<RealType, Policy>& dist)
{ // Mean of Chi-Squared distribution = v.
return dist.degrees_of_freedom();
} // mean

template <class RealType, class Policy>
inline RealType variance(const chi_squared_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType variance(const chi_squared_distribution<RealType, Policy>& dist)
{ // Variance of Chi-Squared distribution = 2v.
return 2 * dist.degrees_of_freedom();
} // variance

template <class RealType, class Policy>
inline RealType mode(const chi_squared_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType mode(const chi_squared_distribution<RealType, Policy>& dist)
{
RealType df = dist.degrees_of_freedom();
static const char* function = "boost::math::mode(const chi_squared_distribution<%1%>&)";
constexpr auto function = "boost::math::mode(const chi_squared_distribution<%1%>&)";

if(df < 2)
return policies::raise_domain_error<RealType>(
Expand All @@ -234,22 +237,22 @@ inline RealType mode(const chi_squared_distribution<RealType, Policy>& dist)
}

template <class RealType, class Policy>
inline RealType skewness(const chi_squared_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType skewness(const chi_squared_distribution<RealType, Policy>& dist)
{
BOOST_MATH_STD_USING // For ADL
RealType df = dist.degrees_of_freedom();
return sqrt (8 / df);
}

template <class RealType, class Policy>
inline RealType kurtosis(const chi_squared_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType kurtosis(const chi_squared_distribution<RealType, Policy>& dist)
{
RealType df = dist.degrees_of_freedom();
return 3 + 12 / df;
}

template <class RealType, class Policy>
inline RealType kurtosis_excess(const chi_squared_distribution<RealType, Policy>& dist)
BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess(const chi_squared_distribution<RealType, Policy>& dist)
{
RealType df = dist.degrees_of_freedom();
return 12 / df;
Expand All @@ -264,12 +267,12 @@ namespace detail
template <class RealType, class Policy>
struct df_estimator
{
df_estimator(RealType a, RealType b, RealType variance, RealType delta)
BOOST_MATH_GPU_ENABLED df_estimator(RealType a, RealType b, RealType variance, RealType delta)
: alpha(a), beta(b), ratio(delta/variance)
{ // Constructor
}

RealType operator()(const RealType& df)
BOOST_MATH_GPU_ENABLED RealType operator()(const RealType& df)
{
if(df <= tools::min_value<RealType>())
return 1;
Expand Down Expand Up @@ -297,14 +300,14 @@ struct df_estimator
} // namespace detail

template <class RealType, class Policy>
RealType chi_squared_distribution<RealType, Policy>::find_degrees_of_freedom(
BOOST_MATH_GPU_ENABLED RealType chi_squared_distribution<RealType, Policy>::find_degrees_of_freedom(
RealType difference_from_variance,
RealType alpha,
RealType beta,
RealType variance,
RealType hint)
{
static const char* function = "boost::math::chi_squared_distribution<%1%>::find_degrees_of_freedom(%1%,%1%,%1%,%1%,%1%)";
constexpr auto function = "boost::math::chi_squared_distribution<%1%>::find_degrees_of_freedom(%1%,%1%,%1%,%1%,%1%)";
// Check for domain errors:
RealType error_result;
if(false ==
Expand All @@ -321,8 +324,8 @@ RealType chi_squared_distribution<RealType, Policy>::find_degrees_of_freedom(

detail::df_estimator<RealType, Policy> f(alpha, beta, variance, difference_from_variance);
tools::eps_tolerance<RealType> tol(policies::digits<RealType, Policy>());
std::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
std::pair<RealType, RealType> r =
boost::math::uintmax_t max_iter = policies::get_max_root_iterations<Policy>();
boost::math::pair<RealType, RealType> r =
tools::bracket_and_solve_root(f, hint, RealType(2), false, tol, max_iter, Policy());
RealType result = r.first + (r.second - r.first) / 2;
if(max_iter >= policies::get_max_root_iterations<Policy>())
Expand Down
Loading