-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Span class. #3548
Span class. #3548
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good in general. I'm wondering if we need all of the functionality here. We could possibly make this more light weight by removing the "as_bytes" functions and span vs span comparison functions. It is hard to see the use case for these in xgboost.
Although, maybe there is an argument for having a more complete implementation true to the standard.
src/common/span.h
Outdated
|
||
XGBOOST_DEVICE reference operator[](index_type idx) const { | ||
SPAN_CHECK(idx >= 0 && idx < size()); | ||
SPAN_CHECK(idx >= 0 && idx < size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate check here.
tests/cpp/common/test_span.cc
Outdated
|
||
TEST(Span, Constructors) { | ||
// Dynamic extent | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two tests are identical.
Span<float> s {nullptr, static_cast<Span<float>::index_type>(0)}; | ||
ASSERT_EQ(s.size(), 0); | ||
ASSERT_EQ(s.data(), nullptr); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More duplicated tests.
@RAMitchell I will re-visit all test cases, see what's been missing. |
5699264
to
9ac5392
Compare
Codecov Report
@@ Coverage Diff @@
## master #3548 +/- ##
============================================
+ Coverage 47.85% 49.79% +1.94%
Complexity 188 188
============================================
Files 169 172 +3
Lines 13330 13868 +538
Branches 457 457
============================================
+ Hits 6379 6906 +527
- Misses 6726 6737 +11
Partials 225 225
Continue to review full report at Codecov.
|
Not ready yet, seems tests is still not thorough enough. |
3f3e0b5
to
0aa4f4e
Compare
@hcho3 as noted by @trivialfis there is actually an array_view class in dmlc-core. After a brief look it seems it is used by the nvvm/tv projects. We could replace array_view with our span which is more powerful, better tested and compliant with the upcoming standard. What do you think? |
@RAMitchell You should file a pull request at dmlc-core and make a case for upgrading array_view with the span class. There seems to be a good amount of code using array_view already and it would take some work to replace all occurrences. For the sake of lesser friction, you could simply add the span class to dmlc-core and have DMLC projects gracefully adopt it. |
df41bc5
to
67d6718
Compare
@RAMitchell Ready for another review. The Travis failed fetching packages in Python test, it should be fine on a good day. The last commit is just a toy show case for using Span in kernel code. It could be reverted for a more formal integration if the rest of the code is suitable for merge. EDIT: Later dealing with the DVec will take some time. I need to understand the whole algorithm for better integration. |
Looks good. One more thing to consider, span will incur a performance overhead when using the operator[], these changes will have worsened performance in places like this: xgboost/src/data/simple_dmatrix.cc Line 61 in a960391
This can be fixed by changing this to a range based for loop, I believe this does not need to do any index checking. Edit: Looks like you have actually already done this :) |
DVec can be dealt with later. My idea is that we can gradually enforce the usage of span across the code base using the clang-tidy linter. The most important algorithm for us is gpu_hist as it is used a lot in production, so maybe we can start there when you are ready. I think this should be good to merge when the CI tests pass. |
@RAMitchell So it passed. \0/ |
e277399
to
cdf3ccf
Compare
b5ea229
to
a474c07
Compare
Implement span class from ISO++20 for safer pointer indexing.
TODOs: