fill_constant_compute.cc 2.2 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15
#include "lite/kernels/arm/fill_constant_compute.h"
Y
Yan Chunwei 已提交
16 17 18 19 20 21

namespace paddle {
namespace lite {
namespace kernels {
namespace arm {

22 23 24
void FillConstantCompute::Run() {
  auto& param = *param_.get_mutable<param_t>();
  auto& context = ctx_->As<ARMContext>();
Y
Yan Chunwei 已提交
25

26 27 28 29
  if (param.dtype == static_cast<int32_t>(lite::core::FluidType::FP32)) {
    auto data = param.out->template mutable_data<float>();
    for (int i = 0; i < param.out->numel(); i++) {
      data[i] = param.value;
30
    }
31 32 33 34 35
  } else if (param.dtype ==
             static_cast<int32_t>(lite::core::FluidType::INT32)) {
    auto data = param.out->template mutable_data<int32_t>();
    for (int i = 0; i < param.out->numel(); i++) {
      data[i] = param.value;
36
    }
37 38 39 40
  } else if (param.dtype == static_cast<int32_t>(lite::core::FluidType::INT8)) {
    auto data = param.out->template mutable_data<int8_t>();
    for (int i = 0; i < param.out->numel(); i++) {
      data[i] = param.value;
Y
Yan Chunwei 已提交
41
    }
42 43
  } else {
    LOG(FATAL) << "not supported dtype " << param.dtype;
Y
Yan Chunwei 已提交
44
  }
45
}
T
TianXiaogang 已提交
46

Y
Yan Chunwei 已提交
47 48 49 50 51 52 53 54
}  // namespace arm
}  // namespace kernels
}  // namespace lite
}  // namespace paddle

// float
REGISTER_LITE_KERNEL(fill_constant,
                     kARM,
55
                     kAny,
Y
Yan Chunwei 已提交
56
                     kNCHW,
J
juncaipeng 已提交
57
                     paddle::lite::kernels::arm::FillConstantCompute,
Y
Yan Chunwei 已提交
58
                     def)
59 60 61 62
    .BindInput("ShapeTensor",
               {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))})
    .BindInput("ShapeTensorList",
               {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kInt32))})
J
juncaipeng 已提交
63
    .BindOutput("Out", {LiteType::GetTensorTy(TARGET(kARM), PRECISION(kAny))})
Y
Yan Chunwei 已提交
64
    .Finalize();