Porting elementwise metrics to GPU. (#3952)

* Port elementwise metrics to GPU.

* All elementwise metrics are converted to static polymorphic.
* Create a reducer for metrics reduction.
* Remove const of Metric::Eval to accommodate CubMemory.
This commit is contained in:
Jiaming Yuan
2018-12-01 18:46:45 +13:00
committed by GitHub
parent a9d684db18
commit 48dddfd635
14 changed files with 605 additions and 279 deletions

View File

@@ -11,8 +11,11 @@
#include <vector>
#include <string>
#include <functional>
#include <utility>
#include "./data.h"
#include "./base.h"
#include "../../src/common/host_device_vector.h"
namespace xgboost {
/*!
@@ -21,6 +24,23 @@ namespace xgboost {
*/
class Metric {
public:
/*!
* \brief Configure the Metric with the specified parameters.
* \param args arguments to the objective function.
*/
virtual void Configure(
const std::vector<std::pair<std::string, std::string> >& args) {}
/*!
* \brief set configuration from pair iterators.
* \param begin The beginning iterator.
* \param end The end iterator.
* \tparam PairIter iterator<std::pair<std::string, std::string> >
*/
template<typename PairIter>
inline void Configure(PairIter begin, PairIter end) {
std::vector<std::pair<std::string, std::string> > vec(begin, end);
this->Configure(vec);
}
/*!
* \brief evaluate a specific metric
* \param preds prediction
@@ -29,9 +49,9 @@ class Metric {
* the average statistics across all the node,
* this is only supported by some metrics
*/
virtual bst_float Eval(const std::vector<bst_float>& preds,
virtual bst_float Eval(const HostDeviceVector<bst_float>& preds,
const MetaInfo& info,
bool distributed) const = 0;
bool distributed) = 0;
/*! \return name of metric */
virtual const char* Name() const = 0;
/*! \brief virtual destructor */