From 3c4c1e756bf3c042f0788e45b9d997054ce3eae2 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Fri, 24 Nov 2023 14:50:43 +0000 Subject: [PATCH] Merge pull request #1039 from omarahmed1111/eliminate-usage-of-regex-in-opencl [UR][OPENCL] Eliminate usage of regex in opencl --- source/adapters/opencl/common.hpp | 24 ++++++++++++++++++------ source/adapters/opencl/kernel.cpp | 3 +++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/source/adapters/opencl/common.hpp b/source/adapters/opencl/common.hpp index 767dc02fda..0cb19694a6 100644 --- a/source/adapters/opencl/common.hpp +++ b/source/adapters/opencl/common.hpp @@ -12,7 +12,6 @@ #include #include #include -#include #include /** @@ -72,12 +71,25 @@ class OpenCLVersion { * 'OpenCL' 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; diff --git a/source/adapters/opencl/kernel.cpp b/source/adapters/opencl/kernel.cpp index e7c8444a17..44157b826b 100644 --- a/source/adapters/opencl/kernel.cpp +++ b/source/adapters/opencl/kernel.cpp @@ -9,6 +9,9 @@ //===----------------------------------------------------------------------===// #include "common.hpp" +#include +#include + UR_APIEXPORT ur_result_t UR_APICALL urKernelCreate(ur_program_handle_t hProgram, const char *pKernelName, ur_kernel_handle_t *phKernel) {