Compute Library
 23.05
DefaultLWSHeuristics.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-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 
27 
28 namespace
29 {
30 cl::NDRange get_gemm_lws(size_t gws_x, size_t gws_y, size_t gws_z)
31 {
32  ARM_COMPUTE_UNUSED(gws_y);
33 
34  if(gws_z != 1)
35  {
36  return cl::NDRange(4, 4, 2);
37  }
38  else
39  {
40  if(gws_x > 256)
41  {
42  return cl::NDRange(2, 16, 1);
43  }
44  else
45  {
46  return cl::NDRange(32, 4, 1);
47  }
48  }
49 }
50 
51 cl::NDRange get_winograd_lws(size_t gws_x, size_t gws_y, size_t gws_z)
52 {
53  ARM_COMPUTE_UNUSED(gws_x, gws_y, gws_z);
54 
55  return cl::NDRange(4, 2, 1);
56 }
57 
58 cl::NDRange get_direct_lws(size_t gws_x, size_t gws_y, size_t gws_z)
59 {
60  ARM_COMPUTE_UNUSED(gws_z);
61 
62  if(gws_x < gws_y)
63  {
64  if(gws_x < 4)
65  {
66  return cl::NDRange(std::min(gws_x, static_cast<size_t>(2u)), 32, 1);
67  }
68  else
69  {
70  return cl::NDRange(std::min(gws_x, static_cast<size_t>(4u)), 8, 1);
71  }
72  }
73  else
74  {
75  return cl::NDRange(8, 4, 1);
76  }
77 }
78 
79 cl::NDRange get_dwc_lws(size_t gws_x, size_t gws_y, size_t gws_z)
80 {
81  ARM_COMPUTE_UNUSED(gws_y);
82  ARM_COMPUTE_UNUSED(gws_z);
83 
84  if(gws_x < 32)
85  {
86  return cl::NDRange(gws_x, 4, 4);
87  }
88  else
89  {
90  return cl::NDRange(8, 4, 2);
91  }
92 }
93 } // namespace
94 
95 namespace arm_compute
96 {
97 cl::NDRange get_default_lws_for_type(CLKernelType kernel_type, cl::NDRange gws)
98 {
99  const size_t gws_x = gws[0];
100  const size_t gws_y = gws[1];
101  const size_t gws_z = gws[2];
102 
103  switch(kernel_type)
104  {
105  case CLKernelType::GEMM:
106  {
107  return get_gemm_lws(gws_x, gws_y, gws_z);
108  }
110  {
111  return get_direct_lws(gws_x, gws_y, gws_z);
112  }
114  {
115  return get_winograd_lws(gws_x, gws_y, gws_z);
116  }
118  {
119  return get_dwc_lws(gws_x, gws_y, gws_z);
120  }
121  default:
122  {
124  }
125  }
126 }
127 } // namespace arm_compute
cl::NDRange get_default_lws_for_type(CLKernelType kernel_type, cl::NDRange gws)
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
Copyright (c) 2017-2023 Arm Limited.
cl::NDRange default_ndrange() const
Return the default NDRange for the device.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Depthwise CL kernel type.
Definition: CLTypes.h:83
Convolution using Winograd.
Convolution using GEMM.