File: test_sycl_transform_range.cc

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 (48 lines) | stat: -rw-r--r-- 1,357 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
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * Copyright 2018-2024, XGBoost Contributors
 */
#include <gtest/gtest.h>
#include <xgboost/base.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-W#pragma-messages"
#include <xgboost/host_device_vector.h>
#pragma GCC diagnostic pop
#include <xgboost/span.h>

#include <numeric>  // for iota
#include <vector>

#include "../../../src/common/transform.h"
#include "../helpers.h"

namespace xgboost::common {

template <typename T>
struct TestTransformRange {
  void operator()(std::size_t _idx, Span<float> _out, Span<const float> _in) {
    _out[_idx] = _in[_idx];
  }
};

TEST(SyclTransform, DeclareUnifiedTest(Basic)) {
  const size_t size{256};
  std::vector<float> h_in(size);
  std::vector<float> h_out(size);
  std::iota(h_in.begin(), h_in.end(), 0);
  std::vector<float> h_sol(size);
  std::iota(h_sol.begin(), h_sol.end(), 0);

  auto device =  DeviceOrd::SyclDefault();
  HostDeviceVector<float> const in_vec{h_in, device};
  HostDeviceVector<float> out_vec{h_out, device};
  out_vec.Fill(0);

  Transform<>::Init(TestTransformRange<float>{},
                    Range{0, static_cast<Range::DifferenceType>(size)}, 1,
                    device)
      .Eval(&out_vec, &in_vec);
  std::vector<float> res = out_vec.HostVector();

  ASSERT_TRUE(std::equal(h_sol.begin(), h_sol.end(), res.begin()));
}
}  // namespace xgboost::common