Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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