Skip to content

Conversation

@Janicewei
Copy link
Contributor

bitwise and kernel with two tensor inputs, only accept integer and boolean

type checks needed

@yodada
Copy link
Contributor

yodada commented Oct 8, 2020

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");
Copy link
Contributor

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,

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants