Skip to content

Commit ebc8d71

Browse files
XiaobingSuperfacebook-github-bot
authored andcommitted
fix the bug for mkldnn clone (#20943)
Summary: This PR is to solve the bug for clone a MKLDNN tensor, please see the issue #20895. Pull Request resolved: #20943 Differential Revision: D15511516 Pulled By: mrshenli fbshipit-source-id: 05b41d6c7eaf8703521f4c768b8f26ec8501dc5e
1 parent 6480d3f commit ebc8d71

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

aten/src/ATen/native/mkldnn/TensorShape.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ Tensor mkldnn_reshape(const Tensor& self, IntArrayRef size) {
4646

4747
Tensor mkldnn_clone(const Tensor& self) {
4848
ideep::tensor& src = itensor_from_mkldnn(self);
49-
ideep::tensor dst{src};
49+
ideep::tensor dst;
50+
ideep::direct_copy::compute<AllocForMKLDNN>(src, dst);
5051
return new_with_itensor_mkldnn(std::move(dst), self.options());
5152
}
5253

test/test_mkldnn.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ def test_clone(self):
232232
x.clone(),
233233
x.to_mkldnn().clone().to_dense(),
234234
)
235+
# test whether share same memory
236+
y = x.to_mkldnn()
237+
z = y.clone().add_(y)
238+
self.assertNotEqual(
239+
y.to_dense(),
240+
z.to_dense(),
241+
)
235242

236243
def test_linear(self):
237244
in_features = torch.randint(3, 10, (1,)).item()

0 commit comments

Comments
 (0)