Compute Library
 21.02
CLPReluLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
29 
30 namespace arm_compute
31 {
32 namespace experimental
33 {
35 {
36 }
37 
38 void CLPReluLayer::configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *alpha, ITensorInfo *output)
39 {
40  auto k = std::make_unique<arm_compute::opencl::kernels::ClArithmeticKernel>();
41  k->configure(compile_context, ArithmeticOperation::PRELU, input, alpha, output);
42  _kernel = std::move(k);
43 }
44 
46 {
48 }
49 
51 {
52  ICLOperator::run(tensors);
53 }
54 } // namespace experimental
55 
56 struct CLPReluLayer::Impl
57 {
58  const ICLTensor *src_0{ nullptr };
59  const ICLTensor *src_1{ nullptr };
60  ICLTensor *dst{ nullptr };
61  std::unique_ptr<experimental::CLPReluLayer> op{ nullptr };
62 };
63 
65  : _impl(std::make_unique<Impl>())
66 {
67 }
70 CLPReluLayer::~CLPReluLayer() = default;
71 
73 {
74  configure(CLKernelLibrary::get().get_compile_context(), input, alpha, output);
75 }
76 
77 void CLPReluLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *alpha, ICLTensor *output)
78 {
79  _impl->src_0 = input;
80  _impl->src_1 = alpha;
81  _impl->dst = output;
82  _impl->op = std::make_unique<experimental::CLPReluLayer>();
83  _impl->op->configure(compile_context, input->info(), alpha->info(), output->info());
84 }
85 
87 {
88  return experimental::CLPReluLayer::validate(input, alpha, output);
89 }
90 
92 {
93  ITensorPack pack;
94  pack.add_tensor(TensorType::ACL_SRC_0, _impl->src_0);
95  pack.add_tensor(TensorType::ACL_SRC_1, _impl->src_1);
96  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
97 
98  _impl->op->run(pack);
99 }
100 } // namespace arm_compute
static Status validate(ArithmeticOperation op, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClArithmeticKernel.
Basic function to run opencl::kernels::ClArithmeticKernel for PRELU.
Definition: CLPReluLayer.h:76
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
void run() override
Run the kernels contained in the function.
Status class.
Definition: Error.h:52
Copyright (c) 2017-2021 Arm Limited.
void configure(ICLTensor *input, ICLTensor *alpha, ICLTensor *output)
Set the input and output tensor.
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
static Status validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLPReluLayer.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
static Status validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLPReluLayer.
~CLPReluLayer()
Default Destructor.
y*x if x < 0, x otherwise
CLCompileContext class.
CLPReluLayer & operator=(const CLPReluLayer &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
Tensor packing service.
Definition: ITensorPack.h:37
void run(ITensorPack &tensors) override
Run the kernels contained in the function.
Definition: CLOperator.cpp:38
CLPReluLayer()
Default Constructor.
void configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *alpha, ITensorInfo *output)
Set the input and output tensor.
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:30
void run(ITensorPack &tensors) override
Run the kernels contained in the function.