-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathutil.hpp
More file actions
69 lines (60 loc) · 1.75 KB
/
util.hpp
File metadata and controls
69 lines (60 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
// Copyright (c) 2021-2026 Ben Ashbaugh
//
// SPDX-License-Identifier: MIT
*/
#pragma once
#include <CL/opencl.hpp>
#include <string>
static cl_version getDeviceOpenCLVersion(
const cl::Device& device)
{
cl_uint major = 0;
cl_uint minor = 0;
std::string version = device.getInfo<CL_DEVICE_VERSION>();
// The device version string has the form:
// OpenCL <Major>.<Minor> <Vendor Specific Info>
const std::string prefix{"OpenCL "};
if (!version.compare(0, prefix.length(), prefix)) {
const char* check = version.c_str() + prefix.length();
while (isdigit(check[0])) {
major *= 10;
major += check[0] - '0';
++check;
}
if (check[0] == '.') {
++check;
}
while (isdigit(check[0])) {
minor *= 10;
minor += check[0] - '0';
++check;
}
}
return CL_MAKE_VERSION(major, minor, 0);
}
static bool checkDeviceForExtension(
const cl::Device& device,
const char* extensionName)
{
bool supported = false;
if (extensionName && !strchr(extensionName, ' ')) {
std::string deviceExtensions = device.getInfo<CL_DEVICE_EXTENSIONS>();
const char* start = deviceExtensions.c_str();
while (true) {
const char* where = strstr(start, extensionName);
if (!where) {
break;
}
const char* terminator = where + strlen(extensionName);
if (where == start || *(where - 1) == ' ') {
if (*terminator == ' ' || *terminator == '\0') {
supported = true;
break;
}
}
start = terminator;
}
}
return supported;
}