forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Equal.cpp
32 lines (28 loc) · 889 Bytes
/
Equal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define TORCH_ASSERT_ONLY_METHOD_OPERATORS
#include <ATen/core/Tensor.h>
#include <ATen/NamedTensorUtils.h>
#ifndef AT_PER_OPERATOR_HEADERS
#include <ATen/NativeFunctions.h>
#include <ATen/CUDAFunctions.h>
#else
#include <ATen/ops/eq_cuda_dispatch.h>
#include <ATen/ops/equal_native.h>
#endif
namespace at::native {
bool cuda_equal(const Tensor& self, const Tensor &src) {
if (!at::namedinference::are_names_equal(
self.unsafeGetTensorImpl(), src.unsafeGetTensorImpl())) {
return false;
}
at::NoNamesGuard guard;
TORCH_CHECK(self.device() == src.device(), "Cannot compare two tensors on "
"different devices. Got: ", self.device(), " and ", src.device());
if (self.sizes() != src.sizes()) {
return false;
}
if (self.numel() == 0) {
return true;
}
return at::cuda::eq(self, src).all().item().to<bool>();
}
} // namespace at::native