Skip to content

Commit

Permalink
Add doc for Span iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Aug 13, 2018
1 parent e22eaac commit b5ea229
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/common/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,29 @@ XGBOOST_DEVICE bool LexicographicalCompare(InputIt1 first1, InputIt1 last1,
* device_vector::data() returns a wrapped pointer.
* It's unclear that what kind of thrust algorithm can be used without
* memory error. See the test case "GPUSpan.WithTrust"
*
* Pass iterator to kernel:
* Not possible. Use subspan instead.
*
* The underlying Span in SpanIterator is a pointer, but CUDA pass kernel
* parameter by value. If we were to hold a Span value instead of a
* pointer, the following snippet will crash, violating the safety
* purpose of Span:
*
* \code{.cpp}
* Span<float> span {arr_a};
* auto beg = span.begin();
*
* Span<float> span_b = arr_b;
* span = span_b;
*
* delete arr_a;
* beg++; // crash
* \endcode
*
* While hoding a pointer or reference should avoid the problem, its a
* compromise. Since we have subspan, it's acceptable not to support
* passing iterator.
*/
template <typename T,
detail::ptrdiff_t Extent = dynamic_extent>
Expand Down

0 comments on commit b5ea229

Please sign in to comment.