Skip to content

Commit 0250c64

Browse files
authored
Merge pull request #1039 from omarahmed1111/eliminate-usage-of-regex-in-opencl
[UR][OPENCL] Eliminate usage of regex in opencl
2 parents 433b952 + 63dfb35 commit 0250c64

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-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;

source/adapters/opencl/kernel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
//===----------------------------------------------------------------------===//
1010
#include "common.hpp"
1111

12+
#include <algorithm>
13+
#include <memory>
14+
1215
UR_APIEXPORT ur_result_t UR_APICALL
1316
urKernelCreate(ur_program_handle_t hProgram, const char *pKernelName,
1417
ur_kernel_handle_t *phKernel) {

0 commit comments

Comments
 (0)