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/scalar_utils.h>
10 #include <executorch/runtime/kernel/kernel_includes.h>
11
12 namespace torch {
13 namespace executor {
14 namespace native {
15
16 using executorch::aten::ScalarType;
17 using executorch::aten::Tensor;
18
full_out(KernelRuntimeContext & ctx,const IntArrayRef sizes,const Scalar & fill_value,Tensor & out)19 Tensor& full_out(
20 KernelRuntimeContext& ctx,
21 const IntArrayRef sizes,
22 const Scalar& fill_value,
23 Tensor& out) {
24 (void)ctx;
25
26 ScalarType val_type = utils::get_scalar_dtype(fill_value);
27 ScalarType out_type = out.scalar_type();
28
29 Error err = resize_tensor(out, sizes);
30 ET_CHECK_MSG(err == Error::Ok, "Could not resize out");
31
32 ET_SWITCH_REAL_TYPES_AND(Bool, val_type, ctx, "full", CTYPE_VAL, [&] {
33 CTYPE_VAL val;
34 ET_EXTRACT_SCALAR(fill_value, val);
35
36 ET_SWITCH_REAL_TYPES_AND(Bool, out_type, ctx, "full", CTYPE_OUT, [&] {
37 CTYPE_OUT val_casted = static_cast<CTYPE_OUT>(val);
38 auto data_out = out.mutable_data_ptr<CTYPE_OUT>();
39 for (size_t i = 0; i < out.numel(); ++i) {
40 data_out[i] = val_casted;
41 }
42 });
43 });
44
45 return out;
46 }
47
48 } // namespace native
49 } // namespace executor
50 } // namespace torch
51