Skip to content

Commit

Permalink
[Static Runtime] Use native version of at::empty (pytorch#53216)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#53216

- at::native::empty_cpu calls at::detail::empty_cpu without any changes to the arguments. So we could call at::detail::empty_cpu directly.
- There is no need to create a TensorOptions object first since we can get all the relevant information from the tensor directly.

Reviewed By: bertmaher, swolchok

Differential Revision: D26792255

fbshipit-source-id: 7a4e368a19cea79e136e34dab854cb1d37dbeb58
  • Loading branch information
Hao Lu authored and Sacha Refshauge committed Mar 31, 2021
1 parent 5c8f33d commit 09c624c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion torch/csrc/jit/runtime/static/ops.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <ATen/Utils.h>
#include <torch/csrc/jit/ir/ir.h>
#include <torch/csrc/jit/runtime/static/impl.h>

Expand Down Expand Up @@ -56,7 +57,13 @@ C10_DECLARE_REGISTRY(SROperatorRegistry, SROperatorFunctor);
C10_DECLARE_REGISTRY(SRViewOperatorRegistry, SROperatorFunctor);

inline at::Tensor create_empty_from(const at::Tensor& t) {
return at::empty({0}, t.options());
return at::detail::empty_cpu(
{0},
c10::typeMetaToScalarType(t.dtype()),
t.layout(),
t.device(),
c10::nullopt,
c10::nullopt);
}

inline bool checkResizedDataPtr(at::Tensor& t) {
Expand Down

0 comments on commit 09c624c

Please sign in to comment.