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 implementation of AFT survival objective and metric #5714

Merged
merged 27 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
03aa30f
Add interval accuracy
hcho3 May 17, 2020
581ab43
De-virtualize AFT functions
hcho3 May 27, 2020
0d8d222
Lint
hcho3 May 27, 2020
4a5256e
Refactor AFT metric using GPU-CPU reducer
hcho3 May 27, 2020
9d69166
Fix R build
hcho3 May 27, 2020
b003dab
Fix build on Windows
hcho3 May 27, 2020
567e9a9
Fix copyright header
hcho3 May 27, 2020
4912e83
Clang-tidy
hcho3 May 27, 2020
bc242e9
Fix crashing demo
hcho3 May 28, 2020
136de6f
Merge remote-tracking branch 'origin/master' into gpu_aft
hcho3 May 28, 2020
29bbccd
Fix typos in comment; explain GPU ID
hcho3 May 28, 2020
5b2b067
Remove unnecessary #include
hcho3 May 28, 2020
46ccd2b
Add C++ test for interval accuracy
hcho3 May 28, 2020
cebd3d3
Fix a bug in accuracy metric: use log pred
hcho3 May 28, 2020
afe1702
Refactor AFT objective using GPU-CPU Transform
hcho3 May 28, 2020
f200dfa
Merge remote-tracking branch 'upstream/master' into gpu_aft
hcho3 Jun 5, 2020
f2a9474
Lint
hcho3 Jun 5, 2020
82f418f
Merge remote-tracking branch 'origin/master' into gpu_aft
hcho3 Jul 7, 2020
3ece12c
Fix lint
hcho3 Jul 7, 2020
4e2b998
Use Ninja to speed up build
hcho3 Jul 7, 2020
0664d0e
Use time, not /usr/bin/time
hcho3 Jul 7, 2020
5ef9ca5
Add cpu_build worker class, with concurrency = 1
hcho3 Jul 7, 2020
c8ce9f6
Use concurrency = 1 only for CUDA build
hcho3 Jul 7, 2020
5b277a8
concurrency = 1 for clang-tidy
hcho3 Jul 7, 2020
e1b5f47
Merge remote-tracking branch 'origin/master' into gpu_aft
hcho3 Jul 14, 2020
b4ae6ab
Address reviewer's feedback
hcho3 Jul 14, 2020
a85fd5e
Update link to AFT paper
hcho3 Jul 14, 2020
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 Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def checkoutSrcs() {
}

