Compute Library
 21.11
DefaultLWSHeuristics.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 
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  return cl::NDRange(4, 16, 1);
65  }
66  else
67  {
68  return cl::NDRange(8, 4, 1);
69  }
70 }
71 } // namespace
72 
73 namespace arm_compute
74 {
75 cl::NDRange get_default_lws_for_type(CLKernelType kernel_type, cl::NDRange gws)
76 {
77  const size_t gws_x = gws[0];
78  const size_t gws_y = gws[1];
79  const size_t gws_z = gws[2];
80 
81  switch(kernel_type)
82  {
83  case CLKernelType::GEMM:
84  {
85  return get_gemm_lws(gws_x, gws_y, gws_z);
86  }
88  {
89  return get_direct_lws(gws_x, gws_y, gws_z);
90  }
92  {
93  return get_winograd_lws(gws_x, gws_y, gws_z);
94  }
95  default:
96  {
98  }
99  }
100 }
101 } // 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-2021 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
Convolution using Winograd.
Convolution using GEMM.