1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*!
* Copyright 2017-2019 XGBoost contributors
*/
#include <gtest/gtest.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtautological-constant-compare"
#pragma GCC diagnostic ignored "-W#pragma-messages"
#include <xgboost/objective.h>
#pragma GCC diagnostic pop
#include <xgboost/context.h>
#include "../helpers.h"
#include "../objective/test_regression_obj.h"
namespace xgboost {
TEST(SyclObjective, LinearRegressionGPair) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestLinearRegressionGPair(&ctx);
}
TEST(SyclObjective, SquaredLog) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestSquaredLog(&ctx);
}
TEST(SyclObjective, LogisticRegressionGPair) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestLogisticRegressionGPair(&ctx);
}
TEST(SyclObjective, LogisticRegressionBasic) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestLogisticRegressionBasic(&ctx);
}
TEST(SyclObjective, LogisticRawGPair) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestsLogisticRawGPair(&ctx);
}
TEST(SyclObjective, PoissonRegressionGPair) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestPoissonRegressionGPair(&ctx);
}
TEST(SyclObjective, PoissonRegressionBasic) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestPoissonRegressionBasic(&ctx);
}
TEST(SyclObjective, GammaRegressionGPair) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestGammaRegressionGPair(&ctx);
}
TEST(SyclObjective, GammaRegressionBasic) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestGammaRegressionBasic(&ctx);
}
TEST(SyclObjective, TweedieRegressionGPair) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestTweedieRegressionGPair(&ctx);
}
TEST(SyclObjective, TweedieRegressionBasic) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestTweedieRegressionBasic(&ctx);
}
TEST(SyclObjective, CoxRegressionGPair) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestCoxRegressionGPair(&ctx);
}
TEST(SyclObjective, AbsoluteError) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestAbsoluteError(&ctx);
}
TEST(SyclObjective, AbsoluteErrorLeaf) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestAbsoluteErrorLeaf(&ctx);
}
TEST(SyclObjective, DeclareUnifiedTest(PseudoHuber)) {
Context ctx;
ctx.UpdateAllowUnknown(Args{{"device", "sycl"}});
TestPseudoHuber(&ctx);
}
TEST(SyclObjective, CPUvsSycl) {
Context ctx_sycl;
ctx_sycl.UpdateAllowUnknown(Args{{"device", "sycl"}});
ObjFunction * obj_sycl =
ObjFunction::Create("reg:squarederror", &ctx_sycl);
Context ctx_cpu;
ctx_cpu.UpdateAllowUnknown(Args{{"device", "cpu"}});
ObjFunction * obj_cpu =
ObjFunction::Create("reg:squarederror", &ctx_cpu);
linalg::Matrix<GradientPair> cpu_out_preds;
linalg::Matrix<GradientPair> sycl_out_preds;
constexpr size_t kRows = 400;
constexpr size_t kCols = 100;
auto pdmat = RandomDataGenerator(kRows, kCols, 0).Seed(0).GenerateDMatrix();
HostDeviceVector<float> preds;
preds.Resize(kRows);
auto& h_preds = preds.HostVector();
for (size_t i = 0; i < h_preds.size(); ++i) {
h_preds[i] = static_cast<float>(i);
}
auto& info = pdmat->Info();
info.labels.Reshape(kRows, 1);
auto& h_labels = info.labels.Data()->HostVector();
for (size_t i = 0; i < h_labels.size(); ++i) {
h_labels[i] = 1 / static_cast<float>(i+1);
}
{
// CPU
obj_cpu->GetGradient(preds, info, 0, &cpu_out_preds);
}
{
// sycl
obj_sycl->GetGradient(preds, info, 0, &sycl_out_preds);
}
auto h_cpu_out = cpu_out_preds.HostView();
auto h_sycl_out = sycl_out_preds.HostView();
float sgrad = 0;
float shess = 0;
for (size_t i = 0; i < kRows; ++i) {
sgrad += std::pow(h_cpu_out(i).GetGrad() - h_sycl_out(i).GetGrad(), 2);
shess += std::pow(h_cpu_out(i).GetHess() - h_sycl_out(i).GetHess(), 2);
}
ASSERT_NEAR(sgrad, 0.0f, kRtEps);
ASSERT_NEAR(shess, 0.0f, kRtEps);
delete obj_cpu;
delete obj_sycl;
}
} // namespace xgboost
|