blob: 30fd558ef3cf262895b8033e400973b6e3f2fb73 [file] [log] [blame]
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +01001/*
2 * Copyright (c) 2019 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 "arm_compute/runtime/CL/tuners/CLLWSList.h"
25
26namespace arm_compute
27{
28namespace cl_tuner
29{
30size_t CLLWSList::size()
31{
32 return search_space_shape.total_size();
33}
34
35cl::NDRange CLLWSListExhaustive::operator[](size_t index)
36{
37 ARM_COMPUTE_ERROR_ON(index >= size());
38 auto coords = index2coords(search_space_shape, index);
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010039 return cl::NDRange{ coords[0] + 1U, coords[1] + 1U, coords[2] + 1U };
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010040}
41
42CLLWSListExhaustive::CLLWSListExhaustive(const cl::NDRange &gws)
43{
Gian Marco Iodicedeaed2d2019-05-14 17:11:53 +010044 ARM_COMPUTE_UNUSED(gws);
45 search_space_shape = TensorShape(max_lws_supported_x,
46 max_lws_supported_y,
47 max_lws_supported_z);
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010048}
49
50cl::NDRange CLLWSListNormal::operator[](size_t index)
51{
52 ARM_COMPUTE_ERROR_ON(index >= size());
53 auto coords = index2coords(search_space_shape, index);
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010054 return cl::NDRange{ _lws_x[coords[0]], _lws_y[coords[1]], _lws_z[coords[2]] };
Vidhya Sudhan Loganathan050471e2019-04-25 09:27:24 +010055}
56
57CLLWSListNormal::CLLWSListNormal(const cl::NDRange &gws)
58{
59 auto lws_x_max = std::min(static_cast<unsigned int>(gws[0]), max_lws_supported_x);
60 auto lws_y_max = std::min(static_cast<unsigned int>(gws[1]), max_lws_supported_y);
61 auto lws_z_max = std::min(static_cast<unsigned int>(gws[2]), max_lws_supported_z);
62
63 // Initialize the LWS values to test
64 initialize_lws_values(_lws_x, gws[0], lws_x_max, gws[2] > 16); // Explore lws that are not factors of gws only when gws[2] > 16
65 initialize_lws_values(_lws_y, gws[1], lws_y_max, gws[2] > 16); // Explore lws that are not factors of gws only when gws[2] > 16
66 initialize_lws_values(_lws_z, gws[2], lws_z_max, false);
67
68 search_space_shape = TensorShape(_lws_x.size(), _lws_y.size(), _lws_z.size());
69}
70
71void CLLWSListNormal::initialize_lws_values(std::vector<unsigned int> &lws, unsigned int gws, unsigned int lws_max, bool mod_let_one)
72{
73 lws.push_back(1);
74
75 for(unsigned int i = 2; i <= lws_max; ++i)
76 {
77 // Power of two condition
78 const bool is_power_of_two = (i & (i - 1)) == 0;
79
80 // Condition for the module accordingly with the mod_let_one flag
81 const bool mod_cond = mod_let_one ? (gws % i) <= 1 : (gws % i) == 0;
82
83 if(mod_cond || is_power_of_two)
84 {
85 lws.push_back(i);
86 }
87 }
88}
89
90CLLWSListRapid::CLLWSListRapid(const cl::NDRange &gws)
91{
92 auto lws_x_max = std::min(static_cast<unsigned int>(gws[0]), 8u); // Limit exploration to 1 - 8
93 auto lws_y_max = std::min(static_cast<unsigned int>(gws[1]), 4u); // Limit exploration to 1 - 4
94 auto lws_z_max = std::min(static_cast<unsigned int>(gws[2]), 4u); // Limit exploration to 1 - 4
95
96 // Initialize the LWS values to test
97 initialize_lws_values(_lws_x, lws_x_max);
98 initialize_lws_values(_lws_y, lws_y_max);
99 initialize_lws_values(_lws_z, lws_z_max);
100
101 search_space_shape = TensorShape(_lws_x.size(), _lws_y.size(), _lws_z.size());
102}
103
104void CLLWSListRapid::initialize_lws_values(std::vector<unsigned int> &lws, unsigned int lws_max)
105{
106 lws.push_back(1);
107
108 for(unsigned int i = 2; i <= lws_max; i *= 4)
109 {
110 lws.push_back(i);
111 }
112}
113} // namespace cl_tuner
114} // namespace arm_compute