• 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 <executorch/kernels/portable/cpu/util/padding_util.h>
10 #include <executorch/runtime/kernel/kernel_includes.h>
11 
12 namespace torch {
13 namespace executor {
14 namespace native {
15 
16 using Tensor = exec_aten::Tensor;
17 
replication_pad1d_out(KernelRuntimeContext & ctx,const Tensor & in,exec_aten::ArrayRef<int64_t> padding,Tensor & out)18 Tensor& replication_pad1d_out(
19     KernelRuntimeContext& ctx,
20     const Tensor& in,
21     exec_aten::ArrayRef<int64_t> padding,
22     Tensor& out) {
23   (void)ctx;
24 
25   ET_KERNEL_CHECK(
26       ctx, check_padding_args(1, in, padding, out), InvalidArgument, out);
27 
28   Tensor::SizesType target_sizes[kTensorDimensionLimit];
29   size_t target_ndim = 0;
30   get_padding_out_target_size(1, in, padding, target_sizes, &target_ndim);
31 
32   ET_KERNEL_CHECK(
33       ctx,
34       resize_tensor(out, {target_sizes, target_ndim}) == Error::Ok,
35       InvalidArgument,
36       out);
37 
38   ScalarType in_type = in.scalar_type();
39   constexpr auto name = "replication_pad1d.out";
40 
41   ET_SWITCH_ALL_TYPES(in_type, ctx, name, CTYPE, [&] {
42     pad1d<CTYPE>(replication_ix, in, out, padding);
43   });
44 
45   return out;
46 }
47 
48 } // namespace native
49 } // namespace executor
50 } // namespace torch
51