Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | ab2bc73 | 2022-01-19 10:06:45 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2022 Arm Limited. |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [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 | #include "arm_compute/core/GPUTarget.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 25 | |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/Log.h" |
| 27 | |
| 28 | #include <map> |
| 29 | #include <regex> |
| 30 | |
| 31 | namespace |
| 32 | { |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 33 | arm_compute::GPUTarget get_valhall_target(const std::string &version) |
| 34 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 35 | if (version.find("G77") != std::string::npos) |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 36 | { |
| 37 | return arm_compute::GPUTarget::G77; |
| 38 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 39 | else if (version.find("G57") != std::string::npos) |
Gian Marco Iodice | 3c4d085 | 2022-07-11 12:09:45 +0100 | [diff] [blame] | 40 | { |
| 41 | return arm_compute::GPUTarget::G57; |
| 42 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 43 | if (version.find("G68") != std::string::npos) |
Gian Marco Iodice | 3c4d085 | 2022-07-11 12:09:45 +0100 | [diff] [blame] | 44 | { |
| 45 | return arm_compute::GPUTarget::G68; |
| 46 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 47 | if (version.find("G78AE") != std::string::npos) |
Gian Marco Iodice | 3c4d085 | 2022-07-11 12:09:45 +0100 | [diff] [blame] | 48 | { |
| 49 | return arm_compute::GPUTarget::G78AE; |
| 50 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 51 | if (version.find("G78") != std::string::npos) |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 52 | { |
Georgios Pinitas | 4ffc42a | 2020-12-01 16:28:24 +0000 | [diff] [blame] | 53 | return arm_compute::GPUTarget::G78; |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 54 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 55 | else if (version.find("G710") != std::string::npos) |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 56 | { |
Gian Marco Iodice | ab2bc73 | 2022-01-19 10:06:45 +0000 | [diff] [blame] | 57 | return arm_compute::GPUTarget::G710; |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 58 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 59 | else if (version.find("G610") != std::string::npos) |
SiCong Li | a3cf241 | 2022-07-01 15:01:10 +0100 | [diff] [blame] | 60 | { |
Gian Marco Iodice | 3c4d085 | 2022-07-11 12:09:45 +0100 | [diff] [blame] | 61 | return arm_compute::GPUTarget::G610; |
| 62 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 63 | else if (version.find("G510") != std::string::npos) |
Gian Marco Iodice | 3c4d085 | 2022-07-11 12:09:45 +0100 | [diff] [blame] | 64 | { |
| 65 | return arm_compute::GPUTarget::G510; |
| 66 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 67 | else if (version.find("G310") != std::string::npos) |
Gian Marco Iodice | 3c4d085 | 2022-07-11 12:09:45 +0100 | [diff] [blame] | 68 | { |
| 69 | return arm_compute::GPUTarget::G310; |
SiCong Li | a3cf241 | 2022-07-01 15:01:10 +0100 | [diff] [blame] | 70 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 71 | else if (version.find("G715") != std::string::npos) |
Gunes Bayir | 4bfc70e | 2021-12-10 16:17:56 +0000 | [diff] [blame] | 72 | { |
| 73 | return arm_compute::GPUTarget::G715; |
| 74 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 75 | else if (version.find("G615") != std::string::npos) |
Gunes Bayir | 4bfc70e | 2021-12-10 16:17:56 +0000 | [diff] [blame] | 76 | { |
| 77 | return arm_compute::GPUTarget::G615; |
| 78 | } |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 79 | else |
| 80 | { |
Gian Marco Iodice | ab2bc73 | 2022-01-19 10:06:45 +0000 | [diff] [blame] | 81 | return arm_compute::GPUTarget::UNKNOWN; |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 85 | arm_compute::GPUTarget get_bifrost_target(const std::string &version) |
| 86 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 87 | if (version.find("G71") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 88 | { |
| 89 | return arm_compute::GPUTarget::G71; |
| 90 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 91 | else if (version.find("G72") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 92 | { |
| 93 | return arm_compute::GPUTarget::G72; |
| 94 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 95 | else if (version.find("G51BIG") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 96 | { |
| 97 | return arm_compute::GPUTarget::G51BIG; |
| 98 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 99 | else if (version.find("G51LIT") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 100 | { |
| 101 | return arm_compute::GPUTarget::G51LIT; |
| 102 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 103 | else if (version.find("G51") != std::string::npos) |
Georgios Pinitas | a34286e | 2018-09-04 12:18:50 +0100 | [diff] [blame] | 104 | { |
Michalis Spyrou | c95988a | 2019-07-17 13:24:52 +0100 | [diff] [blame] | 105 | return arm_compute::GPUTarget::G51; |
Georgios Pinitas | a34286e | 2018-09-04 12:18:50 +0100 | [diff] [blame] | 106 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 107 | else if (version.find("G52LIT") != std::string::npos) |
Georgios Pinitas | a34286e | 2018-09-04 12:18:50 +0100 | [diff] [blame] | 108 | { |
| 109 | return arm_compute::GPUTarget::G52LIT; |
| 110 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 111 | else if (version.find("G52") != std::string::npos) |
Michalis Spyrou | c95988a | 2019-07-17 13:24:52 +0100 | [diff] [blame] | 112 | { |
| 113 | return arm_compute::GPUTarget::G52; |
| 114 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 115 | else if (version.find("G76") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 116 | { |
Georgios Pinitas | b03f7c5 | 2018-07-12 10:49:53 +0100 | [diff] [blame] | 117 | return arm_compute::GPUTarget::G76; |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 118 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 119 | else if (version.find("G31") != std::string::npos) |
Pablo Marquez Tello | b1496e6 | 2021-06-25 14:49:37 +0100 | [diff] [blame] | 120 | { |
| 121 | return arm_compute::GPUTarget::G31; |
| 122 | } |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 123 | else |
| 124 | { |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 125 | return arm_compute::GPUTarget::UNKNOWN; |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| 129 | arm_compute::GPUTarget get_midgard_target(const std::string &version) |
| 130 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 131 | if (version.find("T600") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 132 | { |
| 133 | return arm_compute::GPUTarget::T600; |
| 134 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 135 | else if (version.find("T700") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 136 | { |
| 137 | return arm_compute::GPUTarget::T700; |
| 138 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 139 | else if (version.find("T800") != std::string::npos) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 140 | { |
| 141 | return arm_compute::GPUTarget::T800; |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | return arm_compute::GPUTarget::MIDGARD; |
| 146 | } |
| 147 | } |
| 148 | } // namespace |
| 149 | |
| 150 | namespace arm_compute |
| 151 | { |
| 152 | const std::string &string_from_target(GPUTarget target) |
| 153 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 154 | static std::map<GPUTarget, const std::string> gpu_target_map = { |
| 155 | {GPUTarget::MIDGARD, "midgard"}, {GPUTarget::BIFROST, "bifrost"}, {GPUTarget::VALHALL, "valhall"}, |
| 156 | {GPUTarget::T600, "t600"}, {GPUTarget::T700, "t700"}, {GPUTarget::T800, "t800"}, |
| 157 | {GPUTarget::G71, "g71"}, {GPUTarget::G72, "g72"}, {GPUTarget::G51, "g51"}, |
| 158 | {GPUTarget::G51BIG, "g51big"}, {GPUTarget::G51LIT, "g51lit"}, {GPUTarget::G31, "g31"}, |
| 159 | {GPUTarget::G76, "g76"}, {GPUTarget::G52, "g52"}, {GPUTarget::G52LIT, "g52lit"}, |
| 160 | {GPUTarget::G77, "g77"}, {GPUTarget::G57, "g57"}, {GPUTarget::G78, "g78"}, |
| 161 | {GPUTarget::G68, "g68"}, {GPUTarget::G78AE, "g78ae"}, {GPUTarget::G710, "g710"}, |
| 162 | {GPUTarget::G610, "g610"}, {GPUTarget::G510, "g510"}, {GPUTarget::G310, "g310"}, |
| 163 | {GPUTarget::G715, "g715"}, {GPUTarget::G615, "g615"}, |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | return gpu_target_map[target]; |
| 167 | } |
| 168 | |
| 169 | GPUTarget get_target_from_name(const std::string &device_name) |
| 170 | { |
| 171 | std::regex mali_regex(R"(Mali-(.*))"); |
| 172 | std::smatch name_parts; |
| 173 | const bool found_mali = std::regex_search(device_name, name_parts, mali_regex); |
| 174 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 175 | if (!found_mali) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 176 | { |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 177 | ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Arm® Mali™ GPU. Target is set to default."); |
Vidhya Sudhan Loganathan | bdff491 | 2018-05-22 15:03:09 +0100 | [diff] [blame] | 178 | return GPUTarget::MIDGARD; |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | const char target = name_parts.str(1)[0]; |
| 182 | const std::string &version = name_parts.str(1); |
| 183 | |
| 184 | std::regex future_regex(R"(.*X)"); |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 185 | const bool is_future_gpu = std::regex_search(version, future_regex); |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 186 | |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 187 | // Work-out gpu target |
| 188 | GPUTarget gpu_target; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 189 | if (target == 'G' || is_future_gpu) |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 190 | { |
Gian Marco Iodice | ab2bc73 | 2022-01-19 10:06:45 +0000 | [diff] [blame] | 191 | // Check for Valhall or Bifrost |
| 192 | gpu_target = get_valhall_target(version); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 193 | if (gpu_target == GPUTarget::UNKNOWN) |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 194 | { |
Gian Marco Iodice | ab2bc73 | 2022-01-19 10:06:45 +0000 | [diff] [blame] | 195 | gpu_target = get_bifrost_target(version); |
| 196 | } |
| 197 | |
| 198 | // Default GPUTarget |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 199 | if (gpu_target == GPUTarget::UNKNOWN) |
Gian Marco Iodice | ab2bc73 | 2022-01-19 10:06:45 +0000 | [diff] [blame] | 200 | { |
| 201 | gpu_target = GPUTarget::VALHALL; |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 202 | } |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 203 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 204 | else if (target == 'T') |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 205 | { |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 206 | gpu_target = get_midgard_target(version); |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 207 | } |
| 208 | else |
| 209 | { |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 210 | gpu_target = GPUTarget::UNKNOWN; |
| 211 | } |
| 212 | |
| 213 | // Report in case of unknown target |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame^] | 214 | if (gpu_target == GPUTarget::UNKNOWN) |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 215 | { |
Michele Di Giorgio | 33f41fa | 2021-03-09 14:09:08 +0000 | [diff] [blame] | 216 | ARM_COMPUTE_LOG_INFO_MSG_CORE("Arm® Mali™ Mali GPU unknown. Target is set to the default one. (BIFROST)"); |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 217 | return GPUTarget::BIFROST; |
| 218 | } |
Georgios Pinitas | d5462ff | 2019-07-03 19:33:57 +0100 | [diff] [blame] | 219 | |
| 220 | return gpu_target; |
Michele Di Giorgio | b8fc60f | 2018-04-25 11:58:07 +0100 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | GPUTarget get_arch_from_target(GPUTarget target) |
| 224 | { |
| 225 | return (target & GPUTarget::GPU_ARCH_MASK); |
| 226 | } |
| 227 | } // namespace arm_compute |