Compute Library
 23.05
CLWinogradConvolutionLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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 #include "src/core/CL/ICLKernel.h"
32 #include "support/Cast.h"
33 
34 namespace arm_compute
35 {
36 struct CLWinogradConvolutionLayer::Impl
37 {
38  const ICLTensor *src{ nullptr };
39  const ICLTensor *weights{ nullptr };
40  const ICLTensor *biases{ nullptr };
41  ICLTensor *dst{ nullptr };
42  std::unique_ptr<opencl::ClWinogradConv2d> op{ nullptr };
43  ITensorPack run_pack{};
44  MemoryGroup memory_group{};
45  WorkspaceData<CLTensor> workspace_tensors{};
46  bool is_prepared{ false };
47 };
48 
49 CLWinogradConvolutionLayer::CLWinogradConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager)
50  : _impl(std::make_unique<Impl>())
51 {
52  _impl->memory_group = MemoryGroup(memory_manager);
53 }
54 
56 
58  bool enable_fast_math)
59 {
60  configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, act_info, enable_fast_math);
61 }
62 
63 void CLWinogradConvolutionLayer::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
64  const PadStrideInfo &conv_info,
65  const ActivationLayerInfo &act_info, bool enable_fast_math)
66 {
67  _impl->src = input;
68  _impl->weights = weights;
69  _impl->biases = biases;
70  _impl->dst = output;
71 
72  _impl->op = std::make_unique<opencl::ClWinogradConv2d>();
73  _impl->op->configure(compile_context, input->info(), weights->info(), (biases != nullptr ? biases->info() : nullptr), output->info(), conv_info, act_info, enable_fast_math);
74 
75  _impl->run_pack =
76  {
77  { TensorType::ACL_SRC_0, _impl->src },
78  { TensorType::ACL_SRC_1, _impl->weights },
79  { TensorType::ACL_SRC_2, _impl->biases },
80  { TensorType::ACL_DST, _impl->dst }
81  };
82  _impl->workspace_tensors = manage_workspace<CLTensor>(_impl->op->workspace(), _impl->memory_group, _impl->run_pack, _impl->run_pack);
83 }
84 
86  const ActivationLayerInfo &act_info, bool enable_fast_math)
87 {
88  return opencl::ClWinogradConv2d::validate(input, weights, biases, output, conv_info, act_info, enable_fast_math);
89 }
90 
92 {
93  MemoryGroupResourceScope scope_mg(_impl->memory_group);
94  prepare();
95  _impl->op->run(_impl->run_pack);
96 }
97 
99 {
100  if(!_impl->is_prepared)
101  {
102  _impl->op->prepare(_impl->run_pack);
103 
104  // Release Preparation tensors
105  release_prepare_tensors(_impl->workspace_tensors, _impl->run_pack);
106  _impl->run_pack.remove_tensor(TensorType::ACL_SRC_1);
107  _impl->is_prepared = true;
108  }
109 }
110 } // namespace arm_compute
CLWinogradConvolutionLayer(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default Constructor.
void run() override
Run the kernels contained in the function.
void prepare() override
Prepare the function for executing.
void release_prepare_tensors(WorkspaceData< TensorType > &workspace, ITensorPack &prep_pack)
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:43
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
Status class.
Definition: Error.h:52
Activation Layer Information class.
Definition: Types.h:1659
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2023 Arm Limited.
static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info=ActivationLayerInfo(), bool enable_fast_math=false)
Static function to check if given info will lead to a valid configuration.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Padding and stride information class.
Definition: Types.h:671
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info=ActivationLayerInfo(), bool enable_fast_math=false)
Static function to check if given info will lead to a valid configuration of CLWinogradConvolutionLay...
~CLWinogradConvolutionLayer()
Default Destructor.
CLCompileContext class.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info=ActivationLayerInfo(), bool enable_fast_math=false)
Set the input and output tensors.