summaryrefslogtreecommitdiff
path: root/sc/workben/opencl/platform_detect.cxx
blob: 5fb2544c54ccfd81f37b2683cabef57f95f40689 (plain)
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
70
71
72
73
74
75
76
#include <cstdlib>
#include <iostream>
#include <vector>
#include <string>

#include <clew/clew.h>

using namespace std;

#ifdef WIN32
#define OPENCL_DLL_NAME "OpenCL.dll"
#elif defined(MACOSX)
#define OPENCL_DLL_NAME NULL
#else
#define OPENCL_DLL_NAME "libOpenCL.so"
#endif

int main()
{
    int status = clewInit(OPENCL_DLL_NAME);
    if (status < 0)
    {
        cout << "failed to load" << endl;
        return EXIT_FAILURE;
    }

    cout << "OpenCL.dll loaded successfully." << endl;

    cl_uint platformCount = 0;
    clGetPlatformIDs(0, NULL, &platformCount);

    cout << "number of platforms: " << platformCount << endl;
    vector<cl_platform_id> platformIDs(platformCount);
    if (clGetPlatformIDs(platformCount, &platformIDs[0], NULL) != CL_SUCCESS)
    {
        cout << "failed to get platform IDs" << endl;
        return EXIT_FAILURE;
    }

    for (size_t i = 0, n = platformIDs.size(); i < n; ++i)
    {
        cout << "* platform (ID=" << platformIDs[i] << ")" << endl;
        string param(100, '\0');
        if (clGetPlatformInfo(platformIDs[i], CL_PLATFORM_PROFILE, param.size(), &param[0], NULL) == CL_SUCCESS)
            cout << "  profile: " << param.c_str() << endl;
        if (clGetPlatformInfo(platformIDs[i], CL_PLATFORM_VERSION, param.size(), &param[0], NULL) == CL_SUCCESS)
            cout << "  version: " << param.c_str() << endl;
        if (clGetPlatformInfo(platformIDs[i], CL_PLATFORM_NAME, param.size(), &param[0], NULL) == CL_SUCCESS)
            cout << "  name: " << param.c_str() << endl;
        if (clGetPlatformInfo(platformIDs[i], CL_PLATFORM_VENDOR, param.size(), &param[0], NULL) == CL_SUCCESS)
            cout << "  vendor: " << param.c_str() << endl;
        if (clGetPlatformInfo(platformIDs[i], CL_PLATFORM_EXTENSIONS, param.size(), &param[0], NULL) == CL_SUCCESS)
            cout << "  extensions: " << param.c_str() << endl;

        cl_uint deviceCount = 0;
        clGetDeviceIDs(platformIDs[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount);
        cout << "  number of devices: " << deviceCount << endl;

        vector<cl_device_id> deviceIDs(deviceCount);
        if (clGetDeviceIDs(platformIDs[i], CL_DEVICE_TYPE_ALL, deviceCount, &deviceIDs[0], NULL) != CL_SUCCESS)
            continue;

        for (size_t j = 0; j < deviceIDs.size(); ++j)
        {
            cout << "  * device (ID=" << deviceIDs[j] << ")" << endl;
            if (clGetDeviceInfo(deviceIDs[j], CL_DEVICE_VENDOR, param.size(), &param[0], NULL) == CL_SUCCESS)
                cout << "    vendor: " << param.c_str() << endl;
            if (clGetDeviceInfo(deviceIDs[j], CL_DEVICE_VERSION, param.size(), &param[0], NULL) == CL_SUCCESS)
                cout << "    version: " << param.c_str() << endl;
            if (clGetDeviceInfo(deviceIDs[j], CL_DRIVER_VERSION, param.size(), &param[0], NULL) == CL_SUCCESS)
                cout << "    driver version: " << param.c_str() << endl;
        }
    }

    return EXIT_SUCCESS;
}