def ClangTidy() {
node('linux && cpu') {
node('linux && cpu_build') {
unstash name: 'srcs'
echo "Running clang-tidy job..."
def container_type = "clang_tidy"
Expand Down Expand Up @@ -238,7 +238,7 @@ def BuildCPUNonOmp() {
}

def BuildCUDA(args) {
node('linux && cpu') {
node('linux && cpu_build') {
unstash name: 'srcs'
echo "Build with CUDA ${args.cuda_version}"
def container_type = "gpu_build"
Expand Down
1 change: 0 additions & 1 deletion amalgamation/xgboost-all0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
#include "../src/common/json.cc"
#include "../src/common/io.cc"
#include "../src/common/survival_util.cc"
#include "../src/common/probability_distribution.cc"
#include "../src/common/version.cc"

// c_api
Expand Down
107 changes: 0 additions & 107 deletions src/common/probability_distribution.cc

This file was deleted.

169 changes: 109 additions & 60 deletions src/common/probability_distribution.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Copyright 2020 by Contributors
* Copyright 2019-2020 by Contributors
* \file probability_distribution.h
* \brief Implementation of a few useful probability distributions
* \author Avinash Barnwal and Hyunsu Cho
Expand All @@ -8,15 +8,26 @@
#ifndef XGBOOST_COMMON_PROBABILITY_DISTRIBUTION_H_
#define XGBOOST_COMMON_PROBABILITY_DISTRIBUTION_H_

#include <cmath>

namespace xgboost {
namespace common {

#ifndef __CUDACC__

using std::exp;
trivialfis marked this conversation as resolved.
Show resolved Hide resolved
using std::sqrt;
using std::isinf;
using std::isnan;

#endif // __CUDACC__

namespace probability_constant {

/*! \brief Constant PI */
const double kPI = 3.14159265358979323846;
constexpr double kPI = 3.14159265358979323846;
hcho3 marked this conversation as resolved.
Show resolved Hide resolved
/*! \brief The Euler-Mascheroni_constant */
const double kEulerMascheroni = 0.57721566490153286060651209008240243104215933593992;
constexpr double kEulerMascheroni = 0.57721566490153286060651209008240243104215933593992;

} // namespace probability_constant

Expand All @@ -25,68 +36,106 @@ enum class ProbabilityDistributionType : int {
kNormal = 0, kLogistic = 1, kExtreme = 2
};

/*! \brief Interface for a probability distribution */
class ProbabilityDistribution {
public:
/*!
* \brief Evaluate Probability Density Function (PDF) at a particular point
* \param z point at which to evaluate PDF
* \return Value of PDF evaluated
*/
virtual double PDF(double z) = 0;
/*!
* \brief Evaluate Cumulative Distribution Function (CDF) at a particular point
* \param z point at which to evaluate CDF
* \return Value of CDF evaluated
*/
virtual double CDF(double z) = 0;
/*!
* \brief Evaluate first derivative of PDF at a particular point
* \param z point at which to evaluate first derivative of PDF
* \return Value of first derivative of PDF evaluated
*/
virtual double GradPDF(double z) = 0;
/*!
* \brief Evaluate second derivative of PDF at a particular point
* \param z point at which to evaluate second derivative of PDF
* \return Value of second derivative of PDF evaluated
*/
virtual double HessPDF(double z) = 0;

/*!
* \brief Factory function to instantiate a new probability distribution object
* \param dist kind of probability distribution
* \return Reference to the newly created probability distribution object
*/
static ProbabilityDistribution* Create(ProbabilityDistributionType dist);
virtual ~ProbabilityDistribution() = default;
};
struct NormalDistribution {
XGBOOST_DEVICE inline static
double PDF(double z) {
return exp(-z * z / 2.0) / sqrt(2.0 * probability_constant::kPI);
}

XGBOOST_DEVICE inline static
double CDF(double z) {
return 0.5 * (1 + erf(z / sqrt(2.0)));
}

XGBOOST_DEVICE inline static
double GradPDF(double z) {
return -z * PDF(z);
}

XGBOOST_DEVICE inline static
double HessPDF(double z) {
return (z * z - 1.0) * PDF(z);
}

/*! \brief The (standard) normal distribution */
class NormalDist : public ProbabilityDistribution {
public:
double PDF(double z) override;
double CDF(double z) override;
double GradPDF(double z) override;
double HessPDF(double z) override;
XGBOOST_DEVICE inline static
ProbabilityDistributionType Type() {
return ProbabilityDistributionType::kNormal;
}
};

/*! \brief The (standard) logistic distribution */
class LogisticDist : public ProbabilityDistribution {
public:
double PDF(double z) override;
double CDF(double z) override;
double GradPDF(double z) override;
double HessPDF(double z) override;
struct LogisticDistribution {
XGBOOST_DEVICE inline static
hcho3 marked this conversation as resolved.
Show resolved Hide resolved
double PDF(double z) {
const double w = exp(z);
const double sqrt_denominator = 1 + w;
if (isinf(w) || isinf(w * w)) {
return 0.0;
} else {
return w / (sqrt_denominator * sqrt_denominator);
}
}

XGBOOST_DEVICE inline static
double CDF(double z) {
const double w = exp(z);
return isinf(w) ? 1.0 : (w / (1 + w));
}

XGBOOST_DEVICE inline static
double GradPDF(double z) {
const double w = exp(z);
return isinf(w) ? 0.0 : (PDF(z) * (1 - w) / (1 + w));
}

XGBOOST_DEVICE inline static
double HessPDF(double z) {
const double w = exp(z);
if (isinf(w) || isinf(w * w)) {
return 0.0;
} else {
return PDF(z) * (w * w - 4 * w + 1) / ((1 + w) * (1 + w));
}
}

XGBOOST_DEVICE inline static
ProbabilityDistributionType Type() {
return ProbabilityDistributionType::kLogistic;
}
};

/*! \brief The extreme distribution, also known as the Gumbel (minimum) distribution */
class ExtremeDist : public ProbabilityDistribution {
public:
double PDF(double z) override;
double CDF(double z) override;
double GradPDF(double z) override;
double HessPDF(double z) override;
struct ExtremeDistribution {
XGBOOST_DEVICE inline static
double PDF(double z) {
const double w = exp(z);
return isinf(w) ? 0.0 : (w * exp(-w));
}

XGBOOST_DEVICE inline static
double CDF(double z) {
const double w = exp(z);
return 1 - exp(-w);
}

XGBOOST_DEVICE inline static
double GradPDF(double z) {
const double w = exp(z);
return isinf(w) ? 0.0 : ((1 - w) * PDF(z));
}

XGBOOST_DEVICE inline static
double HessPDF(double z) {
const double w = exp(z);
if (isinf(w) || isinf(w * w)) {
return 0.0;
} else {
return (w * w - 3 * w + 1) * PDF(z);
}
}

XGBOOST_DEVICE inline static
ProbabilityDistributionType Type() {
return ProbabilityDistributionType::kExtreme;
}
};

} // namespace common
Expand Down
Loading