SCM Repository
Annotation of /trunk/src/lib/cl-target/clinfo.c
Parent Directory
|
Revision Log
Revision 3349 - (view) (download) (as text)
1 : | jhr | 1671 | /*! \file clinfo.c |
2 : | * | ||
3 : | * \author John Reppy | ||
4 : | * | ||
5 : | * \brief This file contains functions that can be used to determine properties of the | ||
6 : | * host machine's OpenCL support. | ||
7 : | */ | ||
8 : | |||
9 : | /* | ||
10 : | jhr | 3349 | * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu) |
11 : | * | ||
12 : | * COPYRIGHT (c) 2015 The University of Chicago | ||
13 : | jhr | 1671 | * All rights reserved. |
14 : | */ | ||
15 : | |||
16 : | #include "clinfo.h" | ||
17 : | #include <stdio.h> | ||
18 : | #include <string.h> | ||
19 : | #include <stdlib.h> | ||
20 : | |||
21 : | #define MAX_PLATFORMS 16 | ||
22 : | |||
23 : | static bool GetDevices (PlatformInfo_t *plat); | ||
24 : | |||
25 : | #define CHECK(call) do { \ | ||
26 : | cl_int __sts = call; \ | ||
27 : | if (__sts != CL_SUCCESS) { \ | ||
28 : | fprintf(stderr, "error %d at %s:%d\n", __sts, __FILE__, __LINE__); \ | ||
29 : | exit (1); \ | ||
30 : | } \ | ||
31 : | } while (0) | ||
32 : | |||
33 : | |||
34 : | CLInfo_t *GetCLInfo () | ||
35 : | { | ||
36 : | cl_platform_id platformIDs[MAX_PLATFORMS]; | ||
37 : | char buf[512]; | ||
38 : | |||
39 : | // get platform info | ||
40 : | // get number of OpenCL platforms | ||
41 : | cl_uint numPlatforms; | ||
42 : | CHECK(clGetPlatformIDs (MAX_PLATFORMS, platformIDs, &numPlatforms)); | ||
43 : | |||
44 : | PlatformInfo_t *plats = NEWVEC(PlatformInfo_t, numPlatforms); | ||
45 : | for (int i = 0; i < numPlatforms; i++) { | ||
46 : | clGetPlatformInfo (platformIDs[i], CL_PLATFORM_NAME, sizeof(buf), buf, 0); | ||
47 : | plats[i].name = NEWSTR(buf); | ||
48 : | plats[i].id = platformIDs[i]; | ||
49 : | // get OpenCL version info | ||
50 : | clGetPlatformInfo (platformIDs[i], CL_PLATFORM_VERSION, sizeof(buf), buf, 0); | ||
51 : | // FIXME: parser version info | ||
52 : | // get extension info | ||
53 : | // FIXME: TODO | ||
54 : | // get device info | ||
55 : | if (! GetDevices (&(plats[i]))) { | ||
56 : | // free storage | ||
57 : | for (int j = 0; j <= i; j++) { | ||
58 : | free (plats[i].name); | ||
59 : | } | ||
60 : | free (plats); | ||
61 : | } | ||
62 : | } | ||
63 : | |||
64 : | CLInfo_t *info = NEW(CLInfo_t); | ||
65 : | info->numPlatforms = numPlatforms; | ||
66 : | info->platforms = plats; | ||
67 : | |||
68 : | return info; | ||
69 : | |||
70 : | } | ||
71 : | |||
72 : | static char *GetStringInfo (cl_device_id dev, cl_device_info param) | ||
73 : | { | ||
74 : | char buf[1024]; | ||
75 : | CHECK(clGetDeviceInfo (dev, param, sizeof(buf), buf, 0)); | ||
76 : | return NEWSTR(buf); | ||
77 : | } | ||
78 : | |||
79 : | static bool GetDevices (PlatformInfo_t *plat) | ||
80 : | { | ||
81 : | cl_uint numDevs; | ||
82 : | char buf[512]; | ||
83 : | |||
84 : | // get number of devices for the platform | ||
85 : | clGetDeviceIDs (plat->id, CL_DEVICE_TYPE_ALL, 0, 0, &numDevs); | ||
86 : | |||
87 : | if (numDevs == 0) { | ||
88 : | plat->numDevices = 0; | ||
89 : | plat->devices = 0; | ||
90 : | return false; | ||
91 : | } | ||
92 : | |||
93 : | plat->numDevices = numDevs; | ||
94 : | plat->devices = NEWVEC(DeviceInfo_t, numDevs); | ||
95 : | |||
96 : | cl_device_id *devices = NEWVEC(cl_device_id, numDevs); | ||
97 : | CHECK(clGetDeviceIDs (plat->id, CL_DEVICE_TYPE_ALL, numDevs, devices, 0)); | ||
98 : | |||
99 : | for (int i = 0; i < numDevs; i++) { | ||
100 : | DeviceInfo_t *dev = &(plat->devices[i]); | ||
101 : | dev->name = GetStringInfo(devices[i], CL_DEVICE_NAME); | ||
102 : | dev->vendor = GetStringInfo(devices[i], CL_DEVICE_VENDOR); | ||
103 : | dev->id = devices[i]; | ||
104 : | CHECK(clGetDeviceInfo ( | ||
105 : | devices[i], CL_DEVICE_VERSION, sizeof(buf), buf, 0)); | ||
106 : | if (sscanf (buf, "OpenCL %d.%d", &(dev->majorVersion), &(dev->minorVersion)) != 2) { | ||
107 : | fprintf(stderr, "error scanning version string: \"%s\"\n", buf); | ||
108 : | exit (1); | ||
109 : | } | ||
110 : | CHECK(clGetDeviceInfo ( | ||
111 : | lamonts | 2060 | devices[i], CL_DEVICE_VENDOR_ID, sizeof(cl_uint), &(dev->vendorId), 0)); |
112 : | CHECK(clGetDeviceInfo ( | ||
113 : | jhr | 1671 | devices[i], CL_DEVICE_TYPE, sizeof(cl_device_type), &(dev->ty), 0)); |
114 : | CHECK(clGetDeviceInfo ( | ||
115 : | devices[i], CL_DEVICE_AVAILABLE, sizeof(cl_bool), &(dev->isAvail), 0)); | ||
116 : | CHECK(clGetDeviceInfo ( | ||
117 : | devices[i], CL_DEVICE_ADDRESS_BITS, sizeof(cl_uint), &(dev->addrBits), 0)); | ||
118 : | CHECK(clGetDeviceInfo ( | ||
119 : | devices[i], CL_DEVICE_ENDIAN_LITTLE, sizeof(cl_bool), &(dev->littleEndian), 0)); | ||
120 : | CHECK(clGetDeviceInfo ( | ||
121 : | devices[i], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &(dev->numCUs), 0)); | ||
122 : | CHECK(clGetDeviceInfo ( | ||
123 : | devices[i], CL_DEVICE_MAX_CONSTANT_ARGS, sizeof(cl_uint), &(dev->maxConstArgs), 0)); | ||
124 : | CHECK(clGetDeviceInfo ( | ||
125 : | devices[i], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), &(dev->maxWIDims), 0)); | ||
126 : | CHECK(clGetDeviceInfo ( | ||
127 : | devices[i], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &(dev->maxWGSize), 0)); | ||
128 : | size_t szb = sizeof(size_t) * dev->maxWIDims; | ||
129 : | dev->maxWISize = (size_t *) CheckedAlloc (szb); | ||
130 : | CHECK(clGetDeviceInfo (devices[i], CL_DEVICE_MAX_WORK_ITEM_SIZES, szb, dev->maxWISize, 0)); | ||
131 : | CHECK(clGetDeviceInfo ( | ||
132 : | devices[i], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), &(dev->globalMemSzb), 0)); | ||
133 : | CHECK(clGetDeviceInfo ( | ||
134 : | devices[i], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(cl_ulong), &(dev->localMemSzb), 0)); | ||
135 : | CHECK(clGetDeviceInfo ( | ||
136 : | devices[i], CL_DEVICE_MAX_PARAMETER_SIZE, sizeof(size_t), &(dev->maxParamSzb), 0)); | ||
137 : | CHECK(clGetDeviceInfo ( | ||
138 : | devices[i], CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof(cl_ulong), &(dev->maxConstBufSzb), 0)); | ||
139 : | CHECK(clGetDeviceInfo ( | ||
140 : | devices[i], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(cl_ulong), &(dev->maxAllocSzb), 0)); | ||
141 : | cl_bool imagesSupported; | ||
142 : | CHECK(clGetDeviceInfo ( | ||
143 : | devices[i], CL_DEVICE_IMAGE_SUPPORT, sizeof(cl_bool), &imagesSupported, 0)); | ||
144 : | if (imagesSupported) { | ||
145 : | CHECK(clGetDeviceInfo ( | ||
146 : | devices[i], CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof(size_t), &(dev->maxImg2D[0]), 0)); | ||
147 : | CHECK(clGetDeviceInfo ( | ||
148 : | devices[i], CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof(size_t), &(dev->maxImg2D[1]), 0)); | ||
149 : | CHECK(clGetDeviceInfo ( | ||
150 : | devices[i], CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof(size_t), &(dev->maxImg3D[0]), 0)); | ||
151 : | CHECK(clGetDeviceInfo ( | ||
152 : | devices[i], CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof(size_t), &(dev->maxImg3D[1]), 0)); | ||
153 : | CHECK(clGetDeviceInfo ( | ||
154 : | devices[i], CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof(size_t), &(dev->maxImg3D[2]), 0)); | ||
155 : | } | ||
156 : | else { | ||
157 : | dev->maxImg2D[0] = dev->maxImg2D[1] = 0; | ||
158 : | dev->maxImg3D[0] = dev->maxImg3D[1] = dev->maxImg3D[2] = 0; | ||
159 : | } | ||
160 : | CHECK(clGetDeviceInfo ( | ||
161 : | devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->charWid), 0)); | ||
162 : | CHECK(clGetDeviceInfo ( | ||
163 : | devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->shortWid), 0)); | ||
164 : | CHECK(clGetDeviceInfo ( | ||
165 : | devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->intWid), 0)); | ||
166 : | CHECK(clGetDeviceInfo ( | ||
167 : | devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->longWid), 0)); | ||
168 : | CHECK(clGetDeviceInfo ( | ||
169 : | devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->floatWid), 0)); | ||
170 : | CHECK(clGetDeviceInfo ( | ||
171 : | devices[i], CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, sizeof(cl_uint), &(dev->doubleWid), 0)); | ||
172 : | // determine the compute-unit width | ||
173 : | lamonts | 2060 | |
174 : | jhr | 1671 | if (isCPUDevice(dev)) |
175 : | dev->cuWidth = 1; | ||
176 : | else if (isGPUDevice(dev)) | ||
177 : | lamonts | 2060 | if (dev->vendorId == AMD_VENDOR_ID) |
178 : | jhr | 1671 | dev->cuWidth = 64; // an AMD wavefront is 64-wide |
179 : | lamonts | 2060 | else if (dev->vendorId == NVIDIA_VENDOR_ID) |
180 : | jhr | 1671 | dev->cuWidth = 32; // an NVIDIA warp is 32-wide |
181 : | else | ||
182 : | dev->cuWidth = 32; // FIXME: not sure what this should be? | ||
183 : | else | ||
184 : | dev->cuWidth = 1; // FIXME: not sure what this should be? | ||
185 : | |||
186 : | } | ||
187 : | |||
188 : | free(devices); | ||
189 : | |||
190 : | return true; | ||
191 : | } | ||
192 : | |||
193 : | void PrintCLInfo (FILE *outS, CLInfo_t *clinfo) | ||
194 : | { | ||
195 : | if (clinfo->numPlatforms == 0) { | ||
196 : | fprintf(outS, "No OpenCL platforms\n"); | ||
197 : | return; | ||
198 : | } | ||
199 : | |||
200 : | fprintf(outS, "OpenCL profile:\n"); | ||
201 : | for (int i = 0; i < clinfo->numPlatforms; i++) { | ||
202 : | PlatformInfo_t *plat = &(clinfo->platforms[i]); | ||
203 : | fprintf (outS, " Platform %d (%s)\n", i, plat->name); | ||
204 : | for (int j = 0; j < plat->numDevices; j++) { | ||
205 : | DeviceInfo_t *dev = &(plat->devices[j]); | ||
206 : | if (dev->isAvail) | ||
207 : | fprintf (outS, " Device %d.%d (%s):\n", i, j, dev->name); | ||
208 : | else | ||
209 : | fprintf (outS, " Device %d.%d (%s): **UNAVAILABLE**\n", i, j, dev->name); | ||
210 : | fprintf (outS, " Vendor: %s\n", dev->vendor); | ||
211 : | lamonts | 2060 | fprintf (outS, " Vendor Id: %d\n", dev->vendorId); |
212 : | jhr | 1671 | fprintf (outS, " OpenCL version: %d.%d\n", |
213 : | dev->majorVersion, dev->minorVersion); | ||
214 : | fprintf (outS, " Type: "); | ||
215 : | if (isCPUDevice(dev)) fprintf (outS, " CPU"); | ||
216 : | if (isGPUDevice(dev)) fprintf (outS, " GPU"); | ||
217 : | if (dev->ty & CL_DEVICE_TYPE_ACCELERATOR) fprintf (outS, " ACCELERATOR"); | ||
218 : | if (dev->ty & CL_DEVICE_TYPE_DEFAULT) fprintf (outS, " DEFAULT"); | ||
219 : | fprintf (outS, "\n"); | ||
220 : | fprintf (outS, " Address size: %d\n", dev->addrBits); | ||
221 : | fprintf (outS, " Endianess: %s\n", dev->littleEndian ? "LITTLE" : "BIG"); | ||
222 : | fprintf (outS, " Num. compute units: %d", dev->numCUs); | ||
223 : | if (dev->cuWidth > 1) | ||
224 : | fprintf (outS, " * %d\n", dev->cuWidth); | ||
225 : | else | ||
226 : | fprintf (outS, "\n"); | ||
227 : | fprintf (outS, " Max. dimensions: %d\n", dev->maxWIDims); | ||
228 : | fprintf (outS, " Max. work group size: %ld\n", (long)(dev->maxWGSize)); | ||
229 : | fprintf (outS, " Max. work items: "); | ||
230 : | for (int k = 0; k < dev->maxWIDims; k++) | ||
231 : | fprintf (outS, "%s%ld", (k > 0) ? " x " : "", (long)(dev->maxWISize[k])); | ||
232 : | fprintf (outS, "\n"); | ||
233 : | fprintf (outS, " Global memory size: %ld\n", (long)(dev->globalMemSzb)); | ||
234 : | fprintf (outS, " Local memory size: %ld\n", (long)(dev->localMemSzb)); | ||
235 : | fprintf (outS, " Max. parameter size: %ld\n", (long)(dev->maxParamSzb)); | ||
236 : | fprintf (outS, " Max. allocation size: %ld\n", (long)(dev->maxAllocSzb)); | ||
237 : | fprintf (outS, " Max. const. buffer size: %ld\n", (long)(dev->maxConstBufSzb)); | ||
238 : | fprintf (outS, " Max. const. arguments: %d\n", dev->maxConstArgs); | ||
239 : | fprintf (outS, " Max. 2D image size: %ld x %ld\n", | ||
240 : | (long)(dev->maxImg2D[0]), (long)(dev->maxImg2D[1])); | ||
241 : | fprintf (outS, " Max. 3D image size: %ld x %ld x %ld\n", | ||
242 : | (long)(dev->maxImg3D[0]), (long)(dev->maxImg3D[1]), (long)(dev->maxImg3D[2])); | ||
243 : | fprintf (outS, " Prefered vector width: char%d, short%d, int%d, long%d\n", | ||
244 : | dev->charWid, dev->shortWid, dev->intWid, dev->longWid); | ||
245 : | fprintf (outS, " float%d", dev->floatWid); | ||
246 : | if (dev->doubleWid > 0) | ||
247 : | fprintf (outS, ", double%d\n", dev->doubleWid); | ||
248 : | else | ||
249 : | fprintf (outS, "\n"); | ||
250 : | } | ||
251 : | } | ||
252 : | |||
253 : | } |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |