blob: c082d7fbf90ea18054979c8964d02ed54dd6177d [file] [log] [blame]
Giorgio Arenaba2dd822021-07-28 16:10:03 +01001/*
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 */
24#include "src/core/CL/DefaultLWSHeuristics.h"
25
26#include "arm_compute/core/CL/CLKernelLibrary.h"
27
28namespace
29{
30cl::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
51cl::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
58cl::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
73namespace arm_compute
74{
75cl::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 }
87 case CLKernelType::DIRECT:
88 {
89 return get_direct_lws(gws_x, gws_y, gws_z);
90 }
91 case CLKernelType::WINOGRAD:
92 {
93 return get_winograd_lws(gws_x, gws_y, gws_z);
94 }
95 default:
96 {
97 return CLKernelLibrary::get().default_ndrange();
98 }
99 }
100}
101} // namespace arm_compute