clinfo.pp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. {$mode objfpc}
  2. uses
  3. ctypes, cl;
  4. const
  5. device_str_info : array[1..5] of record id : dword; name : pchar end =
  6. ((id: CL_DEVICE_NAME; name : 'CL_DEVICE_NAME'),
  7. (id: CL_DEVICE_VENDOR; name : 'CL_DEVICE_VENDOR'),
  8. (id: CL_DEVICE_VERSION; name : 'CL_DEVICE_VERSION'),
  9. (id: CL_DEVICE_PROFILE; name : 'CL_DEVICE_PROFILE'),
  10. (id: CL_DEVICE_EXTENSIONS; name : 'CL_DEVICE_EXTENSIONS'));
  11. var
  12. err : Integer; // error code returned from api calls
  13. platformids : pcl_platform_id;
  14. platforms : cl_uint;
  15. devices : cl_uint;
  16. deviceids : pcl_device_id;
  17. i,j,k : Integer;
  18. buf : array[0..99999] of char;
  19. bufwritten : csize_t;
  20. begin
  21. err:=clGetPlatformIDs(0,nil,@platforms);
  22. if (err <> CL_SUCCESS) then
  23. begin
  24. writeln('Error: Cannot get number of platforms!');
  25. Halt(1);
  26. end;
  27. getmem(platformids,platforms*sizeof(cl_platform_id));
  28. err:=clGetPlatformIDs(platforms,platformids,nil);
  29. if (err <> CL_SUCCESS) then
  30. begin
  31. writeln('Error: Cannot get platforms!');
  32. Halt(1);
  33. end;
  34. writeln(platforms,' platform(s) found');
  35. for i:=0 to platforms-1 do
  36. begin
  37. writeln('Platform info ',i);
  38. err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_PROFILE,sizeof(buf),@buf,bufwritten);
  39. writeln('PROFILE: ',buf);
  40. err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_VERSION,sizeof(buf),@buf,bufwritten);
  41. writeln('VERSION: ',buf);
  42. err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_NAME,sizeof(buf),@buf,bufwritten);
  43. writeln('NAME: ',buf);
  44. err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_VENDOR,sizeof(buf),@buf,bufwritten);
  45. writeln('VENDOR: ',buf);
  46. err:=clGetPlatformInfo(platformids[i],CL_PLATFORM_EXTENSIONS,sizeof(buf),@buf,bufwritten);
  47. writeln('EXTENSIONS: ',buf);
  48. err:=clGetDeviceIDs(platformids[i],CL_DEVICE_TYPE_ALL,0,nil,@devices);
  49. if (err <> CL_SUCCESS) then
  50. begin
  51. writeln('Error: Cannot get number of devices!');
  52. Halt(1);
  53. end;
  54. writeln(devices,' device(s) found');
  55. getmem(deviceids,devices*sizeof(cl_device_id));
  56. err:=clGetDeviceIDs(platformids[i],CL_DEVICE_TYPE_ALL,devices,deviceids,nil);
  57. for j:=0 to devices-1 do
  58. begin
  59. writeln('Device info ',j);
  60. for k:=low(device_str_info) to high(device_str_info) do
  61. begin
  62. err:=clGetDeviceInfo(deviceids[j],device_str_info[k].id,sizeof(buf),@buf,bufwritten);
  63. writeln(device_str_info[k].name,': ',buf);
  64. end;
  65. err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(buf),@buf,bufwritten);
  66. writeln('CL_DEVICE_MAX_COMPUTE_UNITS: ',pdword(@buf)^);
  67. err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_IMAGE3D_MAX_WIDTH,sizeof(buf),@buf,bufwritten);
  68. writeln('CL_DEVICE_IMAGE3D_MAX_WIDTH: ',pdword(@buf)^);
  69. err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_IMAGE3D_MAX_HEIGHT,sizeof(buf),@buf,bufwritten);
  70. writeln('CL_DEVICE_IMAGE3D_MAX_HEIGHT: ',pdword(@buf)^);
  71. err:=clGetDeviceInfo(deviceids[j],CL_DEVICE_GLOBAL_MEM_SIZE,sizeof(buf),@buf,bufwritten);
  72. writeln('CL_DEVICE_GLOBAL_MEM_SIZE: ',pdword(@buf)^);
  73. end;
  74. end;
  75. freemem(platformids);
  76. end.