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

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

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 已提交
44 45 46 47 48 49
}  // namespace opencl
}  // namespace kernels
}  // namespace lite
}  // namespace paddle

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

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