Пример #1
0
void
context::get_version(cl_context ctx, int *major, int *minor)
{
    cl_device_id s_buff[16];
    size_t size;
    pyopencl_buf<cl_device_id> d_buff(0);
    cl_device_id *devs = s_buff;
    pyopencl_call_guarded(clGetContextInfo, ctx, CL_CONTEXT_DEVICES,
                          0, nullptr, buf_arg(size));
    if (PYOPENCL_UNLIKELY(!size)) {
        throw clerror("Context.get_version", CL_INVALID_VALUE,
                      "Cannot get devices from context.");
    }
    if (PYOPENCL_UNLIKELY(size > sizeof(s_buff))) {
        d_buff.resize(size / sizeof(cl_device_id));
        devs = d_buff.get();
    }
    pyopencl_call_guarded(clGetContextInfo, ctx, CL_CONTEXT_DEVICES,
                          size_arg(devs, size), buf_arg(size));
    device::get_version(devs[0], major, minor);
}
Пример #2
0
void
platform::get_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 (PYOPENCL_UNLIKELY(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("Platform.get_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));
}