diff --git a/src/common/span.h b/src/common/span.h index d66bcbe85c96..ec5a38bcf80c 100644 --- a/src/common/span.h +++ b/src/common/span.h @@ -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 span {arr_a}; + * auto beg = span.begin(); + * + * Span 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