-
Notifications
You must be signed in to change notification settings - Fork 0
/
amdgpu-devices.c
119 lines (98 loc) · 4.09 KB
/
amdgpu-devices.c
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright (c) 2016 Wladimir J. van der Laan
// Distributed under the MIT software license.
// Based on an example from the OpenCL cookbook.
#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
struct platform_data_item {
int id;
char *name;
};
struct platform_data_item platform_data_items[] = {
{ CL_PLATFORM_PROFILE, "Profile"},
{ CL_PLATFORM_VERSION, "Version"},
{ CL_PLATFORM_NAME, "Name"},
{ CL_PLATFORM_VENDOR, "Vendor"},
{ CL_PLATFORM_EXTENSIONS, "Extensions"},
};
#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))
int main() {
int i, j;
char* value;
size_t valueSize;
cl_uint platformCount = 0;
cl_platform_id* platforms;
cl_uint deviceCount;
cl_device_id* devices;
cl_uint maxComputeUnits;
// get all platforms
if (clGetPlatformIDs(0, NULL, &platformCount) != CL_SUCCESS) {
printf("Unable to get platform IDs\n");
exit(1);
}
platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
if (clGetPlatformIDs(platformCount, platforms, NULL) != CL_SUCCESS) {
printf("Unable to get platform IDs\n");
exit(1);
}
for (i = 0; i < platformCount; i++) {
printf("%i. Platform\n", i+1);
char data[1024];
size_t retsize;
for (int j=0; j<ARRAYLEN(platform_data_items); ++j) {
if (clGetPlatformInfo(platforms[i], platform_data_items[j].id, sizeof(data), data, &retsize) != CL_SUCCESS || retsize == sizeof(data)) {
printf("Unable to get platform %s\n", platform_data_items[j].name);
continue;
}
printf(" %s: %s\n", platform_data_items[j].name, data);
}
// get all devices
if (clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount) != CL_SUCCESS) {
printf("Unable to get device IDs for platform %p\n", platforms[i]);
continue;
}
devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount);
if (clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL) != CL_SUCCESS) {
printf("Unable to get device IDs for platform %p\n", platforms[i]);
continue;
}
// for each device print critical attributes
for (j = 0; j < deviceCount; j++) {
// print device name
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL);
printf("%d. Device: %s\n", j+1, value);
free(value);
// print hardware device version
clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, valueSize, value, NULL);
printf(" %d.%d Hardware version: %s\n", j+1, 1, value);
free(value);
// print software driver version
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL);
printf(" %d.%d Software version: %s\n", j+1, 2, value);
free(value);
// print c version supported by compiler for device
clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, value, NULL);
printf(" %d.%d OpenCL C version: %s\n", j+1, 3, value);
free(value);
// print parallel compute units
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(maxComputeUnits), &maxComputeUnits, NULL);
printf(" %d.%d Parallel compute units: %d\n", j+1, 4, maxComputeUnits);
}
free(devices);
}
free(platforms);
return 0;
}