[GPU-Plugin] Add GPU accelerated prediction (#2593)

* [GPU-Plugin] Add GPU accelerated prediction

* Improve allocation message

* Update documentation

* Resolve linker error for predictor

* Add unit tests
This commit is contained in:
Rory Mitchell
2017-08-16 12:31:59 +12:00
committed by GitHub
parent 71e5e622b1
commit ef23e424f1
25 changed files with 876 additions and 203 deletions

View File

@@ -1,4 +1,6 @@
#include "./helpers.h"
#include "xgboost/c_api.h"
#include <random>
std::string TempFileName() {
return std::tmpnam(nullptr);
@@ -60,3 +62,23 @@ xgboost::bst_float GetMetricEval(xgboost::Metric * metric,
info.weights = weights;
return metric->Eval(preds, info, false);
}
std::shared_ptr<xgboost::DMatrix> CreateDMatrix(int rows, int columns,
float sparsity, int seed) {
const float missing_value = -1;
std::vector<float> test_data(rows * columns);
std::mt19937 gen(seed);
std::uniform_real_distribution<float> dis(0.0f, 1.0f);
for (auto &e : test_data) {
if (dis(gen) < sparsity) {
e = missing_value;
} else {
e = dis(gen);
}
}
DMatrixHandle handle;
XGDMatrixCreateFromMat(test_data.data(), rows, columns, missing_value,
&handle);
return *static_cast<std::shared_ptr<xgboost::DMatrix> *>(handle);
}