-
Couldn't load subscription status.
- Fork 10
bitwise and kernel #156
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
base: master
Are you sure you want to change the base?
bitwise and kernel #156
Conversation
|
I think you mentioned that bitwise and works for booleans as well, right? We probably need a test for booleans as well. |
| Tensor and_kernel_hb(const Tensor& self, const Tensor& other) { | ||
| TORCH_CHECK(self.numel() == other.numel(), "The size of two tensors should match."); | ||
| // TORCH_CHECK(self.scalar_type() == ScalarType::Int || self.scalar_type() == ScalarType::Bool, "HammerBlade and is implemented for Int and Bool only"); | ||
| // TORCH_CHECK(other.scalar_type() == ScalarType::Int || other.scalar_type() == ScalarType::Bool, "HammerBlade and is implemented for Int and Bool only"); |
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 you want to check the data type of tensors, the canonical way is like this
./aten/src/ATen/native/BinaryOps.cpp:94: TORCH_CHECK(self.scalar_type() != kBool || other.scalar_type() != kBool,
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.
Actually, with boolean data the emulator segfaults when you want to quit ... I kind of think the reason is your kernel uses 32bit int internally, and I'm not too sure about the size of booleans
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.
>>> x = torch.ones(10, dtype=torch.bool)
>>> x.element_size()
1
yeah so a booleans is a single byte in pytorch
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.
Actually, with boolean data the emulator segfaults when you want to quit ... I kind of think the reason is your kernel uses 32bit int internally, and I'm not too sure about the size of booleans
how can I get around with the segfault?
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 made two functions in kernel_and (one for int and one for bool). If type is bool, do bool fun; if type is int do int fun. But I still have segfault for bool type.
bitwise and kernel with two tensor inputs, only accept integer and boolean
type checks needed