-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Enabled add, sum and mul for bool tensor #21032
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
Conversation
colesbury
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.
This needs a test for sum(). Where are the modifications for CUDA?
| } | ||
|
|
||
| template <typename T> | ||
| T multiply(T a, T b) { |
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.
Try to avoid this. * should work on bool. You might need to add an overload to Vec256.
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.
It would work without this but the build on CircleCi is failing due to an error about bad usage of "*" with two bools.
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.
Then suppress the warning. I'm not a fan of unnecessarily verbose code driven by the compiler's preferences.
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.
@cpuhrsch, made a good argument against adding an overload to Vec256.
Also, i dont feel comfortable with fully blocking warning for cases like this. If there was a way to block it for this method, i would be fine but as far as i can tell - we block gcc warnings for the whole project and i dont think its a good way to go.
Please, let me know if you have strong preferences here
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.
#pragma GCC diagnostic ignored "-Wint-in-bool-context"
We should stick to the same operators because it keeps the code simple and reduces the chances of incorrect behavior. For example, this PR previously had an incorrect definition of - because it didn't use operator- -- it was the opposite of how - operates on a bool in both C/C++ and Python.
|
|
||
| static void neg_kernel(TensorIterator& iter) { | ||
| AT_DISPATCH_ALL_TYPES(iter.dtype(), "neg_cpu", [&]() { | ||
| if (iter.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 doesn't look right. We shouldn't implement unary - on bool. We should implement bitwise not (unary ~) instead.
It's also worth noting that this is the opposite of C++ behavior. For example:
bool x = ...
bool y = -x;
x and y have the same value (because 0=>0=>false and 1=>-1=>true)
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.
removing this change for now. will implement this as a separate PR
| static inline __host__ __device__ bool ge(uint8_t a, uint8_t b) { return a >= b; } | ||
| static inline __host__ __device__ bool eq(uint8_t a, uint8_t b) { return a == b; } | ||
| static inline __host__ __device__ bool ne(uint8_t a, uint8_t b) { return a != b; } | ||
| static inline __host__ __device__ bool min() { return at::numeric_limits<bool>::lowest(); } |
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.
Where is this used? We shouldn't be using THCNumerics in these functions any more and should try to avoid adding anything to it.
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.
Please see the build error for a previous PR in the stack. I moved numerics changes to the previous PR.
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
|
Don't forget to fix lint |
| template <> Vec256<bool> inline operator*(const Vec256<bool> &a, const Vec256<bool> &b) { | ||
| Vec256<bool> c = Vec256<bool>(); | ||
| for (int i = 0; i != Vec256<bool>::size(); i++) { | ||
| c[i] = a[i] && b[i]; |
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.
Not sure if it is going to work in your case, but please consider checking https://scc.ustc.edu.cn/zlsc/sugon/intel/compiler_c/main_cls/index.htm#intref_cls/common/intref_avx_fmadd_pd.htm
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
|
@pytorchbot retest this please |
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
|
@pytorchbot retest this please |
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Enabled add, sum, mul and neg for bool tensor gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
Summary: Pull Request resolved: pytorch/pytorch#21032 ghimport-source-id: 6ab21752b4af451e8b10a0e02cd5d726aa7472f0 Differential Revision: D15530496 Pulled By: izdeby fbshipit-source-id: f4f83aa80eafbb4f307aadc1a13d8cdcf3055c24
|
this added support for subtraction with bools (by accident?) but it's not tested anywhere. |
Stack from ghstack:
This PR is a part of a stack which will change result tensor type of comparison ops from uint8 to bool. As this change is rather big and a lot of prep work is needed, im breaking it into a stack.
Changes in this PR:
Differential Revision: D15530496