Skip to content
Snippets Groups Projects
Commit 9b34f88c authored by Yichao Yu's avatar Yichao Yu
Browse files

get_platform_version

parent e4652bee
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,9 @@
#include "device.h"
#include "clhelper.h"
#include <stdlib.h>
#include <regex>
namespace pyopencl {
template class clobj<cl_platform_id>;
......@@ -28,6 +31,33 @@ platform::get_info(cl_uint param_name) const
}
}
static const std::regex ver_regex("^OpenCL ([0-9]+)\\.([0-9]+).*");
void
get_platform_version(cl_platform_id plat, int *major, int *minor)
{
char s_buff[128];
size_t size;
pyopencl_buf<char> d_buff(0);
char *name = s_buff;
pyopencl_call_guarded(clGetPlatformInfo, plat, CL_PLATFORM_VERSION,
0, nullptr, buf_arg(size));
if (size > sizeof(s_buff)) {
d_buff.resize(size);
name = d_buff.get();
}
pyopencl_call_guarded(clGetPlatformInfo, plat, CL_PLATFORM_VERSION,
size_arg(name, size), buf_arg(size));
std::cmatch ver_match;
if (!std::regex_match(name, ver_match, ver_regex)) {
throw clerror("get_platform_version", CL_INVALID_VALUE,
"platform returned non-conformant "
"platform version string");
}
*major = atoi(name + ver_match.position(1));
*minor = atoi(name + ver_match.position(2));
}
}
// c wrapper
......
......@@ -23,6 +23,8 @@ public:
extern template void print_clobj<platform>(std::ostream&, const platform*);
void get_platform_version(cl_platform_id plat, int *major, int *minor);
// }}}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment