blob: 97134b1b2c63f3560f5a880cb414db5b6daedd47 [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);
39 return cl::NDRange(coords[0] + 1, coords[1] + 1, coords[2] + 1);
40}
41
42CLLWSListExhaustive::CLLWSListExhaustive(const cl::NDRange &gws)
43{
44 search_space_shape = TensorShape(std::min(static_cast<unsigned int>(gws[0]), max_lws_supported_x), std::min(static_cast<unsigned int>(gws[1]), max_lws_supported_y),
45 std::min(static_cast<unsigned int>(gws[2]), max_lws_supported_z));
46}
47
48cl::NDRange CLLWSListNormal::operator[](size_t index)
49{
50 ARM_COMPUTE_ERROR_ON(index >= size());
51 auto coords = index2coords(search_space_shape, index);
52 return cl::NDRange(_lws_x[coords[0]], _lws_y[coords[1]], _lws_z[coords[2]]);
53}
54
55CLLWSListNormal::CLLWSListNormal(const cl::NDRange &gws)
56{
57 auto lws_x_max = std::min(static_cast<unsigned int>(gws[0]), max_lws_supported_x);
58 auto lws_y_max = std::min(static_cast<unsigned int>(gws[1]), max_lws_supported_y);
59 auto lws_z_max = std::min(static_cast<unsigned int>(gws[2]), max_lws_supported_z);
60
61 // Initialize the LWS values to test
62 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
63 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
64 initialize_lws_values(_lws_z, gws[2], lws_z_max, false);
65
66 search_space_shape = TensorShape(_lws_x.size(), _lws_y.size(), _lws_z.size());
67}
68
69void CLLWSListNormal::initialize_lws_values(std::vector<unsigned int> &lws, unsigned int gws, unsigned int lws_max, bool mod_let_one)
70{
71 lws.push_back(1);
72
73 for(unsigned int i = 2; i <= lws_max; ++i)
74 {
75 // Power of two condition
76 const bool is_power_of_two = (i & (i - 1)) == 0;
77
78 // Condition for the module accordingly with the mod_let_one flag
79 const bool mod_cond = mod_let_one ? (gws % i) <= 1 : (gws % i) == 0;
80
81 if(mod_cond || is_power_of_two)
82 {
83 lws.push_back(i);
84 }
85 }
86}
87
88CLLWSListRapid::CLLWSListRapid(const cl::NDRange &gws)
89{
90 auto lws_x_max = std::min(static_cast<unsigned int>(gws[0]), 8u); // Limit exploration to 1 - 8
91 auto lws_y_max = std::min(static_cast<unsigned int>(gws[1]), 4u); // Limit exploration to 1 - 4
92 auto lws_z_max = std::min(static_cast<unsigned int>(gws[2]), 4u); // Limit exploration to 1 - 4
93
94 // Initialize the LWS values to test
95 initialize_lws_values(_lws_x, lws_x_max);
96 initialize_lws_values(_lws_y, lws_y_max);
97 initialize_lws_values(_lws_z, lws_z_max);
98
99 search_space_shape = TensorShape(_lws_x.size(), _lws_y.size(), _lws_z.size());
100}
101
102void CLLWSListRapid::initialize_lws_values(std::vector<unsigned int> &lws, unsigned int lws_max)
103{
104 lws.push_back(1);
105
106 for(unsigned int i = 2; i <= lws_max; i *= 4)
107 {
108 lws.push_back(i);
109 }
110}
111} // namespace cl_tuner
112} // namespace arm_compute