Skip to content

Commit

Permalink
Merge pull request #1191 from boostorg/gpu_docs
Browse files Browse the repository at this point in the history
Begin documenting GPU support
  • Loading branch information
mborland authored Sep 6, 2024
2 parents 54c229b + 45c7741 commit 1e9b2cc
Show file tree
Hide file tree
Showing 42 changed files with 379 additions and 269 deletions.
5 changes: 5 additions & 0 deletions doc/constants/constants.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ either construct from a decimal digit string or calculate on the fly depending u
[[Any other value ['N]][Sets the compile time precision to ['N] bits.]]
]

[h5 GPU Support]

All Boost.Math constants are marked with `BOOST_MATH_GPU_ENABLED` and can be used on both host and device.
Note that when running on device you are limited to using only `float` and `double` types.

[h5 Custom Specializing a constant]

In addition, for user-defined types that need special handling, it's possible to partially-specialize
Expand Down
12 changes: 7 additions & 5 deletions doc/distributions/arcsine.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
typedef Policy policy_type;

// Constructor from two range parameters, x_min and x_max:
arcsine_distribution(RealType x_min = 0, RealType x_max = 1);
BOOST_MATH_GPU_ENABLED arcsine_distribution(RealType x_min = 0, RealType x_max = 1);

// Range Parameter accessors:
RealType x_min() const;
RealType x_max() const;
BOOST_MATH_GPU_ENABLED RealType x_min() const;
BOOST_MATH_GPU_ENABLED RealType x_max() const;
};
}} // namespaces

Expand Down Expand Up @@ -103,8 +103,8 @@ constructs a 'Standard 01' arcsine distribution.

[h5 Parameter Accessors]

RealType x_min() const;
RealType x_max() const;
BOOST_MATH_GPU_ENABLED RealType x_min() const;
BOOST_MATH_GPU_ENABLED RealType x_max() const;

Return the parameter ['x_min] or ['x_max] from which this distribution was constructed.

Expand All @@ -116,6 +116,8 @@ So, for example:

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

