File: test_clGetDeviceInfo.c

package info (click to toggle)
pocl 0.13-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,452 kB
  • ctags: 13,529
  • sloc: lisp: 113,221; cpp: 57,376; ansic: 25,021; sh: 6,150; makefile: 2,067; python: 699; pascal: 98; java: 72; xml: 49
file content (56 lines) | stat: -rw-r--r-- 1,499 bytes parent folder | download | duplicates (2)
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
#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>

#define MAX_PLATFORMS 32
#define MAX_DEVICES   32

int
main(void)
{
  cl_int err;
  cl_platform_id platforms[MAX_PLATFORMS];
  cl_uint nplatforms;
  cl_device_id devices[MAX_DEVICES];
  cl_uint ndevices;
  cl_uint i, j;

  err = clGetPlatformIDs(MAX_PLATFORMS, platforms, &nplatforms);	
  if (err != CL_SUCCESS)
    return EXIT_FAILURE;

  for (i = 0; i < nplatforms; i++)
  {
    err = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, MAX_DEVICES,
                         devices, &ndevices);
    if (err != CL_SUCCESS)
      return EXIT_FAILURE;

    for (j = 0; j < ndevices; j++)
    {
      cl_long global_memsize, max_mem_alloc_size, min_max_mem_alloc_size;

      err = clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE,
                            sizeof(global_memsize), &global_memsize, NULL);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;

      err = clGetDeviceInfo(devices[j], CL_DEVICE_MAX_MEM_ALLOC_SIZE,
                            sizeof(max_mem_alloc_size), &max_mem_alloc_size,
                            NULL);
      if (err != CL_SUCCESS)
        return EXIT_FAILURE;

      if (global_memsize == 0)
        return EXIT_FAILURE;

      min_max_mem_alloc_size = 128*1024*1024;
      if (min_max_mem_alloc_size < global_memsize/4)
        min_max_mem_alloc_size = global_memsize/4;

      if (max_mem_alloc_size < min_max_mem_alloc_size)
        return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}