forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LegacyDefinitions.cpp
79 lines (71 loc) · 3.38 KB
/
LegacyDefinitions.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <ATen/ATen.h>
#include <ATen/NativeFunctions.h>
#include <ATen/LegacyTHFunctionsCUDA.h>
#include <ATen/NamedTensorUtils.h>
#include <ATen/ExpandUtils.h>
#include <ATen/MemoryOverlap.h>
namespace at { namespace native {
// Methods
Tensor & masked_fill__cuda(Tensor& self, const Tensor & mask, Scalar value) {
auto maybe_outnames = namedinference::broadcast_to_outnames(self, mask, "masked_fill_");
if (at::has_internal_overlap(self) == MemOverlap::YES) {
TORCH_WARN(
"Use of masked_fill_ on expanded tensors is deprecated. "
"Please clone() the tensor before performing this operation. "
"This also applies to advanced indexing e.g. tensor[mask] = scalar");
}
at::assert_no_partial_overlap(self, mask);
Tensor b_mask;
std::tie(b_mask) = expand_inplace(self, mask, "masked_fill_");
// As we dispatch on self and TH is type-checked, we need different definitions.
// This can be fixed by moving to ATen.
if (b_mask.dtype() == at::ScalarType::Byte) {
TORCH_WARN("masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated," \
"please use a mask with dtype torch.bool instead.");
legacy::cuda::_th_masked_fill_(self, b_mask, value);
} else {
legacy::cuda::_th_masked_fill_bool_(self, b_mask, value);
}
namedinference::propagate_names_if_nonempty(self, maybe_outnames);
return self;
}
Tensor & masked_fill__cuda(Tensor& self, const Tensor & mask, const Tensor & value) {
auto maybe_outnames = namedinference::broadcast_to_outnames(self, mask, "masked_fill_");
if (at::has_internal_overlap(self) == MemOverlap::YES) {
TORCH_WARN(
"Use of masked_fill_ on expanded tensors is deprecated. "
"Please clone() the tensor before performing this operation. "
"This also applies to advanced indexing e.g. tensor[mask] = scalar");
}
at::assert_no_partial_overlap(self, mask);
TORCH_CHECK(value.dim() == 0, "masked_fill_ only supports a 0-dimensional value tensor, but got tensor "
"with ", value.dim(), " dimension(s).");
Tensor b_mask;
std::tie(b_mask) = expand_inplace(self, mask, "masked_fill_");
// As we dispatch on self and TH is type-checked, we need different definitions.
// This can be fixed by moving to ATen.
if (b_mask.dtype() == at::ScalarType::Byte) {
TORCH_WARN("masked_fill_ received a mask with dtype torch.uint8, this behavior is now deprecated," \
"please use a mask with dtype torch.bool instead.");
legacy::cuda::_th_masked_fill_(self, b_mask, value.item());
} else {
legacy::cuda::_th_masked_fill_bool_(self, b_mask, value.item());
}
namedinference::propagate_names_if_nonempty(self, maybe_outnames);
return self;
}
Tensor & masked_scatter__cuda(Tensor& self, const Tensor & mask, const Tensor & source) {
at::assert_no_internal_overlap(self);
Tensor b_mask;
std::tie(b_mask) = expand_inplace(self, mask, "masked_scatter_");
// As we dispatch on self and TH is type-checked, we need different definitions.
// This can be fixed by moving to ATen.
if (b_mask.dtype() == at::ScalarType::Byte) {
TORCH_WARN("masked_scatter_ received a mask with dtype torch.uint8, this behavior is now deprecated," \
"please use a mask with dtype torch.bool instead.");
return legacy::cuda::_th_masked_scatter_(self, b_mask, source);
} else {
return legacy::cuda::_th_masked_scatter_bool_(self, b_mask, source);
}
}
}} // namespace at::native