xgboost

span.h
Go to the documentation of this file.
1
29 #ifndef XGBOOST_SPAN_H_
30 #define XGBOOST_SPAN_H_
31
32 #include <xgboost/base.h>
33 #include <xgboost/logging.h>
34
35 #include <cinttypes> // size_t
36 #include <limits> // numeric_limits
37 #include <iterator>
38 #include <type_traits>
39 #include <cstdio>
40
41 #if defined(__CUDACC__)
42 #include <cuda_runtime.h>
43 #endif // defined(__CUDACC__)
44
62 #if defined(_MSC_VER) && _MSC_VER < 1910
63
64 #define __span_noexcept
65
66 #pragma push_macro("constexpr")
67 #define constexpr /*constexpr*/
68
69 #else
70
71 #define __span_noexcept noexcept
72
73 #endif // defined(_MSC_VER) && _MSC_VER < 1910
74
75 namespace xgboost {
76 namespace common {
77
78 #if defined(__CUDA_ARCH__)
79 // Usual logging facility is not available inside device code.
80
81 #if defined(_MSC_VER)
82
83 // Windows CUDA doesn't have __assert_fail.
84 #define KERNEL_CHECK(cond) \
85 do { \
86 if (XGBOOST_EXPECT(!(cond), false)) { \
87 asm("trap;"); \
88 } \
89 } while (0)
90
91 #else // defined(_MSC_VER)
92
93 #define __ASSERT_STR_HELPER(x) #x
94
95 #define KERNEL_CHECK(cond) \
96 (XGBOOST_EXPECT((cond), true) \
97 ? static_cast<void>(0) \
98 : __assert_fail(__ASSERT_STR_HELPER((cond)), __FILE__, __LINE__, \
99 __PRETTY_FUNCTION__))
100
101 #endif // defined(_MSC_VER)
102
103 #define SPAN_CHECK KERNEL_CHECK
104
105 #else // not CUDA
106
107 #define KERNEL_CHECK(cond) \
108 (XGBOOST_EXPECT((cond), true) ? static_cast<void>(0) : std::terminate())
109
110 #define SPAN_CHECK(cond) KERNEL_CHECK(cond)
111
112 #endif // __CUDA_ARCH__
113
114 #if defined(__CUDA_ARCH__)
115 #define SPAN_LT(lhs, rhs) KERNEL_CHECK((lhs) < (rhs))
116 #else
117 #define SPAN_LT(lhs, rhs) KERNEL_CHECK((lhs) < (rhs))
118 #endif // defined(__CUDA_ARCH__)
119
120 namespace detail {
127 using ptrdiff_t = typename std::conditional< // NOLINT
128 std::is_same<std::ptrdiff_t, std::int64_t>::value,
129 std::ptrdiff_t, std::int64_t>::type;
130 } // namespace detail
131
132 #if defined(_MSC_VER) && _MSC_VER < 1910
133 constexpr const std::size_t
134 dynamic_extent = std::numeric_limits<std::size_t>::max(); // NOLINT
135 #else
136 constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max(); // NOLINT
137 #endif // defined(_MSC_VER) && _MSC_VER < 1910
138
139 enum class byte : unsigned char {}; // NOLINT
140
141 template <class ElementType, std::size_t Extent>
142 class Span;
143
144 namespace detail {
145
146 template <typename SpanType, bool IsConst>
147 class SpanIterator {
148 using ElementType = typename SpanType::element_type;
149
150 public:
151 using iterator_category = std::random_access_iterator_tag; // NOLINT
152 using value_type = typename SpanType::value_type; // NOLINT
153 using difference_type = detail::ptrdiff_t; // NOLINT
154
155 using reference = typename std::conditional< // NOLINT
156 IsConst, const ElementType, ElementType>::type&;
157 using pointer = typename std::add_pointer<reference>::type; // NOLINT
158
159 constexpr SpanIterator() = default;
160
161 XGBOOST_DEVICE constexpr SpanIterator(
162 const SpanType* _span,
163 typename SpanType::index_type _idx) __span_noexcept :
164 span_(_span), index_(_idx) {}
165
166 friend SpanIterator<SpanType, true>;
167 template <bool B, typename std::enable_if<!B && IsConst>::type* = nullptr>
168 XGBOOST_DEVICE constexpr SpanIterator( // NOLINT
169 const SpanIterator<SpanType, B>& other_) __span_noexcept
170 : SpanIterator(other_.span_, other_.index_) {}
171
172 XGBOOST_DEVICE reference operator*() const {
173 SPAN_CHECK(index_ < span_->size());
174 return *(span_->data() + index_);
175 }
176 XGBOOST_DEVICE reference operator[](difference_type n) const {
177 return *(*this + n);
178 }
179
180 XGBOOST_DEVICE pointer operator->() const {
181 SPAN_CHECK(index_ != span_->size());
182 return span_->data() + index_;
183 }
184
185 XGBOOST_DEVICE SpanIterator& operator++() {
186 SPAN_CHECK(index_ != span_->size());
187 index_++;
188 return *this;
189 }
190
191 XGBOOST_DEVICE SpanIterator operator++(int) {
192 auto ret = *this;
193 ++(*this);
194 return ret;
195 }
196
197 XGBOOST_DEVICE SpanIterator& operator--() {
198 SPAN_CHECK(index_ != 0 && index_ <= span_->size());
199 index_--;
200 return *this;
201 }
202
203 XGBOOST_DEVICE SpanIterator operator--(int) {
204 auto ret = *this;
205 --(*this);
206 return ret;
207 }
208
209 XGBOOST_DEVICE SpanIterator operator+(difference_type n) const {
210 auto ret = *this;
211 return ret += n;
212 }
213
214 XGBOOST_DEVICE SpanIterator& operator+=(difference_type n) {
215 SPAN_CHECK((index_ + n) <= span_->size());
216 index_ += n;
217 return *this;
218 }
219
220 XGBOOST_DEVICE difference_type operator-(SpanIterator rhs) const {
221 SPAN_CHECK(span_ == rhs.span_);
222 return index_ - rhs.index_;
223 }
224
225 XGBOOST_DEVICE SpanIterator operator-(difference_type n) const {
226 auto ret = *this;
227 return ret -= n;
228 }
229
230 XGBOOST_DEVICE SpanIterator& operator-=(difference_type n) {
231 return *this += -n;
232 }
233
234 // friends
235 XGBOOST_DEVICE constexpr friend bool operator==(
236 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
237 return _lhs.span_ == _rhs.span_ && _lhs.index_ == _rhs.index_;
238 }
239
240 XGBOOST_DEVICE constexpr friend bool operator!=(
241 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
242 return !(_lhs == _rhs);
243 }
244
245 XGBOOST_DEVICE constexpr friend bool operator<(
246 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
247 return _lhs.index_ < _rhs.index_;
248 }
249
250 XGBOOST_DEVICE constexpr friend bool operator<=(
251 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
252 return !(_rhs < _lhs);
253 }
254
255 XGBOOST_DEVICE constexpr friend bool operator>(
256 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
257 return _rhs < _lhs;
258 }
259
260 XGBOOST_DEVICE constexpr friend bool operator>=(
261 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
262 return !(_rhs > _lhs);
263 }
264
265 protected:
266 const SpanType *span_ { nullptr };
267 typename SpanType::index_type index_ { 0 };
268 };
269
270
271 // It's tempting to use constexpr instead of structs to do the following meta
272 // programming. But remember that we are supporting MSVC 2013 here.
273
281 template <std::size_t Extent, std::size_t Offset, std::size_t Count>
282 struct ExtentValue : public std::integral_constant<
283 std::size_t, Count != dynamic_extent ?
284 Count : (Extent != dynamic_extent ? Extent - Offset : Extent)> {};
285
290 template <typename T, std::size_t Extent>
291 struct ExtentAsBytesValue : public std::integral_constant<
292 std::size_t,
293 Extent == dynamic_extent ?
294 Extent : sizeof(T) * Extent> {};
295
296 template <std::size_t From, std::size_t To>
297 struct IsAllowedExtentConversion : public std::integral_constant<
298 bool, From == To || From == dynamic_extent || To == dynamic_extent> {};
299
300 template <class From, class To>
301 struct IsAllowedElementTypeConversion : public std::integral_constant<
302 bool, std::is_convertible<From(*)[], To(*)[]>::value> {};
303
304 template <class T>
305 struct IsSpanOracle : std::false_type {};
306
307 template <class T, std::size_t Extent>
308 struct IsSpanOracle<Span<T, Extent>> : std::true_type {};
309
310 template <class T>
311 struct IsSpan : public IsSpanOracle<typename std::remove_cv<T>::type> {};
312
313 // Re-implement std algorithms here to adopt CUDA.
314 template <typename T>
315 struct Less {
316 XGBOOST_DEVICE constexpr bool operator()(const T& _x, const T& _y) const {
317 return _x < _y;
318 }
319 };
320
321 template <typename T>
322 struct Greater {
323 XGBOOST_DEVICE constexpr bool operator()(const T& _x, const T& _y) const {
324 return _x > _y;
325 }
326 };
327
328 template <class InputIt1, class InputIt2,
329 class Compare =
330 detail::Less<decltype(std::declval<InputIt1>().operator*())>>
331 XGBOOST_DEVICE bool LexicographicalCompare(InputIt1 first1, InputIt1 last1,
332 InputIt2 first2, InputIt2 last2) {
333 Compare comp;
334 for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
335 if (comp(*first1, *first2)) {
336 return true;
337 }
338 if (comp(*first2, *first1)) {
339 return false;
340 }
341 }
342 return first1 == last1 && first2 != last2;
343 }
344
345 } // namespace detail
346
347
415 template <typename T,
416 std::size_t Extent = dynamic_extent>
417 class Span {
418 public:
419 using element_type = T; // NOLINT
420 using value_type = typename std::remove_cv<T>::type; // NOLINT
421 using index_type = std::size_t; // NOLINT
422 using difference_type = detail::ptrdiff_t; // NOLINT
423 using pointer = T*; // NOLINT
424 using reference = T&; // NOLINT
425
426 using iterator = detail::SpanIterator<Span<T, Extent>, false>; // NOLINT
427 using const_iterator = const detail::SpanIterator<Span<T, Extent>, true>; // NOLINT
428 using reverse_iterator = detail::SpanIterator<Span<T, Extent>, false>; // NOLINT
429 using const_reverse_iterator = const detail::SpanIterator<Span<T, Extent>, true>; // NOLINT
430
431 // constructors
432 constexpr Span() __span_noexcept = default;
433
434 XGBOOST_DEVICE Span(pointer _ptr, index_type _count) :
435 size_(_count), data_(_ptr) {
436 SPAN_CHECK(!(Extent != dynamic_extent && _count != Extent));
437 SPAN_CHECK(_ptr || _count == 0);
438 }
439
440 XGBOOST_DEVICE Span(pointer _first, pointer _last) :
441 size_(_last - _first), data_(_first) {
442 SPAN_CHECK(data_ || size_ == 0);
443 }
444
445 template <std::size_t N>
446 XGBOOST_DEVICE constexpr Span(element_type (&arr)[N]) // NOLINT
447 __span_noexcept : size_(N), data_(&arr[0]) {}
448
449 template <class Container,
450 class = typename std::enable_if<
451 !std::is_const<element_type>::value &&
452 !detail::IsSpan<Container>::value &&
453 std::is_convertible<typename Container::pointer, pointer>::value &&
454 std::is_convertible<typename Container::pointer,
455 decltype(std::declval<Container>().data())>::value>::type>
456 Span(Container& _cont) : // NOLINT
457 size_(_cont.size()), data_(_cont.data()) {
458 static_assert(!detail::IsSpan<Container>::value, "Wrong constructor of Span is called.");
459 }
460
461 template <class Container,
462 class = typename std::enable_if<
463 std::is_const<element_type>::value &&
464 !detail::IsSpan<Container>::value &&
465 std::is_convertible<typename Container::pointer, pointer>::value &&
466 std::is_convertible<typename Container::pointer,
467 decltype(std::declval<Container>().data())>::value>::type>
468 Span(const Container& _cont) : size_(_cont.size()), // NOLINT
469 data_(_cont.data()) {
470 static_assert(!detail::IsSpan<Container>::value, "Wrong constructor of Span is called.");
471 }
472
473 template <class U, std::size_t OtherExtent,
474 class = typename std::enable_if<
475 detail::IsAllowedElementTypeConversion<U, T>::value &&
476 detail::IsAllowedExtentConversion<OtherExtent, Extent>::value>>
477 XGBOOST_DEVICE constexpr Span(const Span<U, OtherExtent>& _other) // NOLINT
478 __span_noexcept : size_(_other.size()), data_(_other.data()) {}
479
480 XGBOOST_DEVICE constexpr Span(const Span& _other)
481 __span_noexcept : size_(_other.size()), data_(_other.data()) {}
482
483 XGBOOST_DEVICE Span& operator=(const Span& _other) __span_noexcept {
484 size_ = _other.size();
485 data_ = _other.data();
486 return *this;
487 }
488
489 XGBOOST_DEVICE ~Span() __span_noexcept {}; // NOLINT
490
491 XGBOOST_DEVICE constexpr iterator begin() const __span_noexcept { // NOLINT
492 return {this, 0};
493 }
494
495 XGBOOST_DEVICE constexpr iterator end() const __span_noexcept { // NOLINT
496 return {this, size()};
497 }
498
499 XGBOOST_DEVICE constexpr const_iterator cbegin() const __span_noexcept { // NOLINT
500 return {this, 0};
501 }
502
503 XGBOOST_DEVICE constexpr const_iterator cend() const __span_noexcept { // NOLINT
504 return {this, size()};
505 }
506
507 XGBOOST_DEVICE constexpr reverse_iterator rbegin() const __span_noexcept { // NOLINT
508 return reverse_iterator{end()};
509 }
510
511 XGBOOST_DEVICE constexpr reverse_iterator rend() const __span_noexcept { // NOLINT
512 return reverse_iterator{begin()};
513 }
514
515 XGBOOST_DEVICE constexpr const_reverse_iterator crbegin() const __span_noexcept { // NOLINT
516 return const_reverse_iterator{cend()};
517 }
518
519 XGBOOST_DEVICE constexpr const_reverse_iterator crend() const __span_noexcept { // NOLINT
520 return const_reverse_iterator{cbegin()};
521 }
522
523 // element access
524
525 XGBOOST_DEVICE reference front() const { // NOLINT
526 return (*this)[0];
527 }
528
529 XGBOOST_DEVICE reference back() const { // NOLINT
530 return (*this)[size() - 1];
531 }
532
533 XGBOOST_DEVICE reference operator[](index_type _idx) const {
534 SPAN_LT(_idx, size());
535 return data()[_idx];
536 }
537
538 XGBOOST_DEVICE reference operator()(index_type _idx) const {
539 return this->operator[](_idx);
540 }
541
542 XGBOOST_DEVICE constexpr pointer data() const __span_noexcept { // NOLINT
543 return data_;
544 }
545
546 // Observers
547 XGBOOST_DEVICE constexpr index_type size() const __span_noexcept { // NOLINT
548 return size_;
549 }
550 XGBOOST_DEVICE constexpr index_type size_bytes() const __span_noexcept { // NOLINT
551 return size() * sizeof(T);
552 }
553
554 XGBOOST_DEVICE constexpr bool empty() const __span_noexcept { // NOLINT
555 return size() == 0;
556 }
557
558 // Subviews
559 template <std::size_t Count>
560 XGBOOST_DEVICE Span<element_type, Count> first() const { // NOLINT
561 SPAN_CHECK(Count <= size());
562 return {data(), Count};
563 }
564
565 XGBOOST_DEVICE Span<element_type, dynamic_extent> first( // NOLINT
566 std::size_t _count) const {
567 SPAN_CHECK(_count <= size());
568 return {data(), _count};
569 }
570
571 template <std::size_t Count>
572 XGBOOST_DEVICE Span<element_type, Count> last() const { // NOLINT
573 SPAN_CHECK(Count <= size());
574 return {data() + size() - Count, Count};
575 }
576
577 XGBOOST_DEVICE Span<element_type, dynamic_extent> last( // NOLINT
578 std::size_t _count) const {
579 SPAN_CHECK(_count <= size());
580 return subspan(size() - _count, _count);
581 }
582
587 template <std::size_t Offset,
588 std::size_t Count = dynamic_extent>
589 XGBOOST_DEVICE auto subspan() const -> // NOLINT
590 Span<element_type,
591 detail::ExtentValue<Extent, Offset, Count>::value> {
592 SPAN_CHECK((Count == dynamic_extent) ?
593 (Offset <= size()) : (Offset + Count <= size()));
594 return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count};
595 }
596
597 XGBOOST_DEVICE Span<element_type, dynamic_extent> subspan( // NOLINT
598 index_type _offset,
599 index_type _count = dynamic_extent) const {
600 SPAN_CHECK((_count == dynamic_extent) ?
601 (_offset <= size()) : (_offset + _count <= size()));
602 return {data() + _offset, _count ==
603 dynamic_extent ? size() - _offset : _count};
604 }
605
606 private:
607 index_type size_ { 0 };
608 pointer data_ { nullptr };
609 };
610
611 template <class T, std::size_t X, class U, std::size_t Y>
612 XGBOOST_DEVICE bool operator==(Span<T, X> l, Span<U, Y> r) {
613 if (l.size() != r.size()) {
614 return false;
615 }
616 for (auto l_beg = l.cbegin(), r_beg = r.cbegin(); l_beg != l.cend();
617 ++l_beg, ++r_beg) {
618 if (*l_beg != *r_beg) {
619 return false;
620 }
621 }
622 return true;
623 }
624
625 template <class T, std::size_t X, class U, std::size_t Y>
626 XGBOOST_DEVICE constexpr bool operator!=(Span<T, X> l, Span<U, Y> r) {
627 return !(l == r);
628 }
629
630 template <class T, std::size_t X, class U, std::size_t Y>
631 XGBOOST_DEVICE constexpr bool operator<(Span<T, X> l, Span<U, Y> r) {
632 return detail::LexicographicalCompare(l.begin(), l.end(),
633 r.begin(), r.end());
634 }
635
636 template <class T, std::size_t X, class U, std::size_t Y>
637 XGBOOST_DEVICE constexpr bool operator<=(Span<T, X> l, Span<U, Y> r) {
638 return !(l > r);
639 }
640
641 template <class T, std::size_t X, class U, std::size_t Y>
642 XGBOOST_DEVICE constexpr bool operator>(Span<T, X> l, Span<U, Y> r) {
643 return detail::LexicographicalCompare<
644 typename Span<T, X>::iterator, typename Span<U, Y>::iterator,
645 detail::Greater<typename Span<T, X>::element_type>>(l.begin(), l.end(),
646 r.begin(), r.end());
647 }
648
649 template <class T, std::size_t X, class U, std::size_t Y>
650 XGBOOST_DEVICE constexpr bool operator>=(Span<T, X> l, Span<U, Y> r) {
651 return !(l < r);
652 }
653
654 template <class T, std::size_t E>
655 XGBOOST_DEVICE auto as_bytes(Span<T, E> s) __span_noexcept -> // NOLINT
656 Span<const byte, detail::ExtentAsBytesValue<T, E>::value> {
657 return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
658 }
659
660 template <class T, std::size_t E>
661 XGBOOST_DEVICE auto as_writable_bytes(Span<T, E> s) __span_noexcept -> // NOLINT
662 Span<byte, detail::ExtentAsBytesValue<T, E>::value> {
663 return {reinterpret_cast<byte*>(s.data()), s.size_bytes()};
664 }
665
666 } // namespace common
667 } // namespace xgboost
668
669 #if defined(_MSC_VER) &&_MSC_VER < 1910
670 #undef constexpr
671 #pragma pop_macro("constexpr")
672 #undef __span_noexcept
673 #endif // _MSC_VER < 1910
674
675 #endif // XGBOOST_SPAN_H_
xgboost::common::detail::SpanIterator::operator--
XGBOOST_DEVICE SpanIterator operator--(int)
Definition: span.h:203
xgboost::common::detail::Less::operator()
constexpr XGBOOST_DEVICE bool operator()(const T &_x, const T &_y) const
Definition: span.h:316
xgboost::common::detail::ptrdiff_t
typename std::conditional< std::is_same< std::ptrdiff_t, std::int64_t >::value, std::ptrdiff_t, std::int64_t >::type ptrdiff_t
Definition: span.h:129
xgboost::common::Span::Span
constexpr Span() __span_noexcept=default
xgboost::common::operator<=
constexpr XGBOOST_DEVICE bool operator<=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:637
xgboost::common::Span::end
constexpr XGBOOST_DEVICE iterator end() const __span_noexcept
Definition: span.h:495
xgboost::common::Span::last
XGBOOST_DEVICE Span< element_type, dynamic_extent > last(std::size_t _count) const
Definition: span.h:577
xgboost::common::detail::Greater::operator()
constexpr XGBOOST_DEVICE bool operator()(const T &_x, const T &_y) const
Definition: span.h:323
xgboost::common::detail::SpanIterator::operator--
XGBOOST_DEVICE SpanIterator & operator--()
Definition: span.h:197
__span_noexcept
#define __span_noexcept
span class based on ISO++20 span
Definition: span.h:71
xgboost::common::detail::SpanIterator::operator==
constexpr XGBOOST_DEVICE friend bool operator==(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:235
xgboost::common::detail::ExtentValue
Definition: span.h:282
xgboost::common::operator>=
constexpr XGBOOST_DEVICE bool operator>=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:650
xgboost::common::Span::Span
XGBOOST_DEVICE Span(pointer _first, pointer _last)
Definition: span.h:440
xgboost::common::Span< xgboost::Entry const >::index_type
std::size_t index_type
Definition: span.h:421
xgboost::common::byte
byte
Definition: span.h:139
xgboost::common::detail::IsAllowedExtentConversion
Definition: span.h:297
xgboost::common::operator==
XGBOOST_DEVICE bool operator==(Span< T, X > l, Span< U, Y > r)
Definition: span.h:612
xgboost::common::detail::SpanIterator::operator->
XGBOOST_DEVICE pointer operator->() const
Definition: span.h:180
xgboost::common::detail::SpanIterator::operator++
XGBOOST_DEVICE SpanIterator & operator++()
Definition: span.h:185
xgboost::common::Span< xgboost::Entry const >::element_type
xgboost::Entry const element_type
Definition: span.h:419
xgboost::common::detail::SpanIterator::operator-
XGBOOST_DEVICE SpanIterator operator-(difference_type n) const
Definition: span.h:225
xgboost::common::Span::subspan
XGBOOST_DEVICE Span< element_type, dynamic_extent > subspan(index_type _offset, index_type _count=dynamic_extent) const
Definition: span.h:597
xgboost::common::operator<
constexpr XGBOOST_DEVICE bool operator<(Span< T, X > l, Span< U, Y > r)
Definition: span.h:631
xgboost::common::detail::SpanIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: span.h:151
base.h
defines configuration macros of xgboost.
SPAN_CHECK
#define SPAN_CHECK(cond)
Definition: span.h:110
xgboost::common::Span::operator[]
XGBOOST_DEVICE reference operator[](index_type _idx) const
Definition: span.h:533
xgboost::common::detail::SpanIterator::operator>
constexpr XGBOOST_DEVICE friend bool operator>(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:255
xgboost::common::detail::LexicographicalCompare
XGBOOST_DEVICE bool LexicographicalCompare(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
Definition: span.h:331
xgboost::common::Span< xgboost::Entry const >::difference_type
detail::ptrdiff_t difference_type
Definition: span.h:422
xgboost::common::Span::back
XGBOOST_DEVICE reference back() const
Definition: span.h:529
xgboost::common::detail::SpanIterator::operator-=
XGBOOST_DEVICE SpanIterator & operator-=(difference_type n)
Definition: span.h:230
xgboost::common::Span::size_bytes
constexpr XGBOOST_DEVICE index_type size_bytes() const __span_noexcept
Definition: span.h:550
xgboost::common::detail::SpanIterator::difference_type
detail::ptrdiff_t difference_type
Definition: span.h:153
xgboost::common::Span::Span
constexpr XGBOOST_DEVICE Span(element_type(&arr)[N]) __span_noexcept
Definition: span.h:446
xgboost::common::operator>
constexpr XGBOOST_DEVICE bool operator>(Span< T, X > l, Span< U, Y > r)
Definition: span.h:642
xgboost::common::detail::SpanIterator::operator+=
XGBOOST_DEVICE SpanIterator & operator+=(difference_type n)
Definition: span.h:214
xgboost::common::detail::SpanIterator::operator*
XGBOOST_DEVICE reference operator*() const
Definition: span.h:172
xgboost::common::Span::empty
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:554
xgboost::common::dynamic_extent
constexpr std::size_t dynamic_extent
Definition: span.h:136
xgboost::common::detail::SpanIterator::SpanIterator
constexpr SpanIterator()=default
xgboost::common::detail::SpanIterator::operator+
XGBOOST_DEVICE SpanIterator operator+(difference_type n) const
Definition: span.h:209
xgboost::common::as_writable_bytes
XGBOOST_DEVICE auto as_writable_bytes(Span< T, E > s) __span_noexcept -> Span< byte, detail::ExtentAsBytesValue< T, E >::value >
Definition: span.h:661
xgboost::common::Span::begin
constexpr XGBOOST_DEVICE iterator begin() const __span_noexcept
Definition: span.h:491
xgboost::common::detail::SpanIterator
Definition: span.h:147
xgboost::common::Span< xgboost::Entry const >::reference
xgboost::Entry const & reference
Definition: span.h:424
xgboost::common::detail::SpanIterator::operator-
XGBOOST_DEVICE difference_type operator-(SpanIterator rhs) const
Definition: span.h:220
xgboost::common::detail::SpanIterator::operator[]
XGBOOST_DEVICE reference operator[](difference_type n) const
Definition: span.h:176
xgboost::common::Span::Span
Span(Container &_cont)
Definition: span.h:456
xgboost::common::Span::subspan
XGBOOST_DEVICE auto subspan() const -> Span< element_type, detail::ExtentValue< Extent, Offset, Count >::value >
Definition: span.h:589
xgboost::common::detail::SpanIterator::SpanIterator
constexpr XGBOOST_DEVICE SpanIterator(const SpanIterator< SpanType, B > &other_) __span_noexcept
Definition: span.h:168
xgboost::common::operator!=
constexpr XGBOOST_DEVICE bool operator!=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:626
xgboost::common::Span::front
XGBOOST_DEVICE reference front() const
Definition: span.h:525
xgboost::common::detail::SpanIterator::span_
const SpanType * span_
Definition: span.h:266
xgboost::common::detail::SpanIterator::operator<
constexpr XGBOOST_DEVICE friend bool operator<(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:245
xgboost::common::Span::operator()
XGBOOST_DEVICE reference operator()(index_type _idx) const
Definition: span.h:538
xgboost::common::detail::IsSpanOracle
Definition: span.h:305
xgboost::common::Span< xgboost::Entry const >::value_type
typename std::remove_cv< xgboost::Entry const >::type value_type
Definition: span.h:420
xgboost::common::detail::SpanIterator::operator<=
constexpr XGBOOST_DEVICE friend bool operator<=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:250
xgboost::common::Span::crend
constexpr XGBOOST_DEVICE const_reverse_iterator crend() const __span_noexcept
Definition: span.h:519
xgboost::common::Span::first
XGBOOST_DEVICE Span< element_type, dynamic_extent > first(std::size_t _count) const
Definition: span.h:565
xgboost::common::Span::rbegin
constexpr XGBOOST_DEVICE reverse_iterator rbegin() const __span_noexcept
Definition: span.h:507
xgboost::common::detail::SpanIterator::operator>=
constexpr XGBOOST_DEVICE friend bool operator>=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:260
xgboost::common::Span< xgboost::Entry const >::pointer
xgboost::Entry const * pointer
Definition: span.h:423
SPAN_LT
#define SPAN_LT(lhs, rhs)
Definition: span.h:117
xgboost::common::detail::Greater
Definition: span.h:322
xgboost::common::Span::first
XGBOOST_DEVICE Span< element_type, Count > first() const
Definition: span.h:560
xgboost::common::detail::IsSpan
Definition: span.h:311
xgboost::common::Span
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:142
xgboost::common::Span::operator=
XGBOOST_DEVICE Span & operator=(const Span &_other) __span_noexcept
Definition: span.h:483
xgboost::common::detail::IsAllowedElementTypeConversion
Definition: span.h:301
xgboost::common::Span::cbegin
constexpr XGBOOST_DEVICE const_iterator cbegin() const __span_noexcept
Definition: span.h:499
xgboost::common::Span::crbegin
constexpr XGBOOST_DEVICE const_reverse_iterator crbegin() const __span_noexcept
Definition: span.h:515
xgboost::common::Span::size
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:547
xgboost::common::Span::last
XGBOOST_DEVICE Span< element_type, Count > last() const
Definition: span.h:572
xgboost::common::Span::data
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:542
xgboost::common::Span::cend
constexpr XGBOOST_DEVICE const_iterator cend() const __span_noexcept
Definition: span.h:503
xgboost::common::as_bytes
XGBOOST_DEVICE auto as_bytes(Span< T, E > s) __span_noexcept -> Span< const byte, detail::ExtentAsBytesValue< T, E >::value >
Definition: span.h:655
xgboost::common::Span::Span
Span(const Container &_cont)
Definition: span.h:468
xgboost::common::detail::ExtentAsBytesValue
Definition: span.h:291
xgboost::common::detail::SpanIterator::operator++
XGBOOST_DEVICE SpanIterator operator++(int)
Definition: span.h:191
xgboost::common::Span::Span
constexpr XGBOOST_DEVICE Span(const Span &_other) __span_noexcept
Definition: span.h:480
xgboost::common::detail::SpanIterator::operator!=
constexpr XGBOOST_DEVICE friend bool operator!=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:240
xgboost::common::detail::SpanIterator::pointer
typename std::add_pointer< reference >::type pointer
Definition: span.h:157
xgboost::common::detail::SpanIterator::reference
typename std::conditional< IsConst, const ElementType, ElementType >::type & reference
Definition: span.h:156
xgboost::common::detail::SpanIterator::index_
SpanType::index_type index_
Definition: span.h:267
XGBOOST_DEVICE
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
xgboost::common::detail::Less
Definition: span.h:315
xgboost::common::detail::SpanIterator::value_type
typename SpanType::value_type value_type
Definition: span.h:152
xgboost::common::Span::~Span
XGBOOST_DEVICE ~Span() __span_noexcept
Definition: span.h:489
xgboost
namespace of xgboost
Definition: base.h:110
xgboost::common::Span::rend
constexpr XGBOOST_DEVICE reverse_iterator rend() const __span_noexcept
Definition: span.h:511
xgboost::common::detail::SpanIterator::SpanIterator
constexpr XGBOOST_DEVICE SpanIterator(const SpanType *_span, typename SpanType::index_type _idx) __span_noexcept
Definition: span.h:161
xgboost::common::Span::Span
constexpr XGBOOST_DEVICE Span(const Span< U, OtherExtent > &_other) __span_noexcept
Definition: span.h:477