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) {
134127TEST (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) {
155148TEST (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
177170TEST (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}
0 commit comments