• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <cstring>
10 
11 #include <executorch/runtime/kernel/kernel_includes.h>
12 
13 namespace torch {
14 namespace executor {
15 namespace native {
16 
17 using Tensor = exec_aten::Tensor;
18 
19 Tensor&
lift_fresh_copy_out(KernelRuntimeContext & ctx,const Tensor & in,Tensor & out)20 lift_fresh_copy_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
21   (void)ctx;
22 
23   ET_KERNEL_CHECK(ctx, tensors_have_same_dtype(in, out), InvalidArgument, out);
24 
25   ET_KERNEL_CHECK(
26       ctx, resize_tensor(out, in.sizes()) == Error::Ok, InvalidArgument, out);
27 
28   ET_KERNEL_CHECK(
29       ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);
30 
31   if (in.nbytes() > 0) {
32     // Note that this check is important. It's valid for a tensor with numel 0
33     // to have a null data pointer, but in some environments it's invalid to
34     // pass a null pointer to memcpy() even when the size is zero.
35     memcpy(out.mutable_data_ptr(), in.const_data_ptr(), in.nbytes());
36   }
37   return out;
38 }
39 
40 } // namespace native
41 } // namespace executor
42 } // namespace torch
43