Skip to content

Commit 566a798

Browse files
committed
lint.
1 parent 854c41a commit 566a798

File tree

6 files changed

+60
-62
lines changed

6 files changed

+60
-62
lines changed

include/xgboost/host_device_vector.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ namespace xgboost {
6464
void SetCudaSetDeviceHandler(void (*handler)(int));
6565
#endif // __CUDACC__
6666

67-
template <typename T> struct HostDeviceVectorImpl;
67+
template <typename T>
68+
struct HostDeviceVectorImpl;
6869

6970
/*!
7071
* \brief Controls data access from the GPU.
@@ -78,7 +79,8 @@ template <typename T> struct HostDeviceVectorImpl;
7879
* - Data is being manipulated on the host. Host has write access, device doesn't have access.
7980
*/
8081
enum GPUAccess {
81-
kNone, kRead,
82+
kNone,
83+
kRead,
8284
// write implies read
8385
kWrite
8486
};
@@ -113,9 +115,7 @@ class HostDeviceVector {
113115
}
114116
T* DevicePointer(Context const* ctx = nullptr);
115117
const T* ConstDevicePointer(Context const* ctx = nullptr) const;
116-
const T* DevicePointer(Context const* ctx = nullptr) const {
117-
return ConstDevicePointer(ctx);
118-
}
118+
const T* DevicePointer(Context const* ctx = nullptr) const { return ConstDevicePointer(ctx); }
119119

120120
T* HostPointer(Context const* ctx = nullptr) { return HostVector(ctx).data(); }
121121
common::Span<T> HostSpan(Context const* ctx = nullptr) {
@@ -124,15 +124,11 @@ class HostDeviceVector {
124124
common::Span<T const> HostSpan(Context const* ctx = nullptr) const {
125125
return common::Span<T const>{HostVector(ctx)};
126126
}
127-
common::Span<T const> ConstHostSpan(Context const* ctx = nullptr) const {
128-
return HostSpan(ctx);
129-
}
127+
common::Span<T const> ConstHostSpan(Context const* ctx = nullptr) const { return HostSpan(ctx); }
130128
const T* ConstHostPointer(Context const* ctx = nullptr) const {
131129
return ConstHostVector(ctx).data();
132130
}
133-
const T* HostPointer(Context const* ctx = nullptr) const {
134-
return ConstHostPointer(ctx);
135-
}
131+
const T* HostPointer(Context const* ctx = nullptr) const { return ConstHostPointer(ctx); }
136132

137133
void Fill(T v, Context const* ctx = nullptr);
138134
void Copy(const HostDeviceVector<T>& other, Context const* ctx = nullptr);

include/xgboost/linalg.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ class Tensor {
768768
Order order_{Order::kC};
769769

770770
template <typename I, std::int32_t D>
771-
void Initialize(I const (&shape)[D], DeviceOrd device, Context const* ctx = nullptr) {
771+
void Initialize(I const (&shape)[D], DeviceOrd device, Context const *ctx = nullptr) {
772772
static_assert(D <= kDim, "Invalid shape.");
773773
std::copy(shape, shape + D, shape_);
774774
for (auto i = D; i < kDim; ++i) {
@@ -792,12 +792,12 @@ class Tensor {
792792
*/
793793
template <typename I, int32_t D>
794794
explicit Tensor(I const (&shape)[D], DeviceOrd device, Order order = kC,
795-
Context const* ctx = nullptr)
795+
Context const *ctx = nullptr)
796796
: Tensor{common::Span<I const, D>{shape}, device, order, ctx} {}
797797

798798
template <typename I, size_t D>
799799
explicit Tensor(common::Span<I const, D> shape, DeviceOrd device, Order order = kC,
800-
Context const* ctx = nullptr)
800+
Context const *ctx = nullptr)
801801
: order_{order} {
802802
// No device unroll as this is a host only function.
803803
std::copy(shape.data(), shape.data() + D, shape_);
@@ -818,7 +818,7 @@ class Tensor {
818818
*/
819819
template <typename It, typename I, int32_t D>
820820
explicit Tensor(It begin, It end, I const (&shape)[D], DeviceOrd device, Order order = kC,
821-
Context const* ctx = nullptr)
821+
Context const *ctx = nullptr)
822822
: order_{order} {
823823
auto &h_vec = data_.HostVector();
824824
h_vec.insert(h_vec.begin(), begin, end);
@@ -828,7 +828,7 @@ class Tensor {
828828

829829
template <typename I, int32_t D>
830830
explicit Tensor(std::initializer_list<T> data, I const (&shape)[D], DeviceOrd device,
831-
Order order = kC, Context const* ctx = nullptr)
831+
Order order = kC, Context const *ctx = nullptr)
832832
: order_{order} {
833833
auto &h_vec = data_.HostVector();
834834
h_vec = data;
@@ -855,7 +855,7 @@ class Tensor {
855855
/**
856856
* @brief Get a @ref TensorView for this tensor.
857857
*/
858-
auto View(DeviceOrd device, Context const* ctx = nullptr) {
858+
auto View(DeviceOrd device, Context const *ctx = nullptr) {
859859
if (device.IsCPU()) {
860860
auto span = data_.HostSpan(ctx);
861861
return TensorView<T, kDim>{span, shape_, device, order_};
@@ -865,7 +865,7 @@ class Tensor {
865865
return TensorView<T, kDim>{span, shape_, device, order_};
866866
}
867867
}
868-
auto View(DeviceOrd device, Context const* ctx = nullptr) const {
868+
auto View(DeviceOrd device, Context const *ctx = nullptr) const {
869869
if (device.IsCPU()) {
870870
auto span = data_.ConstHostSpan(ctx);
871871
return TensorView<T const, kDim>{span, shape_, device, order_};
@@ -876,10 +876,8 @@ class Tensor {
876876
}
877877
}
878878

879-
auto HostView(Context const* ctx = nullptr) { return this->View(DeviceOrd::CPU(), ctx); }
880-
auto HostView(Context const* ctx = nullptr) const {
881-
return this->View(DeviceOrd::CPU(), ctx);
882-
}
879+
auto HostView(Context const *ctx = nullptr) { return this->View(DeviceOrd::CPU(), ctx); }
880+
auto HostView(Context const *ctx = nullptr) const { return this->View(DeviceOrd::CPU(), ctx); }
883881

884882
[[nodiscard]] std::size_t Size() const { return data_.Size(); }
885883
[[nodiscard]] bool Empty() const { return Size() == 0; }
@@ -955,7 +953,7 @@ class Tensor {
955953
/**
956954
* \brief Set device ordinal for this tensor.
957955
*/
958-
void SetDevice(DeviceOrd device, Context const* ctx = nullptr) const {
956+
void SetDevice(DeviceOrd device, Context const *ctx = nullptr) const {
959957
data_.SetDevice(device, ctx);
960958
}
961959
[[nodiscard]] DeviceOrd Device() const { return data_.Device(); }

src/common/host_device_vector.cc

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@
66

77
// dummy implementation of HostDeviceVector in case CUDA is not used
88

9+
#include "xgboost/host_device_vector.h"
10+
911
#include <xgboost/base.h>
1012
#include <xgboost/data.h>
13+
1114
#include <cstdint>
1215
#include <memory>
1316
#include <utility>
17+
1418
#include "xgboost/tree_model.h"
15-
#include "xgboost/host_device_vector.h"
1619

1720
namespace xgboost {
1821

1922
template <typename T>
2023
struct HostDeviceVectorImpl {
2124
explicit HostDeviceVectorImpl(size_t size, T v) : data_h_(size, v) {}
2225
HostDeviceVectorImpl(std::initializer_list<T> init) : data_h_(init) {}
23-
explicit HostDeviceVectorImpl(std::vector<T> init) : data_h_(std::move(init)) {}
26+
explicit HostDeviceVectorImpl(std::vector<T> init) : data_h_(std::move(init)) {}
2427
HostDeviceVectorImpl(HostDeviceVectorImpl&& that) : data_h_(std::move(that.data_h_)) {}
2528

26-
void Swap(HostDeviceVectorImpl &other) {
27-
data_h_.swap(other.data_h_);
28-
}
29+
void Swap(HostDeviceVectorImpl& other) { data_h_.swap(other.data_h_); }
2930

3031
std::vector<T>& Vec() { return data_h_; }
3132

@@ -35,19 +36,19 @@ struct HostDeviceVectorImpl {
3536

3637
template <typename T>
3738
HostDeviceVector<T>::HostDeviceVector(size_t size, T v, DeviceOrd, Context const*)
38-
: impl_(nullptr) {
39+
: impl_(nullptr) {
3940
impl_ = new HostDeviceVectorImpl<T>(size, v);
4041
}
4142

4243
template <typename T>
4344
HostDeviceVector<T>::HostDeviceVector(std::initializer_list<T> init, DeviceOrd, Context const*)
44-
: impl_(nullptr) {
45+
: impl_(nullptr) {
4546
impl_ = new HostDeviceVectorImpl<T>(init);
4647
}
4748

4849
template <typename T>
4950
HostDeviceVector<T>::HostDeviceVector(const std::vector<T>& init, DeviceOrd, Context const*)
50-
: impl_(nullptr) {
51+
: impl_(nullptr) {
5152
impl_ = new HostDeviceVectorImpl<T>(init);
5253
}
5354

@@ -58,7 +59,9 @@ HostDeviceVector<T>::HostDeviceVector(HostDeviceVector<T>&& that) {
5859

5960
template <typename T>
6061
HostDeviceVector<T>& HostDeviceVector<T>::operator=(HostDeviceVector<T>&& that) {
61-
if (this == &that) { return *this; }
62+
if (this == &that) {
63+
return *this;
64+
}
6265

6366
std::unique_ptr<HostDeviceVectorImpl<T>> new_impl(
6467
new HostDeviceVectorImpl<T>(std::move(*that.impl_)));
@@ -79,13 +82,19 @@ GPUAccess HostDeviceVector<T>::DeviceAccess() const {
7982
}
8083

8184
template <typename T>
82-
size_t HostDeviceVector<T>::Size() const { return impl_->Vec().size(); }
85+
size_t HostDeviceVector<T>::Size() const {
86+
return impl_->Vec().size();
87+
}
8388

8489
template <typename T>
85-
DeviceOrd HostDeviceVector<T>::Device() const { return DeviceOrd::CPU(); }
90+
DeviceOrd HostDeviceVector<T>::Device() const {
91+
return DeviceOrd::CPU();
92+
}
8693

8794
template <typename T>
88-
T* HostDeviceVector<T>::DevicePointer(Context const*) { return nullptr; }
95+
T* HostDeviceVector<T>::DevicePointer(Context const*) {
96+
return nullptr;
97+
}
8998

9099
template <typename T>
91100
const T* HostDeviceVector<T>::ConstDevicePointer(Context const*) const {
@@ -103,7 +112,9 @@ common::Span<const T> HostDeviceVector<T>::ConstDeviceSpan(Context const*) const
103112
}
104113

105114
template <typename T>
106-
std::vector<T>& HostDeviceVector<T>::HostVector(Context const*) { return impl_->Vec(); }
115+
std::vector<T>& HostDeviceVector<T>::HostVector(Context const*) {
116+
return impl_->Vec();
117+
}
107118

108119
template <typename T>
109120
const std::vector<T>& HostDeviceVector<T>::ConstHostVector(Context const*) const {
@@ -179,7 +190,7 @@ template class HostDeviceVector<bst_float>;
179190
template class HostDeviceVector<double>;
180191
template class HostDeviceVector<GradientPair>;
181192
template class HostDeviceVector<GradientPairPrecise>;
182-
template class HostDeviceVector<std::int32_t>; // bst_node_t
193+
template class HostDeviceVector<std::int32_t>; // bst_node_t
183194
template class HostDeviceVector<std::uint8_t>;
184195
template class HostDeviceVector<std::int8_t>;
185196
template class HostDeviceVector<FeatureType>;

tests/cpp/common/test_host_device_vector.cu

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018-2025, XGBoost contributors
2+
* Copyright 2018-2026, XGBoost contributors
33
*/
44
#include <gtest/gtest.h>
55
#include <thrust/equal.h>
@@ -26,12 +26,10 @@ struct HostDeviceVectorSetDeviceHandler {
2626
SetCudaSetDeviceHandler(f);
2727
}
2828

29-
~HostDeviceVectorSetDeviceHandler() {
30-
SetCudaSetDeviceHandler(nullptr);
31-
}
29+
~HostDeviceVectorSetDeviceHandler() { SetCudaSetDeviceHandler(nullptr); }
3230
};
3331

34-
void InitHostDeviceVector(size_t n, DeviceOrd device, HostDeviceVector<int> *v,
32+
void InitHostDeviceVector(size_t n, DeviceOrd device, HostDeviceVector<int>* v,
3533
Context const* ctx) {
3634
v->SetDevice(device, ctx);
3735
v->Resize(n);
@@ -52,40 +50,35 @@ void InitHostDeviceVector(size_t n, DeviceOrd device, HostDeviceVector<int> *v,
5250
std::copy_n(thrust::make_counting_iterator(0), n, data_h.begin());
5351
}
5452

55-
void PlusOne(HostDeviceVector<int> *v) {
53+
void PlusOne(HostDeviceVector<int>* v) {
5654
auto device = v->Device();
5755
SetDeviceForTest(device);
5856
thrust::transform(dh::tcbegin(*v), dh::tcend(*v), dh::tbegin(*v),
59-
[=]__device__(unsigned int a){ return a + 1; });
57+
[=] __device__(unsigned int a) { return a + 1; });
6058
ASSERT_TRUE(v->DeviceCanWrite());
6159
}
6260

63-
void CheckDevice(HostDeviceVector<int>* v,
64-
size_t size,
65-
unsigned int first,
66-
GPUAccess access,
61+
void CheckDevice(HostDeviceVector<int>* v, size_t size, unsigned int first, GPUAccess access,
6762
Context const* ctx) {
6863
ASSERT_EQ(v->Size(), size);
6964
SetDeviceForTest(v->Device());
7065

71-
ASSERT_TRUE(thrust::equal(dh::tcbegin(*v), dh::tcend(*v),
72-
thrust::make_counting_iterator(first)));
66+
ASSERT_TRUE(thrust::equal(dh::tcbegin(*v), dh::tcend(*v), thrust::make_counting_iterator(first)));
7367
ASSERT_TRUE(v->DeviceCanRead());
7468
ASSERT_EQ(v->DeviceCanWrite(), access == GPUAccess::kWrite);
7569
ASSERT_EQ(v->HostCanRead(), access == GPUAccess::kRead);
7670
ASSERT_FALSE(v->HostCanWrite());
7771

78-
ASSERT_TRUE(thrust::equal(dh::tbegin(*v), dh::tend(*v),
79-
thrust::make_counting_iterator(first)));
72+
ASSERT_TRUE(thrust::equal(dh::tbegin(*v), dh::tend(*v), thrust::make_counting_iterator(first)));
8073
ASSERT_TRUE(v->DeviceCanRead());
8174
ASSERT_TRUE(v->DeviceCanWrite());
8275
ASSERT_FALSE(v->HostCanRead());
8376
ASSERT_FALSE(v->HostCanWrite());
8477
}
8578

86-
void CheckHost(HostDeviceVector<int> *v, GPUAccess access, Context const* ctx) {
87-
const std::vector<int>& data_h = access == GPUAccess::kNone ?
88-
v->HostVector(ctx) : v->ConstHostVector(ctx);
79+
void CheckHost(HostDeviceVector<int>* v, GPUAccess access, Context const* ctx) {
80+
const std::vector<int>& data_h =
81+
access == GPUAccess::kNone ? v->HostVector(ctx) : v->ConstHostVector(ctx);
8982
for (size_t i = 0; i < v->Size(); ++i) {
9083
ASSERT_EQ(data_h.at(i), i + 1);
9184
}
@@ -134,11 +127,11 @@ TEST(HostDeviceVector, Copy) {
134127
TEST(HostDeviceVector, SetDevice) {
135128
auto ctx = Context{}.MakeCUDA(0);
136129

137-
std::vector<int> h_vec (2345);
130+
std::vector<int> h_vec(2345);
138131
for (size_t i = 0; i < h_vec.size(); ++i) {
139132
h_vec[i] = i;
140133
}
141-
HostDeviceVector<int> vec (h_vec);
134+
HostDeviceVector<int> vec(h_vec);
142135

143136
vec.SetDevice(ctx.Device(), &ctx);
144137
ASSERT_EQ(vec.Size(), h_vec.size());
@@ -155,7 +148,7 @@ TEST(HostDeviceVector, SetDevice) {
155148
TEST(HostDeviceVector, Span) {
156149
auto ctx = Context{}.MakeCUDA(0);
157150

158-
HostDeviceVector<float> vec {1.0f, 2.0f, 3.0f, 4.0f};
151+
HostDeviceVector<float> vec{1.0f, 2.0f, 3.0f, 4.0f};
159152
vec.SetDevice(ctx.Device(), &ctx);
160153
auto span = vec.DeviceSpan(&ctx);
161154
ASSERT_EQ(vec.Size(), span.size());
@@ -175,8 +168,8 @@ TEST(HostDeviceVector, Span) {
175168
}
176169

177170
TEST(HostDeviceVector, Empty) {
178-
HostDeviceVector<float> vec {1.0f, 2.0f, 3.0f, 4.0f};
179-
HostDeviceVector<float> another { std::move(vec) };
171+
HostDeviceVector<float> vec{1.0f, 2.0f, 3.0f, 4.0f};
172+
HostDeviceVector<float> another{std::move(vec)};
180173
ASSERT_FALSE(another.Empty());
181174
ASSERT_TRUE(vec.Empty());
182175
}

tests/cpp/common/test_linalg.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2021-2025, XGBoost Contributors
2+
* Copyright 2021-2026, XGBoost Contributors
33
*/
44
#include <gtest/gtest.h>
55
#include <thrust/equal.h> // for equal

tests/cpp/common/test_linalg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2025, XGBoost Contributors
2+
* Copyright 2025-2026, XGBoost Contributors
33
*/
44
#pragma once
55

0 commit comments

Comments
 (0)