Skip to content

Commit

Permalink
[UR][OPENCL] eliminate usage of regex in opencl
Browse files Browse the repository at this point in the history
  • Loading branch information
omarahmed1111 committed Nov 3, 2023
1 parent be53fb3 commit 56f6994
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions source/adapters/opencl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <climits>
#include <map>
#include <mutex>
#include <regex>
#include <ur/ur.hpp>

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

if (std::regex_search(Version, Match, Rx) && (Match.size() == 3)) {
OCLMajor = strtoul(Match[1].str().c_str(), nullptr, 10);
OCLMinor = strtoul(Match[2].str().c_str(), nullptr, 10);
bool haveOCLPrefix =
std::equal(prefix.begin(), prefix.end(), Version.begin());

if (haveOCLPrefix && versionBegin != std::string::npos &&
versionEnd != std::string::npos &&
versionSeparator != std::string::npos) {

std::string versionMajor{Version.begin() + versionBegin + 1,
Version.begin() + versionSeparator};
std::string versionMinor{Version.begin() + versionSeparator + 1,
Version.begin() + versionEnd};

OCLMajor = strtoul(versionMajor.c_str(), nullptr, 10);
OCLMinor = strtoul(versionMinor.c_str(), nullptr, 10);

if (!isValid()) {
OCLMajor = OCLMinor = 0;
Expand Down

0 comments on commit 56f6994

Please sign in to comment.