aboutsummaryrefslogtreecommitdiff
path: root/src/core/CL/CLHelpers.cpp
diff options
context:
space:
mode:
authorMoritz Pflanzer <moritz.pflanzer@arm.com>2017-09-15 15:08:12 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commite997859ed978a42191e429f9357c95c38d84baaa (patch)
tree362be7eefb0ad2a317640767bfd767d3eaf1d717 /src/core/CL/CLHelpers.cpp
parent45634b488da781373104541f5348eb9550aafb33 (diff)
downloadComputeLibrary-e997859ed978a42191e429f9357c95c38d84baaa.tar.gz
COMPMID-417: Refactor GPU detection
Change-Id: Ia21f2c51cb3bb4390b0ad26590bca63ac8446e17 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/87927 Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com> Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Diffstat (limited to 'src/core/CL/CLHelpers.cpp')
-rw-r--r--src/core/CL/CLHelpers.cpp94
1 files changed, 42 insertions, 52 deletions
diff --git a/src/core/CL/CLHelpers.cpp b/src/core/CL/CLHelpers.cpp
index c9b602d54a..5c4d8e9184 100644
--- a/src/core/CL/CLHelpers.cpp
+++ b/src/core/CL/CLHelpers.cpp
@@ -27,40 +27,36 @@
#include "arm_compute/core/Types.h"
#include <map>
+#include <regex>
#include <vector>
namespace
{
-arm_compute::GPUTarget get_bifrost_target(const std::string &name)
+arm_compute::GPUTarget get_bifrost_target(const std::string &version)
{
- arm_compute::GPUTarget target = arm_compute::GPUTarget::BIFROST;
-
- if(name == "G7")
+ if(version == "70")
{
- target = arm_compute::GPUTarget::G70;
+ return arm_compute::GPUTarget::G70;
+ }
+ else
+ {
+ return arm_compute::GPUTarget::BIFROST;
}
-
- return target;
}
-arm_compute::GPUTarget get_midgard_target(const std::string &name)
+arm_compute::GPUTarget get_midgard_target(const std::string &version)
{
- arm_compute::GPUTarget target = arm_compute::GPUTarget::MIDGARD;
-
- if(name == "T6")
+ switch(version[0])
{
- target = arm_compute::GPUTarget::T600;
- }
- else if(name == "T7")
- {
- target = arm_compute::GPUTarget::T700;
- }
- else if(name == "T8")
- {
- target = arm_compute::GPUTarget::T800;
+ case '6':
+ return arm_compute::GPUTarget::T600;
+ case '7':
+ return arm_compute::GPUTarget::T700;
+ case '8':
+ return arm_compute::GPUTarget::T800;
+ default:
+ return arm_compute::GPUTarget::MIDGARD;
}
-
- return target;
}
} // namespace
@@ -160,49 +156,43 @@ const std::string &string_from_target(GPUTarget target)
GPUTarget get_target_from_device(cl::Device &device)
{
- const std::string name_mali("Mali-");
- GPUTarget target{ GPUTarget::MIDGARD };
-
- size_t name_size = 0;
- std::vector<char> name;
+ size_t name_size = 0;
// Query device name size
cl_int err = clGetDeviceInfo(device.get(), CL_DEVICE_NAME, 0, nullptr, &name_size);
ARM_COMPUTE_ERROR_ON_MSG((err != 0) || (name_size == 0), "clGetDeviceInfo failed to return valid information");
- // Resize vector
- name.resize(name_size);
+
+ std::vector<char> name_buffer(name_size);
+
// Query device name
- err = clGetDeviceInfo(device.get(), CL_DEVICE_NAME, name_size, name.data(), nullptr);
+ err = clGetDeviceInfo(device.get(), CL_DEVICE_NAME, name_size, name_buffer.data(), nullptr);
ARM_COMPUTE_ERROR_ON_MSG(err != 0, "clGetDeviceInfo failed to return valid information");
ARM_COMPUTE_UNUSED(err);
- std::string name_str(name.begin(), name.end());
- auto pos = name_str.find(name_mali);
+ std::regex mali_regex(R"(Mali-([TG])(\d+))");
+ std::string device_name(name_buffer.begin(), name_buffer.end());
+ std::smatch name_parts;
+ const bool found_mali = std::regex_search(device_name, name_parts, mali_regex);
- if(pos != std::string::npos)
+ if(!found_mali)
{
- ARM_COMPUTE_ERROR_ON_MSG((pos + name_mali.size() + 2) > name_str.size(), "Device name is shorter than expected.");
- std::string sub_name = name_str.substr(pos + name_mali.size(), 2);
-
- if(sub_name[0] == 'G')
- {
- target = get_bifrost_target(sub_name);
- }
- else if(sub_name[0] == 'T')
- {
- target = get_midgard_target(sub_name);
- }
- else
- {
- ARM_COMPUTE_INFO("Mali GPU unknown. Target is set to the default one.");
- }
+ ARM_COMPUTE_INFO("Can't find valid Mali GPU. Target is set to MIDGARD.");
+ return GPUTarget::MIDGARD;
}
- else
+
+ const char target = name_parts.str(1)[0];
+ const std::string &version = name_parts.str(2);
+
+ switch(target)
{
- ARM_COMPUTE_INFO("Can't find valid Mali GPU. Target is set to the default one.");
+ case 'T':
+ return get_midgard_target(version);
+ case 'G':
+ return get_bifrost_target(version);
+ default:
+ ARM_COMPUTE_INFO("Mali GPU unknown. Target is set to the default one.");
+ return GPUTarget::MIDGARD;
}
-
- return target;
}
GPUTarget get_arch_from_target(GPUTarget target)