fusion_elementwise_add_activation_image_compute.cc 2.4 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/backends/opencl/cl_include.h"
Y
Yan Chunwei 已提交
16
#include "lite/core/op_registry.h"
17
#include "lite/kernels/opencl/elementwise_add_image_compute.h"
Y
Yan Chunwei 已提交
18 19 20 21 22

namespace paddle {
namespace lite {
namespace kernels {
namespace opencl {
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

class FusionElementwiseAddActivationImageCompute
    : public ElementwiseAddImageCompute {
 public:
  using param_t = operators::FusionElementwiseActivationParam;

  void PrepareForRun() override {
    build_options_ += " -DRELU";
    auto& context = ctx_->As<OpenCLContext>();
    context.cl_context()->AddKernel(
        kernel_func_name_, "image/elementwise_add_kernel.cl", build_options_);
    ele_param_ = param_.get_mutable<param_t>();
    auto act_t = static_cast<param_t*>(ele_param_)->act_type;
    VLOG(4) << "act: " << act_t;
    if (act_t != "relu") {
      LOG(FATAL) << "Unsupported Activation type: " << act_t;
    }
  }
};

Y
Yan Chunwei 已提交
43 44 45 46 47 48
}  // namespace opencl
}  // namespace kernels
}  // namespace lite
}  // namespace paddle

namespace ocl = paddle::lite::kernels::opencl;
49

Y
Yan Chunwei 已提交
50 51
REGISTER_LITE_KERNEL(fusion_elementwise_add_activation,
                     kOpenCL,
52
                     kFP16,
53 54
                     kImageDefault,
                     ocl::FusionElementwiseAddActivationImageCompute,
Y
Yan Chunwei 已提交
55
                     def)
56 57
    .BindInput("X",
               {LiteType::GetTensorTy(TARGET(kOpenCL),
58
                                      PRECISION(kFP16),
59 60 61
                                      DATALAYOUT(kImageDefault))})
    .BindInput("Y",
               {LiteType::GetTensorTy(TARGET(kOpenCL),
62
                                      PRECISION(kFP16),
63 64 65
                                      DATALAYOUT(kImageDefault))})
    .BindOutput("Out",
                {LiteType::GetTensorTy(TARGET(kOpenCL),
66
                                       PRECISION(kFP16),
67
                                       DATALAYOUT(kImageDefault))})
Y
Yan Chunwei 已提交
68
    .Finalize();