Skip to content

Commit

Permalink
Force guards when performing boolean operations on XLASymNode (#6433)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezyang authored Feb 2, 2024
1 parent ad822bf commit fe604e9
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions torch_xla/csrc/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,23 +761,28 @@ c10::SymNode XLASymNodeImpl::sym_max(const c10::SymNode& other) {
<< " has not been implemented.";
}

// It is used to compute contiguity fields on tensors like "is non overlapping
// and dense" and it's never fetched. If they are never fetched it is fine for
// them to error only if poked.
// Force guards when performing these logical operations

c10::SymNode XLASymNodeImpl::sym_or(const c10::SymNode& other) {
auto error_node = torch::lazy::MakeNode<SizeError>();
return c10::make_intrusive<XLASymNodeImpl>(error_node, PyType::BOOL);
auto a =
guard_bool(__FILE__, __LINE__) || other->guard_bool(__FILE__, __LINE__);
auto cnst = torch::lazy::MakeNode<SizeConstant>(a);
return c10::make_intrusive<XLASymNodeImpl>(cnst, PyType::BOOL);
}

c10::SymNode XLASymNodeImpl::sym_and(const c10::SymNode& other) {
XLA_CHECK(false) << "XLASymNodeImpl::" << __FUNCTION__
<< " has not been implemented.";
auto a =
guard_bool(__FILE__, __LINE__) && other->guard_bool(__FILE__, __LINE__);
auto cnst = torch::lazy::MakeNode<SizeConstant>(a);
return c10::make_intrusive<XLASymNodeImpl>(cnst, PyType::BOOL);
}

c10::SymNode XLASymNodeImpl::sym_not() {
XLA_CHECK(false) << "XLASymNodeImpl::" << __FUNCTION__
<< " has not been implemented.";
auto a = !guard_bool(__FILE__, __LINE__);
auto cnst = torch::lazy::MakeNode<SizeConstant>(a);
return c10::make_intrusive<XLASymNodeImpl>(cnst, PyType::BOOL);
}

// NB: self is ignored here, only the arguments are used
c10::SymNode XLASymNodeImpl::is_contiguous(at::ArrayRef<c10::SymNode> sizes,
at::ArrayRef<c10::SymNode> strides) {
Expand Down

0 comments on commit fe604e9

Please sign in to comment.