• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017-2020 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  */
24 #include "arm_compute/runtime/CL/functions/CLDirectConvolutionLayer.h"
25 
26 #include "arm_compute/core/CL/ICLTensor.h"
27 #include "arm_compute/core/PixelValue.h"
28 #include "arm_compute/core/Utils.h"
29 #include "arm_compute/core/Validate.h"
30 #include "arm_compute/runtime/CL/CLScheduler.h"
31 #include "src/core/CL/kernels/CLDirectConvolutionLayerKernel.h"
32 #include "src/core/CL/kernels/CLFillBorderKernel.h"
33 #include "support/MemorySupport.h"
34 
35 using namespace arm_compute;
36 
CLDirectConvolutionLayer()37 CLDirectConvolutionLayer::CLDirectConvolutionLayer()
38     : _direct_conv_kernel(support::cpp14::make_unique<CLDirectConvolutionLayerKernel>()), _input_border_handler(support::cpp14::make_unique<CLFillBorderKernel>()), _activationlayer_function(),
39       _is_activationlayer_enabled(false)
40 {
41 }
42 
43 CLDirectConvolutionLayer::~CLDirectConvolutionLayer() = default;
44 
configure(ICLTensor * input,const ICLTensor * weights,const ICLTensor * biases,ICLTensor * output,const PadStrideInfo & conv_info,const ActivationLayerInfo & act_info)45 void CLDirectConvolutionLayer::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info)
46 {
47     configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, act_info);
48 }
49 
configure(const CLCompileContext & compile_context,ICLTensor * input,const ICLTensor * weights,const ICLTensor * biases,ICLTensor * output,const PadStrideInfo & conv_info,const ActivationLayerInfo & act_info)50 void CLDirectConvolutionLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
51                                          const PadStrideInfo       &conv_info,
52                                          const ActivationLayerInfo &act_info)
53 {
54     // Set GPU target
55     _direct_conv_kernel->set_target(CLScheduler::get().target());
56 
57     // Configure direct convolution
58     _direct_conv_kernel->configure(compile_context, input, weights, biases, output, conv_info);
59 
60     // Configure border handler
61     PixelValue &&zero_value(0.f);
62     if(is_data_type_quantized_asymmetric(input->info()->data_type()))
63     {
64         zero_value = PixelValue(0, input->info()->data_type(), input->info()->quantization_info());
65     }
66     _input_border_handler->configure(compile_context, input, _direct_conv_kernel->border_size(), BorderMode::CONSTANT, zero_value);
67 
68     // Tune kernels
69     CLScheduler::get().tune_kernel_static(*_direct_conv_kernel);
70 
71     _is_activationlayer_enabled = act_info.enabled();
72 
73     //Configure Activation Layer
74     if(_is_activationlayer_enabled)
75     {
76         _activationlayer_function.configure(compile_context, output, nullptr, act_info);
77     }
78 }
79 
validate(const ITensorInfo * input,const ITensorInfo * weights,const ITensorInfo * biases,const ITensorInfo * output,const PadStrideInfo & conv_info,const ActivationLayerInfo & act_info)80 Status CLDirectConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info,
81                                           const ActivationLayerInfo &act_info)
82 {
83     ARM_COMPUTE_RETURN_ON_ERROR(CLDirectConvolutionLayerKernel::validate(input, weights, biases, output, conv_info, CLScheduler::get().target()));
84     if(act_info.enabled())
85     {
86         ARM_COMPUTE_RETURN_ON_ERROR(CLActivationLayer::validate(output, nullptr, act_info));
87     }
88     return Status{};
89 }
90 
run()91 void CLDirectConvolutionLayer::run()
92 {
93     // Run border handler
94     CLScheduler::get().enqueue(*_input_border_handler, false);
95 
96     // Run direct convolution
97     CLScheduler::get().enqueue(*_direct_conv_kernel);
98 
99     //Run Activation Layer
100     if(_is_activationlayer_enabled)
101     {
102         _activationlayer_function.run();
103     }
104 }
105