Repository navigation
Introducing (Const)StridedRandomAccessor + CompositeRandomAccessor + migrate sort to ATen (CPU) - #39744
Introducing (Const)StridedRandomAccessor + CompositeRandomAccessor + migrate sort to ATen (CPU)#39744nikitaved wants to merge 10 commits into
sort to ATen (CPU)#39744Conversation
|
Wow! It's pretty cool that you implemented the random-access iterator! I think this PR also paves the roads for a stable sort with |
💊 CI failures summary and remediationsAs of commit 5975f98 (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 77 times. |
sort to ATen
sort to ATensort to ATen (CPU)
3fc19b9 to
647eb16
Compare
a6c143b to
c05afe3
Compare
sort to ATen (CPU)sort to ATen (CPU)
|
Do you think there should be unit tests for all of the accessor methods? It's a pretty extensive API. |
|
So far I test with |
|
@nikitaved , woops, accidentally edited your comment instead of replying, sorry! If |
|
@kurtamohler , well, more tests never do harm :) Do you know how I could add cpp tests? |
|
You might be able to put it in If |
| template <typename scalar_t> | ||
| struct KeyValueCompAsc { | ||
| template <typename LHS, typename RHS> | ||
| constexpr bool operator()(LHS lhs, RHS rhs) const { | ||
| return (!_isnan<scalar_t>(get<0>(lhs)) && _isnan<scalar_t>(get<0>(rhs))) | ||
| || (get<0>(lhs) < get<0>(rhs)); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Add a comment why we need typename LHS & RHS here.
|
@glaringlee , note that |
@nikitaved putting |
|
@glaringlee , got it! Thank you for this clarification :) |
|
@glaringlee , and what about the TensorIterator traversal? Does it make sense to move it from |
The sort_kernel related stuff can be moved out from cpu folder for sure. The topk_kernel seems fine to me as well. But if we want to move that out as well, need to do small benchmark to make sure the perf of topk_kernel doesn't change. |
|
After moving Outside Inside lscpu |
|
@nikitaved give me 30mins, I'll do a test. |
|
@glaringlee , do you want me to push the commit that moves things? |
Codecov Report
@@ Coverage Diff @@
## master #39744 +/- ##
=======================================
Coverage 67.83% 67.83%
=======================================
Files 384 384
Lines 49945 49945
=======================================
+ Hits 33881 33882 +1
+ Misses 16064 16063 -1
Continue to review full report at Codecov.
|
I think
@nikitaved Let's keep the code in cpu folder then. Sorry about this back and force. |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@glaringlee has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@nikitaved One more thing i want to ask is that. I saw the benchmark you post. For 3D tensor, the new benchmark is much faster than the old code, this probably due to the parallel computing that supported by Tensoriterator. Can you do a benchmark to test the performance of your code under single thread? |
|
Will do, a more thorough benchmarking was done here: I have updated the benchmark in the header. Only single thread was used. |
|
@nikitaved Thanks a lot. I noticed that you actually rebased this code today. I will go ahead to land this once the fb internal tests are done. |
facebook-github-bot
left a comment
There was a problem hiding this comment.
@glaringlee has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@glaringlee , thank you for taking care of this one! |
|
@glaringlee merged this pull request in 9dc2bcd. |
This PR introduces a (Const)StridedRandomAccessor, a random access iterator over a strided array, and a CompositeRandomAccessor, a random access iterator over two random access iterators.
The main motivation is to be able to use a handful of operations from STL and thrust in numerous dim-apply types of algorithms and eliminate unnecessary buffer allocations. Plus more advanced algorithms are going to be available with C++17.
Porting
sortprovides a hands-on example of how these iterators could be used.Fixes #24770.
Some benchmarks:
Master
This PR
As you can see, the legacy sorting routine is actually quite efficient. The performance gain is likely due to the improved reduction with TensorIterator.