File: test_linear.cu

package info (click to toggle)
xgboost 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,796 kB
  • sloc: cpp: 67,502; python: 35,503; java: 4,676; ansic: 1,426; sh: 1,320; xml: 1,197; makefile: 204; javascript: 19
file content (36 lines) | stat: -rw-r--r-- 1,012 bytes parent folder | download | duplicates (2)
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
/**
 * Copyright 2018-2023, XGBoost Contributors
 */
#include <xgboost/linear_updater.h>
#include <xgboost/gbm.h>

#include "../helpers.h"
#include "test_json_io.h"
#include "../../../src/gbm/gblinear_model.h"

namespace xgboost {

TEST(Linear, GPUCoordinate) {
  size_t constexpr kRows = 10;
  size_t constexpr kCols = 10;

  auto mat = xgboost::RandomDataGenerator(kRows, kCols, 0).GenerateDMatrix();
  auto ctx = MakeCUDACtx(0);

  LearnerModelParam mparam{MakeMP(kCols, .5, 1)};
  auto updater = std::unique_ptr<xgboost::LinearUpdater>(
      xgboost::LinearUpdater::Create("gpu_coord_descent", &ctx));
  updater->Configure({{"eta", "1."}});
  auto gpair = linalg::Constant(&ctx, xgboost::GradientPair(-5, 1.0), mat->Info().num_row_, 1);
  xgboost::gbm::GBLinearModel model{&mparam};

  model.LazyInitModel();
  updater->Update(&gpair, mat.get(), &model, gpair.Size());

  ASSERT_EQ(model.Bias()[0], 5.0f);
}

TEST(GPUCoordinate, JsonIO) {
  TestUpdaterJsonIO("gpu_coord_descent");
}
}  // namespace xgboost