File: platform.cpp

package info (click to toggle)
clinfo 0.0.20130513-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 464 kB
  • ctags: 146
  • sloc: sh: 1,054; cpp: 853; makefile: 8
file content (67 lines) | stat: -rw-r--r-- 1,671 bytes parent folder | download
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
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "platform.h"

#include "device.h"

platform::platform(cl_platform_id id) throw() : id(id)
{
        return;
}

platform::platform(platform const &p) :
        id(p.id),
        profile(p.profile),
        version(p.version),
        name(p.name),
        vendor(p.vendor),
        extensions(p.extensions),
        devices(p.devices)
{
        return;
}

platform::~platform() throw()
{
        return;
}

void platform::load()
{
        query(name, CL_PLATFORM_NAME);
        query(vendor, CL_PLATFORM_VENDOR);
        query(profile, CL_PLATFORM_PROFILE);
        query(version, CL_PLATFORM_VERSION);
        query(extensions, CL_PLATFORM_EXTENSIONS);

        cl_uint num_device_ids;
        cl_int rc = clGetDeviceIDs(id, CL_DEVICE_TYPE_ALL, 0, 0, &num_device_ids);
        if(rc == CL_DEVICE_NOT_FOUND)
                return;
        if(rc != CL_SUCCESS)
                throw rc;

        cl_device_id device_ids[num_device_ids];
        rc = clGetDeviceIDs(id, CL_DEVICE_TYPE_ALL, num_device_ids, device_ids, 0);
        if(rc != CL_SUCCESS)
                throw rc;

        for(cl_device_id const *i = device_ids; i != device_ids + num_device_ids; ++i)
                devices.insert(devices.end(), device(*i))->load();
}

void platform::query(std::string &value, cl_platform_info info)
{
        size_t length;
        cl_int rc = clGetPlatformInfo(id, info, 0, 0, &length);
        if(rc != CL_SUCCESS)
                throw rc;
        char buffer[length];
        rc = clGetPlatformInfo(id, info, length, buffer, 0);
        if(rc != CL_SUCCESS)
                throw rc;
        value = buffer;
}