Skip to content

Conversation

@izdeby
Copy link
Contributor

@izdeby izdeby commented May 28, 2019

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:

  • Enable add, sum, mul and neg for bool tensors.

Differential Revision: D15530496

Copy link
Member

@colesbury colesbury left a 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) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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) {
Copy link
Member

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)

Copy link
Contributor Author

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(); }
Copy link
Member

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.

Copy link
Contributor Author

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
@izdeby izdeby changed the title Enabled add, sum, mul and neg for bool tensor [WIP] Enabled add, sum, mul and neg for bool tensor May 28, 2019
@izdeby izdeby requested a review from colesbury May 28, 2019 21:39
izdeby added 2 commits May 28, 2019 15:38
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
@izdeby izdeby changed the title [WIP] Enabled add, sum, mul and neg for bool tensor [WIP] Enabled add, sum and mul for bool tensor May 28, 2019
@izdeby izdeby changed the title [WIP] Enabled add, sum and mul for bool tensor Enabled add, sum and mul for bool tensor May 28, 2019
izdeby added 2 commits May 28, 2019 17:43
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
@ezyang
Copy link
Contributor

ezyang commented May 29, 2019

Don't forget to fix lint

@ezyang ezyang removed their request for review May 29, 2019 11:25
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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enabled add, sum, mul and neg for bool tensor

gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
@izdeby izdeby requested a review from ezyang May 29, 2019 15:56
izdeby added 2 commits May 29, 2019 10:26
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
@izdeby izdeby changed the title Enabled add, sum and mul for bool tensor [WIP] Enabled add, sum and mul for bool tensor May 29, 2019
izdeby added 2 commits May 29, 2019 14:18
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
@izdeby
Copy link
Contributor Author

izdeby commented May 29, 2019

@pytorchbot retest this please

Enabled add, sum, mul and neg for bool tensor

gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
@izdeby
Copy link
Contributor Author

izdeby commented May 30, 2019

@pytorchbot retest this please

@izdeby izdeby changed the title [WIP] Enabled add, sum and mul for bool tensor Enabled add, sum and mul for bool tensor May 30, 2019
Enabled add, sum, mul and neg for bool tensor

gh-metadata: pytorch pytorch 21032 gh/izdeby/3/head
izdeby added 9 commits May 29, 2019 19:43
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
@zou3519 zou3519 deleted the gh/izdeby/3/head branch May 30, 2019 23:14
zdevito pushed a commit to zdevito/ATen that referenced this pull request May 31, 2019
Summary:
Pull Request resolved: pytorch/pytorch#21032
ghimport-source-id: 6ab21752b4af451e8b10a0e02cd5d726aa7472f0

Differential Revision: D15530496

Pulled By: izdeby

fbshipit-source-id: f4f83aa80eafbb4f307aadc1a13d8cdcf3055c24
@facebook-github-bot
Copy link
Contributor

@izdeby merged this pull request in 9a22cb9.

@gchanan
Copy link
Contributor

gchanan commented Jun 5, 2019

this added support for subtraction with bools (by accident?) but it's not tested anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: cpu CPU specific problem (e.g., perf, algorithm) module: cuda Related to torch.cuda, and CUDA support in general

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants