Skip to content

Commit

Permalink
[CrashFix] Make the dst tensor contiguous when copying from metal
Browse files Browse the repository at this point in the history
Summary: Somehow the destination tensor becomes incontiguous when copying from Metal. We need to call `.contiguous()` explicitly. See the crash log - https://www.internalfb.com/intern/logview/details/facebook_ios_crashes/1d865405fbc1a45f9517470906c9ec08/

Test Plan:
- verify the crash
- Sandcastle CIs

Reviewed By: dreiss

Differential Revision: D25502884

fbshipit-source-id: 46ee720bf6b6658e51cb56a4e4c16ce121eeabc7
  • Loading branch information
xta0 authored and facebook-github-bot committed Dec 14, 2020
1 parent a0432a7 commit 25833e5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion aten/src/ATen/native/metal/mpscnn/MPSCNNOps.mm
Expand Up @@ -608,7 +608,9 @@ Tensor copy_to_host(const Tensor& input) {
MPSImage* X = imageFromTensor(input);
MetalCommandBuffer* commandBuffer = commandBufferFromInputTensor(input);
auto&& sizes = [X sizes];
MetalTensor mt{sizes};
auto dummy = at::zeros(input.sizes()).contiguous();
auto strides = dummy.strides();
MetalTensor mt{sizes, strides.vec()};
mt.texture()->setCommandBuffer(commandBuffer);
mt.texture()->allocateTextureStorage(sizes);
MPSImage* Y = imageFromMetalTensor(mt);
Expand Down

0 comments on commit 25833e5

Please sign in to comment.