Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 1 | /* |
Pablo Marquez Tello | dc73246 | 2022-10-24 14:43:08 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2022 Arm Limited. |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 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 | #ifndef ARM_COMPUTE_CLTUNING_PARAMS_H |
| 25 | #define ARM_COMPUTE_CLTUNING_PARAMS_H |
| 26 | |
| 27 | #include "arm_compute/core/CL/OpenCL.h" |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 28 | #include "arm_compute/runtime/CL/CLTunerTypes.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 29 | |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 30 | #include "support/StringSupport.h" |
| 31 | |
| 32 | #include <ostream> |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | /**< OpenCL tuner parameters */ |
| 37 | class CLTuningParams |
| 38 | { |
| 39 | public: |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 40 | CLTuningParams(const CLTuningParams &tuning_params) : _lws(tuning_params._lws), _wbsm(tuning_params._wbsm) |
Pablo Marquez Tello | dc73246 | 2022-10-24 14:43:08 +0100 | [diff] [blame] | 41 | { |
| 42 | } |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 43 | |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 44 | CLTuningParams(unsigned int lws_x = 0, unsigned int lws_y = 0, unsigned int lws_z = 0, int wbsm = 0) |
| 45 | : _lws(lws_x, lws_y, lws_z), _wbsm(wbsm) |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 46 | { |
| 47 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 48 | CLTuningParams(cl::NDRange lws, cl_int wbsm = 0) : _lws(lws), _wbsm(wbsm) |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 49 | { |
| 50 | } |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 51 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 52 | CLTuningParams(cl_int wbsm) : CLTuningParams(cl::NullRange, wbsm) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 53 | { |
| 54 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 55 | CLTuningParams &operator=(const CLTuningParams &other) |
Pablo Marquez Tello | dc73246 | 2022-10-24 14:43:08 +0100 | [diff] [blame] | 56 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 57 | _lws = other._lws; |
Pablo Marquez Tello | dc73246 | 2022-10-24 14:43:08 +0100 | [diff] [blame] | 58 | _wbsm = other._wbsm; |
| 59 | return *this; |
| 60 | } |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 61 | |
| 62 | void set_lws(cl::NDRange lws) |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 63 | { |
| 64 | _lws = lws; |
| 65 | } |
| 66 | |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 67 | cl::NDRange get_lws() const |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 68 | { |
| 69 | return _lws; |
| 70 | } |
| 71 | |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 72 | void set_wbsm(cl_int wbsm) |
| 73 | { |
| 74 | _wbsm = wbsm; |
| 75 | } |
| 76 | |
| 77 | cl_int get_wbsm() const |
| 78 | { |
| 79 | return _wbsm; |
| 80 | } |
| 81 | |
| 82 | std::string to_string(CLTuningInfo tuning_info) |
| 83 | { |
| 84 | std::string tuning_params_string = ""; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 85 | tuning_params_string += ";" + support::cpp11::to_string(_lws[0]) + ";" + support::cpp11::to_string(_lws[1]) + |
| 86 | ";" + support::cpp11::to_string(_lws[2]); |
| 87 | if (tuning_info.tune_wbsm) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 88 | { |
| 89 | tuning_params_string += ";" + support::cpp11::to_string(_wbsm); |
| 90 | } |
| 91 | return tuning_params_string; |
| 92 | } |
| 93 | |
| 94 | bool from_string(CLTuningInfo tuning_info, std::string tuning_params_string) |
| 95 | { |
| 96 | std::replace(tuning_params_string.begin(), tuning_params_string.end(), ';', ' '); |
| 97 | std::vector<std::string> array; |
| 98 | std::stringstream ss(tuning_params_string); |
| 99 | std::string temp; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 100 | while (ss >> temp) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 101 | { |
| 102 | array.push_back(temp); |
| 103 | } |
| 104 | // Read 3 values for lws |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 105 | if (array.size() < 3) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 106 | { |
| 107 | return false; |
| 108 | } |
| 109 | const unsigned int lws_0 = support::cpp11::stoi(array[0]); |
| 110 | const unsigned int lws_1 = support::cpp11::stoi(array[1]); |
| 111 | const unsigned int lws_2 = support::cpp11::stoi(array[2]); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 112 | if (lws_0 == 0 && lws_1 == 0 && lws_2 == 0) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 113 | { |
| 114 | // If lws values are 0, cl::NullRange has to be used |
| 115 | // otherwise the lws object will be badly created |
| 116 | _lws = cl::NullRange; |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | _lws = cl::NDRange(lws_0, lws_1, lws_2); |
| 121 | } |
| 122 | array.erase(array.begin(), array.begin() + 3); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 123 | if (tuning_info.tune_wbsm) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 124 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 125 | if (array.size() < 1) |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 126 | { |
| 127 | return false; |
| 128 | } |
| 129 | _wbsm = support::cpp11::stoi(array[0]); |
| 130 | array.erase(array.begin()); |
| 131 | } |
| 132 | return true; |
| 133 | } |
| 134 | |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 135 | private: |
| 136 | cl::NDRange _lws; |
Manuel Bottini | be9f9f9 | 2021-01-25 15:07:17 +0000 | [diff] [blame] | 137 | cl_int _wbsm; |
Manuel Bottini | b56c175 | 2020-11-18 17:56:30 +0000 | [diff] [blame] | 138 | }; |
| 139 | } // namespace arm_compute |
| 140 | #endif /*ARM_COMPUTE_CLTUNING_PARAMS_H */ |