2
2
* Copyright 2017-2023 by Contributors
3
3
* \file hist_util.h
4
4
*/
5
- #ifndef XGBOOST_COMMON_HIST_UTIL_SYCL_H_
6
- #define XGBOOST_COMMON_HIST_UTIL_SYCL_H_
5
+ #ifndef PLUGIN_SYCL_COMMON_HIST_UTIL_H_
6
+ #define PLUGIN_SYCL_COMMON_HIST_UTIL_H_
7
7
8
8
#include < vector>
9
9
12
12
13
13
#include " ../../src/common/hist_util.h"
14
14
15
- #include " CL/sycl.hpp"
15
+ #include < CL/sycl.hpp>
16
16
17
17
namespace xgboost {
18
18
namespace sycl {
@@ -31,32 +31,32 @@ using AtomicRef = ::sycl::atomic_ref<T,
31
31
* \brief SYCL implementation of HistogramCuts stored in USM buffers to provide access from device kernels
32
32
*/
33
33
class HistogramCuts {
34
- protected:
34
+ protected:
35
35
using BinIdx = uint32_t ;
36
36
37
- public:
37
+ public:
38
38
HistogramCuts () {}
39
39
40
- HistogramCuts (::sycl::queue qu) {
41
- cut_ptrs_.Resize (qu_, 1 , 0 );
40
+ explicit HistogramCuts (::sycl::queue qu) {
41
+ cut_ptrs_.Resize (& qu_, 1 , 0 );
42
42
}
43
43
44
44
~HistogramCuts () {
45
45
}
46
46
47
47
void Init (::sycl::queue qu, xgboost::common::HistogramCuts const & cuts) {
48
48
qu_ = qu;
49
- cut_values_.Init (qu_, cuts.cut_values_ .HostVector ());
50
- cut_ptrs_.Init (qu_, cuts.cut_ptrs_ .HostVector ());
51
- min_vals_.Init (qu_, cuts.min_vals_ .HostVector ());
49
+ cut_values_.Init (& qu_, cuts.cut_values_ .HostVector ());
50
+ cut_ptrs_.Init (& qu_, cuts.cut_ptrs_ .HostVector ());
51
+ min_vals_.Init (& qu_, cuts.min_vals_ .HostVector ());
52
52
}
53
53
54
54
// Getters for USM buffers to pass pointers into device kernels
55
55
const USMVector<uint32_t >& Ptrs () const { return cut_ptrs_; }
56
56
const USMVector<float >& Values () const { return cut_values_; }
57
57
const USMVector<float >& MinValues () const { return min_vals_; }
58
58
59
- private:
59
+ private:
60
60
USMVector<bst_float> cut_values_;
61
61
USMVector<uint32_t > cut_ptrs_;
62
62
USMVector<float > min_vals_;
@@ -128,11 +128,11 @@ struct Index {
128
128
}
129
129
130
130
void Resize (const size_t nBytesData) {
131
- data_.Resize (qu_, nBytesData);
131
+ data_.Resize (& qu_, nBytesData);
132
132
}
133
133
134
134
void ResizeOffset (const size_t nDisps) {
135
- offset_.Resize (qu_, nDisps);
135
+ offset_.Resize (& qu_, nDisps);
136
136
p_ = nDisps;
137
137
}
138
138
@@ -162,7 +162,8 @@ struct Index {
162
162
using Func = uint32_t (*)(const uint8_t *, size_t );
163
163
164
164
USMVector<uint8_t , MemoryType::on_device> data_;
165
- USMVector<uint32_t , MemoryType::on_device> offset_; // size of this field is equal to number of features
165
+ // size of this field is equal to number of features
166
+ USMVector<uint32_t , MemoryType::on_device> offset_;
166
167
BinTypeSize binTypeSize_ {BinTypeSize::kUint8BinsTypeSize };
167
168
size_t p_ {1 };
168
169
Func func_;
@@ -194,7 +195,8 @@ struct GHistIndexMatrix {
194
195
size_t row_stride;
195
196
196
197
// Create a global histogram matrix based on a given DMatrix device wrapper
197
- void Init (::sycl::queue qu, Context const * ctx, const sycl::DeviceMatrix& p_fmat_device, int max_num_bins);
198
+ void Init (::sycl::queue qu, Context const * ctx,
199
+ const sycl::DeviceMatrix& p_fmat_device, int max_num_bins);
198
200
199
201
template <typename BinIdxType>
200
202
void SetIndexData (::sycl::queue qu, xgboost::common::Span<BinIdxType> index_data_span,
@@ -204,13 +206,13 @@ struct GHistIndexMatrix {
204
206
void ResizeIndex (const size_t n_offsets, const size_t n_index,
205
207
const bool isDense);
206
208
207
- inline void GetFeatureCounts (std::vector<size_t >& counts) const {
209
+ inline void GetFeatureCounts (std::vector<size_t >* counts) const {
208
210
auto nfeature = cut_device.Ptrs ().Size () - 1 ;
209
211
for (unsigned fid = 0 ; fid < nfeature; ++fid) {
210
212
auto ibegin = cut_device.Ptrs ()[fid];
211
213
auto iend = cut_device.Ptrs ()[fid + 1 ];
212
214
for (auto i = ibegin; i < iend; ++i) {
213
- counts[fid] += hit_count[i];
215
+ (* counts) [fid] += hit_count[i];
214
216
}
215
217
}
216
218
}
@@ -229,15 +231,15 @@ class ColumnMatrix;
229
231
*/
230
232
template <typename GradientSumT>
231
233
void InitHist (::sycl::queue qu,
232
- GHistRow<GradientSumT, MemoryType::on_device>& hist,
234
+ GHistRow<GradientSumT, MemoryType::on_device>* hist,
233
235
size_t size);
234
236
235
237
/* !
236
238
* \brief Copy histogram from src to dst
237
239
*/
238
240
template <typename GradientSumT>
239
241
void CopyHist (::sycl::queue qu,
240
- GHistRow<GradientSumT, MemoryType::on_device>& dst,
242
+ GHistRow<GradientSumT, MemoryType::on_device>* dst,
241
243
const GHistRow<GradientSumT, MemoryType::on_device>& src,
242
244
size_t size);
243
245
@@ -246,10 +248,10 @@ void CopyHist(::sycl::queue qu,
246
248
*/
247
249
template <typename GradientSumT>
248
250
::sycl::event SubtractionHist (::sycl::queue qu,
249
- GHistRow<GradientSumT, MemoryType::on_device>& dst,
250
- const GHistRow<GradientSumT, MemoryType::on_device>& src1,
251
- const GHistRow<GradientSumT, MemoryType::on_device>& src2,
252
- size_t size, ::sycl::event event_priv);
251
+ GHistRow<GradientSumT, MemoryType::on_device>* dst,
252
+ const GHistRow<GradientSumT, MemoryType::on_device>& src1,
253
+ const GHistRow<GradientSumT, MemoryType::on_device>& src2,
254
+ size_t size, ::sycl::event event_priv);
253
255
254
256
/* !
255
257
* \brief Histograms of gradient statistics for multiple nodes
@@ -287,7 +289,8 @@ class HistCollection {
287
289
if (nid >= data_.size ()) {
288
290
data_.resize (nid + 1 );
289
291
}
290
- return data_[nid].ResizeAsync (qu_, nbins_, xgboost::detail::GradientPairInternal<GradientSumT>(0 , 0 ));
292
+ return data_[nid].ResizeAsync (&qu_, nbins_,
293
+ xgboost::detail::GradientPairInternal<GradientSumT>(0 , 0 ));
291
294
}
292
295
293
296
void Wait_and_throw () {
@@ -320,7 +323,7 @@ class ParallelGHistBuilder {
320
323
}
321
324
322
325
void Reset (size_t nblocks) {
323
- hist_device_buffer_.Resize (qu_, nblocks * nbins_ * 2 );
326
+ hist_device_buffer_.Resize (& qu_, nblocks * nbins_ * 2 );
324
327
}
325
328
326
329
GHistRowT& GetDeviceBuffer () {
@@ -353,17 +356,17 @@ class GHistBuilder {
353
356
354
357
// Construct a histogram via histogram aggregation
355
358
::sycl::event BuildHist (const USMVector<GradientPair, MemoryType::on_device>& gpair_device,
356
- const RowSetCollection::Elem& row_indices,
357
- const GHistIndexMatrix& gmat,
358
- GHistRowT<MemoryType::on_device>& HistCollection,
359
- bool isDense,
360
- GHistRowT<MemoryType::on_device>& hist_buffer,
361
- ::sycl::event evens);
359
+ const RowSetCollection::Elem& row_indices,
360
+ const GHistIndexMatrix& gmat,
361
+ GHistRowT<MemoryType::on_device>* HistCollection,
362
+ bool isDense,
363
+ GHistRowT<MemoryType::on_device>* hist_buffer,
364
+ ::sycl::event evens);
362
365
363
366
// Construct a histogram via subtraction trick
364
- void SubtractionTrick (GHistRowT<MemoryType::on_device>& self,
365
- GHistRowT<MemoryType::on_device>& sibling,
366
- GHistRowT<MemoryType::on_device>& parent);
367
+ void SubtractionTrick (GHistRowT<MemoryType::on_device>* self,
368
+ const GHistRowT<MemoryType::on_device>& sibling,
369
+ const GHistRowT<MemoryType::on_device>& parent);
367
370
368
371
uint32_t GetNumBins () const {
369
372
return nbins_;
@@ -378,4 +381,4 @@ class GHistBuilder {
378
381
} // namespace common
379
382
} // namespace sycl
380
383
} // namespace xgboost
381
- #endif // XGBOOST_COMMON_HIST_UTIL_SYCL_H_
384
+ #endif // PLUGIN_SYCL_COMMON_HIST_UTIL_H_
0 commit comments