source: proiecte/NBody/NBody 2.0/GetDeviceInfos.cpp @ 34

Last change on this file since 34 was 34, checked in by (none), 14 years ago

Iulian Milas: ultima versiune a NBody (17 dec 2009)

File size: 9.7 KB
Line 
1#include "NBody.hpp"
2
3/////////////////////////////////// NBody::getDeviceInfo Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
4//
5// Returns information about the device on  which the simulation
6// will run. Also some variables will be init here based on the
7// device information.
8//
9/////////////////////////////////// NBody::getDeviceInfo Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
10
11int NBody::getDeviceInfo()
12{
13        cl_int status = CL_SUCCESS;
14
15        cl_char infoString[1024] = {0};
16        cl_ulong infoLong;
17        cl_uint infoInt;
18        cl_bool infoBool;
19        size_t infoSize_t;
20        size_t *infoSz_t;
21       
22        //----------------------------------
23        status= clGetDeviceInfo(
24                        devices[0], 
25                        CL_DEVICE_NAME, 
26                        sizeof(infoString), 
27                        infoString, 
28                        NULL);
29       
30        if (status != CL_SUCCESS){
31                std::cout << "clGetDeviceInfo CL_DEVICE_NAME failed." << std::endl;
32                return 1;
33        }else{
34                std::cout << "CL_DEVICE_NAME : \t\t" << infoString << std::endl;
35        }
36
37        //----------------------------------
38        status = clGetDeviceInfo(
39                        devices[0], 
40                        CL_DEVICE_VENDOR, 
41                        sizeof(infoString), 
42                        infoString, 
43                        NULL);
44       
45        if (status != CL_SUCCESS){
46                std::cout << "clGetDeviceInfo CL_DEVICE_VENDOR failed." << std::endl;
47                return 1;
48        }else{
49                std::cout << "CL_DEVICE_VENDOR : \t\t\t" << infoString << std::endl;
50        }
51       
52        //----------------------------------
53        status = clGetDeviceInfo(
54                        devices[0], 
55                        CL_DRIVER_VERSION, 
56                        sizeof(infoString), 
57                        infoString, 
58                        NULL);
59       
60        if (status != CL_SUCCESS){
61                std::cout << "clGetDeviceInfo CL_DRIVER_VERSION failed." << std::endl;
62                return 1;
63        }else{
64                std::cout << "CL_DRIVER_VERSION : \t\t\t" << infoString << std::endl;
65        }
66
67        //----------------------------------
68        status = clGetDeviceInfo(
69                        devices[0], 
70                        CL_DEVICE_TYPE, 
71                        sizeof(cl_device_type), 
72                        (void*)&infoLong, 
73                        NULL);
74       
75        if (status != CL_SUCCESS){
76                std::cout << "clGetDeviceInfo CL_DEVICE_TYPE failed." << std::endl;
77                return 1;
78        }else{
79                std::cout << "CL_DEVICE_TYPE : \t\t\t";
80
81                switch(infoLong){
82                        case CL_DEVICE_TYPE_CPU :                       std::cout << "CL_DEVICE_TYPE_CPU" << std::endl;
83                                                                                                break;
84                        case CL_DEVICE_TYPE_GPU :                       std::cout << "CL_DEVICE_TYPE_GPU" << std::endl;
85                                                                                                break;
86                        case CL_DEVICE_TYPE_ACCELERATOR :       std::cout << "CL_DEVICE_TYPE_ACCELERATOR" << std::endl;
87                                                                                                break;
88                        case CL_DEVICE_TYPE_ALL :                       std::cout << "CL_DEVICE_TYPE_ALL" << std::endl;
89                                                                                                break;
90                        case CL_DEVICE_TYPE_DEFAULT :           std::cout << "CL_DEVICE_TYPE_DEFAULT" << std::endl;
91                                                                                                break;
92                }
93        }
94
95        std::cout << std::endl;
96
97        //----------------------------------
98        // The number of parallel compute cores
99        // on the OpenCL device.
100
101        status = clGetDeviceInfo(
102            devices[0],
103            CL_DEVICE_MAX_COMPUTE_UNITS,
104            sizeof(cl_uint),
105            (void*)&infoInt,
106            NULL);
107
108        if (status != CL_SUCCESS){
109                std::cout << "clGetDeviceInfo CL_DEVICE_MAX_COMPUTE_UNITS failed." << std::endl;
110                return 1;
111        }else{
112                std::cout << "CL_DEVICE_MAX_COMPUTE_UNITS : \t\t" << (size_t)infoInt << std::endl;
113        }
114
115        //----------------------------------
116        status = clGetDeviceInfo(
117            devices[0],
118            CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,
119            sizeof(cl_uint),
120            (void*)&maxDimensions,
121            NULL);
122
123        if (status != CL_SUCCESS){
124                std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS failed." << std::endl;
125                return 1;
126        }else{
127                std::cout << "CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS : \t" << (size_t)maxDimensions << std::endl;
128        }
129           
130    maxWorkItemSizes = (size_t*)malloc(maxDimensions * sizeof(size_t));
131   
132        //----------------------------------
133        // Maximum number of work-items that can be
134        // specified in each dimension of the work-group
135        // to clEnqueueNDRangeKernel.
136
137    status = clGetDeviceInfo(
138            devices[0],
139            CL_DEVICE_MAX_WORK_ITEM_SIZES,
140            sizeof(size_t) * maxDimensions,
141            (void*)maxWorkItemSizes,
142            NULL);
143       
144        if (status != CL_SUCCESS){
145                std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_SIZES failed." << std::endl;
146                return 1;
147        }else{
148                std::cout << "CL_DEVICE_MAX_WORK_ITEM_SIZES : \t" << (size_t)maxWorkItemSizes << std::endl;
149        }
150
151        //----------------------------------
152        // Maximum number of work-items in a work-group
153        // executing a kernel using the data parallel
154        // execution model
155
156
157        status = clGetDeviceInfo(
158            devices[0],
159            CL_DEVICE_MAX_WORK_GROUP_SIZE,
160            sizeof(size_t),
161            (void*)&maxWorkGroupSize,
162            NULL);
163       
164        if (status != CL_SUCCESS){
165                std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_GROUP_SIZE failed." << std::endl;
166                return 1;
167        }else{
168                std::cout << "CL_DEVICE_MAX_WORK_GROUP_SIZE : \t" << maxWorkGroupSize << std::endl;
169        }
170
171        std::cout << std::endl;
172
173        //----------------------------------
174        // Is CL_TRUE if images are supported by the
175        // OpenCL device and CL_FALSE otherwise.
176
177    status = clGetDeviceInfo(
178            devices[0],
179            CL_DEVICE_IMAGE_SUPPORT,
180            sizeof(cl_bool),
181            (void *)&infoBool,
182            NULL);
183
184        if (status != CL_SUCCESS){
185                std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE_SUPPORT failed." << std::endl;
186                return 1;
187        }else{
188                if (infoBool == true)
189                        std::cout << "CL_DEVICE_IMAGE_SUPPORT : \t\t" << "true" << std::endl;
190                else
191                        std::cout << "CL_DEVICE_IMAGE_SUPPORT : \t\t" << "false" << std::endl;
192        }
193
194        //----------------------------------
195        // Max width of 2D image in pixels. The minimum
196        // value is 8192 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
197
198    status = clGetDeviceInfo(
199            devices[0],
200            CL_DEVICE_IMAGE2D_MAX_WIDTH,
201            sizeof(size_t),
202            (void *)&infoSize_t,
203            NULL);
204
205        if (status != CL_SUCCESS){
206                std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE2D_MAX_WIDTH failed." << std::endl;
207                return 1;
208        }else{
209                std::cout << "CL_DEVICE_IMAGE2D_MAX_WIDTH : \t\t" << (size_t)infoSize_t
210                        << " pixels" << std::endl;
211        }
212
213        //----------------------------------
214        // Max height of 2D image in pixels. The minimum value
215        // is 8192 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
216
217    status = clGetDeviceInfo(
218            devices[0],
219            CL_DEVICE_IMAGE2D_MAX_HEIGHT,
220            sizeof(size_t),
221            (void *)&infoSize_t,
222            NULL);
223
224        if (status != CL_SUCCESS){
225                std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE2D_MAX_HEIGHT failed." << std::endl;
226                return 1;
227        }else{
228                std::cout << "CL_DEVICE_IMAGE2D_MAX_HEIGHT : \t\t" << (size_t)infoSize_t
229                        << " pixels" << std::endl;
230        }
231
232        //----------------------------------
233        // Max width of 3D image in pixels. The minimum value
234        // is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
235
236    status = clGetDeviceInfo(
237            devices[0],
238            CL_DEVICE_IMAGE3D_MAX_WIDTH,
239            sizeof(size_t),
240            (void *)&infoSize_t,
241            NULL);
242
243        if (status != CL_SUCCESS){
244                std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_WIDTH failed." << std::endl;
245                return 1;
246        }else{
247                std::cout << "CL_DEVICE_IMAGE3D_MAX_WIDTH : \t\t" << (size_t)infoSize_t
248                        << " pixels" << std::endl;
249        }
250
251        //----------------------------------
252        // Max height of 3D image in pixels. The minimum value
253        // is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
254
255    status = clGetDeviceInfo(
256            devices[0],
257            CL_DEVICE_IMAGE3D_MAX_HEIGHT,
258            sizeof(size_t),
259            (void *)&infoSize_t,
260            NULL);
261
262        if (status != CL_SUCCESS){
263                std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_HEIGHT failed." << std::endl;
264                return 1;
265        }else{
266                std::cout << "CL_DEVICE_IMAGE3D_MAX_HEIGHT : \t\t" << (size_t)infoSize_t
267                        << " pixels" << std::endl;
268        }
269
270        //----------------------------------
271        // Max depth of 3D image in pixels. The minimum value
272        // is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE.
273
274    status = clGetDeviceInfo(
275            devices[0],
276            CL_DEVICE_IMAGE3D_MAX_DEPTH,
277            sizeof(size_t),
278            (void *)&infoSize_t,
279            NULL);
280
281        if (status != CL_SUCCESS){
282                std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_DEPTH failed." << std::endl;
283                return 1;
284        }else{
285                std::cout << "CL_DEVICE_IMAGE3D_MAX_DEPTH : \t\t" << (size_t)infoSize_t
286                        << " pixels" << std::endl;
287        }
288
289        std::cout << std::endl;
290
291        //----------------------------------
292    status = clGetDeviceInfo(
293            devices[0],
294            CL_DEVICE_MAX_CLOCK_FREQUENCY,
295            sizeof(cl_uint),
296            (void *)&infoInt,
297            NULL);
298
299        if (status != CL_SUCCESS){
300                std::cout << "clGetDeviceInfo CL_DEVICE_MAX_CLOCK_FREQUENCY failed." << std::endl;
301                return 1;
302        }else{
303                std::cout << "CL_DEVICE_MAX_CLOCK_FREQUENCY : \t" << infoInt << " MHz" << std::endl;
304        }
305
306        //----------------------------------
307        // Size of global device memory in bytes.
308
309    status = clGetDeviceInfo(
310            devices[0],
311            CL_DEVICE_GLOBAL_MEM_SIZE,
312            sizeof(cl_ulong),
313            (void *)&infoLong,
314            NULL);
315
316        if (status != CL_SUCCESS){
317                std::cout << "clGetDeviceInfo CL_DEVICE_GLOBAL_MEM_SIZE failed." << std::endl;
318                return 1;
319        }else{
320                std::cout << "CL_DEVICE_GLOBAL_MEM_SIZE : \t\t" << infoLong << " bytes" << std::endl;
321        }
322
323        //----------------------------------
324        // Size of local memory arena in bytes.
325        // The minimum value is 16 KB.
326
327    status = clGetDeviceInfo(
328            devices[0],
329            CL_DEVICE_LOCAL_MEM_SIZE,
330            sizeof(cl_ulong),
331            (void *)&totalLocalMemory,
332            NULL);
333
334        if (status != CL_SUCCESS){
335                std::cout << "clGetDeviceInfo CL_DEVICE_LOCAL_MEM_SIZE failed." << std::endl;
336                return 1;
337        }else{
338                std::cout << "CL_DEVICE_LOCAL_MEM_SIZE : \t\t" << totalLocalMemory << " bytes" << std::endl;
339        }
340
341        return 0;
342}
Note: See TracBrowser for help on using the repository browser.