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
Implement kthvalue in ATen #17544
Implement kthvalue in ATen #17544
Conversation
The CPU version is based on the TH version. The GPU version is based on pytorch#8406 by Pararth Shah (thank you). As discussed with @izdeby, this splits out a small(ish) chunk from pytorch#17232, the other bits will follow in spearate PRs. Plan for PRs: - This - Sort - TopK + Mode + Median in any order - Rip out THC stuff. There may be utility functions in the SortingCommon.cuh that come into relevance only with sort. I hope this is more digestible..
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.
Thomas, thanks again for breaking the original PR into a smaller chunks.
Going forward, could you, please, include some info in the description about which methods you are renaming and where are you moving them? That would help a lot.
*topK = TopKTypeConfig<scalar_t>::deconvert(desired); | ||
} | ||
} // namespace native | ||
} // namespace at |
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.
two questions about this file:
- Im just curious why is gatherTopK in cuda/SortingKthValue.cu instead of being here?
- Did you check if some the ported code can me deleted in TH or is it still being used somewhere?
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.
- I only moved those bits into the cuh that are used by more than one file eventually, but I can move it to the .cuh if you prefer. (But I hope it's gatherKthValue. :) ) That said I'm not entirely sure whether it's still as relevant as it used to be, but the THC code went to great length to reduce the sizes of compilation units - splitting the scalar type files etc., so I think keeping the .cuh minimal is a feature.
- I don't think much can go - the THC code needs to stay in until we move topk. Also mode needs kth value for now.
Can we kill the _th_kthvalue declaration in the Declarations.cwrap as a part of this PR or is it still needed? |
LGTM. lets make sure that all tests are passing and its good to go |
@pytorchbot merge this, please |
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.
@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: The CPU version is based on the TH version. The GPU version is based on #8406 by Pararth Shah (thank you). CPU quickselect based on that in TH's THTensorMoreMath.cpp, but with C++ (quickselectnoindex will be achieved by a different swap) CPU kthvalue is based on the THTensor function in the same file. The dim_apply function is a C++ replacement for TH_TENSOR_DIM_APPLYx macros. The CUDA kernel uses functions adapted from the THCTensorSortK implementation. In particular radixSelect is from THCTensorTopK.cuh. The CUDA launcher code replaces a bunch of macros with C++. It will be re-used in one of the following patches. Plan for further PRs: - This - Sort - TopK + Mode + Median in any order - Rip out THC stuff. There may be utility functions / structs in the SortingCommon.cuh that come into relevance only with sort. Pull Request resolved: pytorch/pytorch#17544 Differential Revision: D14286934 Pulled By: ezyang fbshipit-source-id: 35dbea050b097e88777ac5fa5c0f499d5e23c738
Summary: This moves median to ATen. - median with dimension reduces to kthvalue - median without dimension (aka medianall) is implemented in parallel to kthvalue because we would not want to reshape (copying for non-contiguous) and then copy again in kthvalue. We can sue the helper functions we moved from kthvalue. - `median_cuda` was accidentally already put into ATen in #17544. - The quickselect algorthm without indices for CPU in TH is now obsolete and removed. Pull Request resolved: #17637 Differential Revision: D14346510 Pulled By: ezyang fbshipit-source-id: c07ad144efbd6b4194179bb1c02635862521d8cb
The CPU version is based on the TH version.
The GPU version is based on #8406 by Pararth Shah (thank you).
CPU quickselect based on that in TH's THTensorMoreMath.cpp, but with C++ (quickselectnoindex will be achieved by a different swap)
CPU kthvalue is based on the THTensor function in the same file.
The dim_apply function is a C++ replacement for TH_TENSOR_DIM_APPLYx macros.
The CUDA kernel uses functions adapted from the THCTensorSortK implementation.
In particular radixSelect is from THCTensorTopK.cuh.
The CUDA launcher code replaces a bunch of macros with C++. It will be re-used in one of the following patches.
Plan for further PRs:
There may be utility functions / structs in the SortingCommon.cuh that come into
relevance only with sort.