Skip to content

Commit 56f6994

Browse files
committed
[UR][OPENCL] eliminate usage of regex in opencl
1 parent be53fb3 commit 56f6994

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

source/adapters/opencl/common.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <climits>
1313
#include <map>
1414
#include <mutex>
15-
#include <regex>
1615
#include <ur/ur.hpp>
1716

1817
/**
@@ -72,12 +71,25 @@ class OpenCLVersion {
7271
* 'OpenCL<space><ocl_major_version.ocl_minor_version><space><vendor-specific
7372
* information>' for devices.
7473
*/
75-
std::regex Rx("OpenCL ([0-9]+)\\.([0-9]+)");
76-
std::smatch Match;
74+
std::string_view prefix = "OpenCL ";
75+
size_t versionBegin = Version.find_first_of(" ");
76+
size_t versionEnd = Version.find_first_of(" ", versionBegin + 1);
77+
size_t versionSeparator = Version.find_first_of(".", versionBegin + 1);
7778

78-
if (std::regex_search(Version, Match, Rx) && (Match.size() == 3)) {
79-
OCLMajor = strtoul(Match[1].str().c_str(), nullptr, 10);
80-
OCLMinor = strtoul(Match[2].str().c_str(), nullptr, 10);
79+
bool haveOCLPrefix =
80+
std::equal(prefix.begin(), prefix.end(), Version.begin());
81+
82+
if (haveOCLPrefix && versionBegin != std::string::npos &&
83+
versionEnd != std::string::npos &&
84+
versionSeparator != std::string::npos) {
85+
86+
std::string versionMajor{Version.begin() + versionBegin + 1,
87+
Version.begin() + versionSeparator};
88+
std::string versionMinor{Version.begin() + versionSeparator + 1,
89+
Version.begin() + versionEnd};
90+
91+
OCLMajor = strtoul(versionMajor.c_str(), nullptr, 10);
92+
OCLMinor = strtoul(versionMinor.c_str(), nullptr, 10);
8193

8294
if (!isValid()) {
8395
OCLMajor = OCLMinor = 0;

0 commit comments

Comments
 (0)