The formulae for calculating these are shown in the table below, and at
[@http://mathworld.wolfram.com/arcsineDistribution.html Wolfram Mathworld].
Expand Down
10 changes: 6 additions & 4 deletions doc/distributions/bernoulli.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
typedef RealType value_type;
typedef Policy policy_type;

bernoulli_distribution(RealType p); // Constructor.
BOOST_MATH_GPU_ENABLED bernoulli_distribution(RealType p); // Constructor.
// Accessor function.
RealType success_fraction() const
BOOST_MATH_GPU_ENABLED RealType success_fraction() const
// Probability of success (as a fraction).
};
}} // namespaces
Expand Down Expand Up @@ -51,19 +51,21 @@ and the [@http://en.wikipedia.org/wiki/Cumulative_Distribution_Function Cumulati

[h4 Member Functions]

bernoulli_distribution(RealType p);
BOOST_MATH_GPU_ENABLED bernoulli_distribution(RealType p);

Constructs a [@http://en.wikipedia.org/wiki/bernoulli_distribution
bernoulli distribution] with success_fraction /p/.

RealType success_fraction() const
BOOST_MATH_GPU_ENABLED RealType success_fraction() const

Returns the /success_fraction/ parameter of this distribution.

[h4 Non-member Accessors]

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

The domain of the random variable is 0 and 1,
and the useful supported range is only 0 or 1.
Expand Down
22 changes: 12 additions & 10 deletions doc/distributions/beta.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@
typedef RealType value_type;
typedef Policy policy_type;
// Constructor from two shape parameters, alpha & beta:
beta_distribution(RealType a, RealType b);
BOOST_MATH_GPU_ENABLED beta_distribution(RealType a, RealType b);

// Parameter accessors:
RealType alpha() const;
RealType beta() const;
BOOST_MATH_GPU_ENABLED RealType alpha() const;
BOOST_MATH_GPU_ENABLED RealType beta() const;

// Parameter estimators of alpha or beta from mean and variance.
static RealType find_alpha(
BOOST_MATH_GPU_ENABLED static RealType find_alpha(
RealType mean, // Expected value of mean.
RealType variance); // Expected value of variance.

static RealType find_beta(
BOOST_MATH_GPU_ENABLED static RealType find_beta(
RealType mean, // Expected value of mean.
RealType variance); // Expected value of variance.

// Parameter estimators from
// either alpha or beta, and x and probability.

static RealType find_alpha(
BOOST_MATH_GPU_ENABLED static RealType find_alpha(
RealType beta, // from beta.
RealType x, // x.
RealType probability); // cdf

static RealType find_beta(
BOOST_MATH_GPU_ENABLED static RealType find_beta(
RealType alpha, // alpha.
RealType x, // probability x.
RealType probability); // probability cdf.
Expand Down Expand Up @@ -98,7 +98,7 @@ whose apex is away from the centre (where x = half).

[h5 Constructor]

beta_distribution(RealType alpha, RealType beta);
BOOST_MATH_GPU_ENABLED beta_distribution(RealType alpha, RealType beta);

Constructs a beta distribution with shape parameters /alpha/ and /beta/.

Expand All @@ -117,11 +117,11 @@ in the graph above).

[h5 Parameter Accessors]

RealType alpha() const;
BOOST_MATH_GPU_ENABLED RealType alpha() const;

Returns the parameter /alpha/ from which this distribution was constructed.

RealType beta() const;
BOOST_MATH_GPU_ENABLED RealType beta() const;

Returns the parameter /beta/ from which this distribution was constructed.

Expand Down Expand Up @@ -182,6 +182,8 @@ Returns the value of [beta] that gives:

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

The formulae for calculating these are shown in the table below, and at
[@http://mathworld.wolfram.com/BetaDistribution.html Wolfram Mathworld].
Expand Down
14 changes: 8 additions & 6 deletions doc/distributions/cauchy.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
typedef RealType value_type;
typedef Policy policy_type;

cauchy_distribution(RealType location = 0, RealType scale = 1);
BOOST_MATH_GPU_ENABLED cauchy_distribution(RealType location = 0, RealType scale = 1);

RealType location()const;
RealType scale()const;
BOOST_MATH_GPU_ENABLED RealType location()const;
BOOST_MATH_GPU_ENABLED RealType scale()const;
};

The [@http://en.wikipedia.org/wiki/Cauchy_distribution Cauchy-Lorentz distribution]
Expand Down Expand Up @@ -53,7 +53,7 @@ the distribution:

[h4 Member Functions]

cauchy_distribution(RealType location = 0, RealType scale = 1);
BOOST_MATH_GPU_ENABLED cauchy_distribution(RealType location = 0, RealType scale = 1);

Constructs a Cauchy distribution, with location parameter /location/
and scale parameter /scale/. When these parameters take their default
Expand All @@ -62,18 +62,20 @@ then the result is a Standard Cauchy Distribution.

Requires scale > 0, otherwise calls __domain_error.

RealType location()const;
BOOST_MATH_GPU_ENABLED RealType location()const;

Returns the location parameter of the distribution.

RealType scale()const;
BOOST_MATH_GPU_ENABLED RealType scale()const;

Returns the scale parameter of the distribution.

[h4 Non-member Accessors]

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

Note however that the Cauchy distribution does not have a mean,
standard deviation, etc. See __math_undefined
Expand Down
8 changes: 5 additions & 3 deletions doc/distributions/chi_squared.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
typedef Policy policy_type;

// Constructor:
chi_squared_distribution(RealType i);
BOOST_MATH_GPU_ENABLED chi_squared_distribution(RealType i);

// Accessor to parameter:
RealType degrees_of_freedom()const;
BOOST_MATH_GPU_ENABLED RealType degrees_of_freedom()const;

// Parameter estimation:
static RealType find_degrees_of_freedom(
BOOST_MATH_GPU_ENABLED static RealType find_degrees_of_freedom(
RealType difference_from_mean,
RealType alpha,
RealType beta,
Expand Down Expand Up @@ -104,6 +104,8 @@ See also section on Sample sizes required in

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

(We have followed the usual restriction of the mode to degrees of freedom >= 2,
but note that the maximum of the pdf is actually zero for degrees of freedom from 2 down to 0,
Expand Down
10 changes: 6 additions & 4 deletions doc/distributions/exponential.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
typedef RealType value_type;
typedef Policy policy_type;

exponential_distribution(RealType lambda = 1);
BOOST_MATH_GPU_ENABLED exponential_distribution(RealType lambda = 1);

RealType lambda()const;
BOOST_MATH_GPU_ENABLED RealType lambda()const;
};


Expand All @@ -37,7 +37,7 @@ values of the rate parameter lambda:

[h4 Member Functions]

exponential_distribution(RealType lambda = 1);
BOOST_MATH_GPU_ENABLED exponential_distribution(RealType lambda = 1);

Constructs an
[@http://en.wikipedia.org/wiki/Exponential_distribution Exponential distribution]
Expand All @@ -46,14 +46,16 @@ Lambda is defined as the reciprocal of the scale parameter.

Requires lambda > 0, otherwise calls __domain_error.

RealType lambda()const;
BOOST_MATH_GPU_ENABLED RealType lambda()const;

Accessor function returns the lambda parameter of the distribution.

[h4 Non-member Accessors]

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

The domain of the random variable is \[0, +[infin]\].

Expand Down
14 changes: 8 additions & 6 deletions doc/distributions/extreme_value.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
public:
typedef RealType value_type;

extreme_value_distribution(RealType location = 0, RealType scale = 1);
BOOST_MATH_GPU_ENABLED extreme_value_distribution(RealType location = 0, RealType scale = 1);

RealType scale()const;
RealType location()const;
BOOST_MATH_GPU_ENABLED RealType scale()const;
BOOST_MATH_GPU_ENABLED RealType location()const;
};

There are various
Expand Down Expand Up @@ -59,25 +59,27 @@ And this graph illustrates how the PDF varies with the shape parameter:

[h4 Member Functions]

extreme_value_distribution(RealType location = 0, RealType scale = 1);
BOOST_MATH_GPU_ENABLED extreme_value_distribution(RealType location = 0, RealType scale = 1);

Constructs an Extreme Value distribution with the specified location and scale
parameters.

Requires `scale > 0`, otherwise calls __domain_error.

RealType location()const;
BOOST_MATH_GPU_ENABLED RealType location()const;

Returns the location parameter of the distribution.

RealType scale()const;
BOOST_MATH_GPU_ENABLED RealType scale()const;

Returns the scale parameter of the distribution.

[h4 Non-member Accessors]

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

The domain of the random parameter is \[-[infin], +[infin]\].

Expand Down
14 changes: 8 additions & 6 deletions doc/distributions/fisher.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
typedef RealType value_type;

// Construct:
fisher_f_distribution(const RealType& i, const RealType& j);
BOOST_MATH_GPU_ENABLED fisher_f_distribution(const RealType& i, const RealType& j);

// Accessors:
RealType degrees_of_freedom1()const;
RealType degrees_of_freedom2()const;
BOOST_MATH_GPU_ENABLED RealType degrees_of_freedom1()const;
BOOST_MATH_GPU_ENABLED RealType degrees_of_freedom2()const;
};

}} //namespaces
Expand All @@ -46,26 +46,28 @@ two degrees of freedom parameters.

[h4 Member Functions]

fisher_f_distribution(const RealType& df1, const RealType& df2);
BOOST_MATH_GPU_ENABLED fisher_f_distribution(const RealType& df1, const RealType& df2);

Constructs an F-distribution with numerator degrees of freedom /df1/
and denominator degrees of freedom /df2/.

Requires that /df1/ and /df2/ are both greater than zero, otherwise __domain_error
is called.

RealType degrees_of_freedom1()const;
BOOST_MATH_GPU_ENABLED RealType degrees_of_freedom1()const;

Returns the numerator degrees of freedom parameter of the distribution.

RealType degrees_of_freedom2()const;
BOOST_MATH_GPU_ENABLED RealType degrees_of_freedom2()const;

Returns the denominator degrees of freedom parameter of the distribution.

[h4 Non-member Accessors]

All the [link math_toolkit.dist_ref.nmp usual non-member accessor functions]
that are generic to all distributions are supported: __usual_accessors.
For this distribution all non-member accessor functions are marked with `BOOST_MATH_GPU_ENABLED` and can
be run on both host and device.

The domain of the random variable is \[0, +[infin]\].

Expand Down
Loading

0 comments on commit 1e9b2cc

Please sign in to comment.