Skip to content

Commit

Permalink
Merge pull request #1039 from omarahmed1111/eliminate-usage-of-regex-…
Browse files Browse the repository at this point in the history
…in-opencl

[UR][OPENCL] Eliminate usage of regex in opencl
  • Loading branch information
kbenzie committed Nov 24, 2023
2 parents 433b952 + 63dfb35 commit 0250c64
Show file tree
Hide file tree
Showing 2 changed files with 21 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
3 changes: 3 additions & 0 deletions source/adapters/opencl/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
//===----------------------------------------------------------------------===//
#include "common.hpp"

#include <algorithm>
#include <memory>

UR_APIEXPORT ur_result_t UR_APICALL
urKernelCreate(ur_program_handle_t hProgram, const char *pKernelName,
ur_kernel_handle_t *phKernel) {
Expand Down

0 comments on commit 0250c64

Please sign in to comment.