-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Improving BinaryOpsKernel.cu #29428
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
Improving BinaryOpsKernel.cu #29428
Conversation
| } | ||
|
|
||
| void logical_xor_kernel_cuda(TensorIterator& iter) { | ||
| if (iter.common_dtype() == ScalarType::Bool) { |
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.
This logic is useless
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.
Seems like so. Perhaps deleting this logical for all comparison ops will speed up sufficiently without the need to split.
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.
@xuhdev Even splitted, BinaryCompareKernel.cu still takes 2min 44s to compile
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.
If every function in BinaryCompareKernel.cu is cut into half, then it may be reduced down to a reasonable time. I believe the functions in BinaryCompareKernel.cu might be the bottleneck.
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.
Hmm, this PR already cut it into half, but it still takes more than 2 minutes...
|
|
||
| void lt_kernel_cuda(TensorIterator& iter) { | ||
| if (iter.common_dtype() == ScalarType::Bool) { | ||
| AT_DISPATCH_ALL_TYPES_AND2(kHalf, kBool, iter.input_dtype(), "lt_cpu", [&]() { |
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.
should be lt_cuda
| } | ||
|
|
||
| void lt_kernel_cuda(TensorIterator& iter) { | ||
| if (iter.common_dtype() == ScalarType::Bool) { |
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.
This logic is useless either. With the dynamic casting approach in TensorIterator, it always does the computation in common dtype and stores the result as the common dtype and then dynamically cast it into bool.
|
@ngimel @VitalyFedyunin Could you please take a look at this? You reviewed the dynamic casting of TensorIterator. |
VitalyFedyunin
left a comment
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.
Would be nice to add benchmark results for changed operators like logical_xor_kernel_cuda
|
@VitalyFedyunin Benchmarks shows the performance change very little: import torch
print(torch.__version__)
print(torch.version.git_version)
print()
print('=' * 20)
for size in [10, 1000000, 100000000]:
for dtype in [torch.float, torch.bool]:
print('size:', size, ', dtype:', dtype)
a = torch.randn(size, device='cuda').to(dtype)
print('compare ops')
torch.cuda.synchronize()
%timeit a < a; torch.cuda.synchronize()
print('logical_xor')
torch.cuda.synchronize()
%timeit torch.logical_xor(a, a); torch.cuda.synchronize()
print()
print('-' * 20)before after |
facebook-github-bot
left a comment
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.
@VitalyFedyunin has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@VitalyFedyunin Is the internal failure real? |
Summary: - Building `BinaryOpsKernel.cu` takes extremely long. Split the original file into 3 pieces, and copy-paste code into these files. - Remove some useless logic - change some wrong ops name `*_cpu` -> `*_cuda` Pull Request resolved: pytorch/pytorch#29428 Differential Revision: D18408858 Pulled By: VitalyFedyunin fbshipit-source-id: 29323b0bc40a928ae698345ad1ffe46c5851b012
|
@VitalyFedyunin merged this pull request in 01ad2bc. |
BinaryOpsKernel.cutakes extremely long. Split the original file into 3 pieces, and copy-paste code into these files.*_cpu->*_cuda