fusion_elementwise_add_activation_image_compute.cc 2.7 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"
19
#include "lite/kernels/opencl/image_helper.h"
Y
Yan Chunwei 已提交
20 21 22 23 24

namespace paddle {
namespace lite {
namespace kernels {
namespace opencl {
25 26 27 28 29 30 31 32 33

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

  void PrepareForRun() override {
    build_options_ += " -DRELU";
    auto& context = ctx_->As<OpenCLContext>();
34 35 36 37
    context.cl_context()->AddKernel(kernel_func_name_,
                                    "image/elementwise_add_kernel.cl",
                                    build_options_,
                                    time_stamp_);
38 39 40 41 42 43
    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;
    }
44
    VLOG(1) << "kernel_func_name_:" << kernel_func_name_;
45 46 47
  }
};

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

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

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