summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/opencl/examples/clinfo.pp
blob: 1b40b83fcd83080b907f18c5b612167f9612e0e6 (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
77
78
79
80
81
82
83
{$mode objfpc}
uses
  cl;

const
  device_str_info : array[1..5] of record id : dword; name : pchar end =
   ((id: CL_DEVICE_NAME; name : 'CL_DEVICE_NAME'),
    (id: CL_DEVICE_VENDOR; name : 'CL_DEVICE_VENDOR'),
    (id: CL_DEVICE_VERSION; name : 'CL_DEVICE_VERSION'),
    (id: CL_DEVICE_PROFILE; name : 'CL_DEVICE_PROFILE'),
    (id: CL_DEVICE_EXTENSIONS; name : 'CL_DEVICE_EXTENSIONS'));



var
  err     : Integer; // error code returned from api calls
  platformids : pcl_platform_id;
  platforms : cl_uint;
  devices : cl_uint;
  deviceids : pcl_device_id;
  i,j,k : Integer;
  buf : array[0..99999] of char;
  bufwritten : LongWord;


begin
  err:=clGetPlatformIDs(0,nil,@platforms);
  if (err <> CL_SUCCESS) then
    begin
      writeln('Error: Cannot get number of platforms!');
      Halt(1);
    end;
  getmem(platformids,platforms*sizeof(cl_platform_id));
  err:=clGetPlatformIDs(platforms,platformids,nil);
  if (err <> CL_SUCCESS) then
    begin
      writeln('Error: Cannot get platforms!');
      Halt(1);
    end;
  writeln(platforms,' platform(s) found');
  for i:=0 to platforms-1 do
    begin
      writeln('Platform info ',i);
      err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_PROFILE,sizeof(buf),@buf,bufwritten);
      writeln('PROFILE: ',buf);
      err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_VERSION,sizeof(buf),@buf,bufwritten);
      writeln('VERSION: ',buf);
      err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_NAME,sizeof(buf),@buf,bufwritten);
      writeln('NAME: ',buf);
      err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_VENDOR,sizeof(buf),@buf,bufwritten);
      writeln('VENDOR: ',buf);
      err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_EXTENSIONS,sizeof(buf),@buf,bufwritten);
      writeln('EXTENSIONS: ',buf);

      err:=clGetDeviceIDs(platformids[i],CL_DEVICE_TYPE_ALL,0,nil,@devices);
      if (err <> CL_SUCCESS) then
        begin
          writeln('Error: Cannot get number of devices!');
          Halt(1);
        end;
      writeln(devices,' device(s) found');
      getmem(deviceids,devices*sizeof(cl_device_id));
      err:=clGetDeviceIDs(platformids[i],CL_DEVICE_TYPE_ALL,devices,deviceids,nil);
      for j:=0 to devices-1 do
        begin
          writeln('Device info ',j);
          for k:=low(device_str_info) to high(device_str_info) do
            begin
              err:=clGetDeviceInfo(deviceids[j],device_str_info[k].id,sizeof(buf),@buf,bufwritten);
              writeln(device_str_info[k].name,': ',buf);
            end;
          err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(buf),@buf,bufwritten);
          writeln('CL_DEVICE_MAX_COMPUTE_UNITS: ',pdword(@buf)^);
          err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_IMAGE3D_MAX_WIDTH,sizeof(buf),@buf,bufwritten);
          writeln('CL_DEVICE_IMAGE3D_MAX_WIDTH: ',pdword(@buf)^);
          err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_IMAGE3D_MAX_HEIGHT,sizeof(buf),@buf,bufwritten);
          writeln('CL_DEVICE_IMAGE3D_MAX_HEIGHT: ',pdword(@buf)^);
          err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_GLOBAL_MEM_SIZE,sizeof(buf),@buf,bufwritten);
          writeln('CL_DEVICE_GLOBAL_MEM_SIZE: ',pdword(@buf)^);
        end;
    end;
  freemem(platformids);
end.