Compute Library
 23.11
ClDirectConvDefaultConfigBifrost.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 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 
32 
33 #include <utility>
34 
35 namespace arm_compute
36 {
37 namespace cl_direct_conv
38 {
40 
42 {
43 }
44 
46  const ITensorInfo *wei,
47  const PadStrideInfo &conv_info)
48 {
49  using ConfigurationFunctionExecutorPtr = DirectConvComputeKernelInfo (ClDirectConvDefaultConfigBifrost::*)(
50  const ITensorInfo *src, const ITensorInfo *wei, const PadStrideInfo &conv_info);
51 
53  &ClDirectConvDefaultConfigBifrost::configure_G71_f32, &ClDirectConvDefaultConfigBifrost::configure_G71_f16,
54  &ClDirectConvDefaultConfigBifrost::configure_G71_u8);
55 
57  &ClDirectConvDefaultConfigBifrost::configure_default_f32,
58  &ClDirectConvDefaultConfigBifrost::configure_default_f16, &ClDirectConvDefaultConfigBifrost::configure_G71_u8);
59 
60  ConfigurationFunctionExecutorPtr func = nullptr;
61  switch (_target)
62  {
63  case GPUTarget::G71:
64  func = configs_G71.get_function(src->data_type());
65  break;
66  default:
67  func = configs_default.get_function(src->data_type());
68  break;
69  }
70 
71  ARM_COMPUTE_ERROR_ON_MSG(func == nullptr, "Data type not supported for direct convolution");
72  return (this->*func)(src, wei, conv_info);
73 }
74 
75 DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_G71_f32(const ITensorInfo *src,
76  const ITensorInfo *wei,
77  const PadStrideInfo &conv_info)
78 {
80 
81  if (src->data_layout() == DataLayout::NHWC)
82  {
83  // Get the output shape
85 
86  desc.n0 = 4;
87 
88  if (output_shape[0] > 16)
89  {
90  desc.m0 = 2;
91  }
92 
93  desc.k0 = 8;
94 
95  desc.export_weights_to_cl_image = false;
96  }
97 
98  return desc;
99 }
100 
101 DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_G71_f16(const ITensorInfo *src,
102  const ITensorInfo *wei,
103  const PadStrideInfo &conv_info)
104 {
105  DirectConvComputeKernelInfo desc;
106 
107  if (src->data_layout() == DataLayout::NHWC)
108  {
109  // Get the output shape
111 
112  desc.n0 = 4;
113 
114  if (output_shape[0] > 16)
115  {
116  desc.m0 = 4;
117  }
118 
119  desc.k0 = 8;
120 
121  desc.export_weights_to_cl_image = false;
122  }
123 
124  return desc;
125 }
126 
127 DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_G71_u8(const ITensorInfo *src,
128  const ITensorInfo *wei,
129  const PadStrideInfo &conv_info)
130 {
131  DirectConvComputeKernelInfo desc;
132 
133  if (src->data_layout() == DataLayout::NHWC)
134  {
135  // Get the output shape
137 
138  desc.n0 = 4;
139 
140  if (output_shape[0] > 16)
141  {
142  desc.m0 = 4;
143  }
144 
145  desc.k0 = 16;
146 
147  desc.export_weights_to_cl_image = false;
148  }
149 
150  return desc;
151 }
152 
153 DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_default_f32(const ITensorInfo *src,
154  const ITensorInfo *wei,
155  const PadStrideInfo &conv_info)
156 {
157  DirectConvComputeKernelInfo desc;
158 
159  if (src->data_layout() == DataLayout::NHWC)
160  {
161  // Get the output shape
163 
164  desc.n0 = 4;
165 
166  if (output_shape[0] > 16)
167  {
168  desc.m0 = 2;
169  }
170 
171  desc.k0 = 8;
172 
173  desc.export_weights_to_cl_image = export_to_cl_image(wei);
174  }
175 
176  return desc;
177 }
178 
179 DirectConvComputeKernelInfo ClDirectConvDefaultConfigBifrost::configure_default_f16(const ITensorInfo *src,
180  const ITensorInfo *wei,
181  const PadStrideInfo &conv_info)
182 {
183  DirectConvComputeKernelInfo desc;
184 
185  if (src->data_layout() == DataLayout::NHWC)
186  {
187  // Get the output shape
189 
190  desc.n0 = 4;
191 
192  if (output_shape[0] > 16)
193  {
194  desc.m0 = 4;
195  }
196 
197  desc.k0 = 8;
198 
199  desc.export_weights_to_cl_image = export_to_cl_image(wei);
200  }
201 
202  return desc;
203 }
204 } // namespace cl_direct_conv
205 } // namespace arm_compute
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
arm_compute::export_to_cl_image
bool export_to_cl_image(const ITensorInfo *tensor)
Definition: CLHelpers.cpp:449
arm_compute::cl_direct_conv::ClDirectConvDefaultConfigBifrost::ClDirectConvDefaultConfigBifrost
ClDirectConvDefaultConfigBifrost(GPUTarget gpu)
Constructor.
Definition: ClDirectConvDefaultConfigBifrost.cpp:41
arm_compute::test::validation::output_shape
TensorShape output_shape
Definition: LSTMLayerQuantized.cpp:469
arm_compute::DataLayout::NHWC
@ NHWC
Num samples, height, width, channels.
arm_compute::cl_direct_conv::ClDirectConvDefaultConfigBifrost
Bifrost based OpenCL direct convolution configuration.
Definition: ClDirectConvDefaultConfigBifrost.h:34
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
TensorInfo.h
ClDirectConvDefaultConfigBifrost.h
arm_compute::cl_direct_conv::IClDirectConvKernelConfig
Basic interface for the Direct convolution kernel configuration.
Definition: IClDirectConvKernelConfig.h:88
CLKernelLibrary.h
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
arm_compute::DirectConvComputeKernelInfo::n0
int32_t n0
Number of columns to be processed by the kernel.
Definition: KernelDescriptors.h:127
ARM_COMPUTE_ERROR_ON_MSG
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
GPUTarget.h
arm_compute::cl_direct_conv::ClDirectConvConfigArray
Basic container for the OpenCL direct convolution configuration functions.
Definition: IClDirectConvKernelConfig.h:39
arm_compute::DirectConvComputeKernelInfo::m0
int32_t m0
Number of rows to be processed by the kernel.
Definition: KernelDescriptors.h:126
arm_compute::cl_direct_conv::ClDirectConvDefaultConfigBifrost::configure
DirectConvComputeKernelInfo configure(const ITensorInfo *src, const ITensorInfo *wei, const PadStrideInfo &conv_info) override
This method returns the DirectConvComputeKernelInfo for the given inputs.
Definition: ClDirectConvDefaultConfigBifrost.cpp:45
arm_compute::PadStrideInfo
Definition: CoreTypes.h:139
arm_compute::GPUTarget
GPUTarget
Available GPU Targets.
Definition: GPUTarget.h:34
ShapeCalculator.h
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::validation::conv_info
conv_info
Definition: DirectConvolutionLayer.cpp:547
arm_compute::DirectConvComputeKernelInfo::export_weights_to_cl_image
bool export_weights_to_cl_image
Flag to export the weights to cl_image.
Definition: KernelDescriptors.h:129
TensorShape.h
arm_compute::GPUTarget::G71
@ G71
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:44
arm_compute::misc::shape_calculator
Definition: ShapeCalculator.h:41
arm_compute::cl_direct_conv::ClDirectConvConfigArray::get_function
T get_function(DataType data_type)
Method to return the direct convolution configuration function based on data type.
Definition: IClDirectConvKernelConfig.h:66
arm_compute::misc::shape_calculator::compute_deep_convolution_shape
TensorShape compute_deep_convolution_shape(const TensorShape &input_shape, DataLayout input_data_layout, const TensorShape &weights_shape, const PadStrideInfo &conv_info)
Calculate the deep convolution shape output shape of a tensor.
Definition: ShapeCalculator.h:777
arm_compute::DirectConvComputeKernelInfo::k0
int32_t k0
Number of partial accumulations to be processed in a single iteration by the kernel.
Definition: KernelDescriptors.h:128
arm_compute::DirectConvComputeKernelInfo
Compute descriptor used by the direct convolution kernel.
Definition: KernelDescriptors.h:124
CLHelpers.h