xref: /aosp_15_r20/external/executorch/extension/runner_util/inputs_aten.cpp (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
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/extension/runner_util/inputs.h>
10 
11 #include <vector>
12 
13 #include <ATen/ATen.h> // @manual=//caffe2/aten:ATen-core
14 #include <executorch/runtime/executor/method.h>
15 #include <executorch/runtime/executor/method_meta.h>
16 
17 using executorch::runtime::Error;
18 using executorch::runtime::Method;
19 using executorch::runtime::TensorInfo;
20 
21 namespace executorch {
22 namespace extension {
23 namespace internal {
24 
fill_and_set_input(Method & method,TensorInfo & tensor_meta,size_t input_index,void * data_ptr)25 Error fill_and_set_input(
26     Method& method,
27     TensorInfo& tensor_meta,
28     size_t input_index,
29     void* data_ptr) {
30   // Convert the sizes array from int32_t to int64_t.
31   std::vector<int64_t> sizes;
32   for (auto s : tensor_meta.sizes()) {
33     sizes.push_back(s);
34   }
35   at::Tensor t = at::from_blob(
36       data_ptr, sizes, at::TensorOptions(tensor_meta.scalar_type()));
37   t.fill_(1.0f);
38 
39   return method.set_input(t, input_index);
40 }
41 
42 } // namespace internal
43 } // namespace extension
44 } // namespace executorch
45