CUDA.Utility.pas 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // The graphics engine GLScene
  3. //
  4. unit CUDA.Utility;
  5. (* CUDA Utility Wraper of cutil. Note: *)
  6. interface
  7. uses
  8. {$IFDEF MSWINDOWS}
  9. Winapi.Windows;
  10. {$ELSE}
  11. Windows; // or for LINUX
  12. {$ENDIF}
  13. const
  14. {$IFDEF WIN64}
  15. CUTILDLL = 'cutil64.dll';
  16. {$ELSE}
  17. CUTILDLL = 'cutil32.dll';
  18. {$ENDIF}
  19. var
  20. cutFindFilePath: function(const filename: PAnsiChar; const executablePath: PAnsiChar): PAnsiChar;stdcall;
  21. cutLoadPGMf: function(const filename: PAnsiChar; var data: System.PSingle; var w: Integer; var h: Integer): Boolean;stdcall;
  22. cutSavePGMf: function(const filename: PAnsiChar; data: System.PSingle; w: Integer; h: Integer): Boolean;stdcall;
  23. cutLoadPGMub: function(const filename: PAnsiChar; var data: PByte; var w: Integer; var h: Integer): Boolean;stdcall;
  24. cutLoadPPMub: function(const filename: PAnsiChar; var data: PByte; var w: Integer; var h: Integer): Boolean;stdcall;
  25. cutLoadPPM4ub: function(const filename: PAnsiChar; var data: PByte; var w: Integer; var h: Integer): Boolean;stdcall;
  26. cutLoadPGMi: function(const filename: PAnsiChar; var data: PInteger; var w: Integer; var h: Integer): Boolean;stdcall;
  27. cutLoadPGMs: function(const filename: PAnsiChar; var data: PWord; var w: Integer; var h: Integer): Boolean;stdcall;
  28. cutSavePGMub: function(const filename: PAnsiChar; data: PByte; w: Integer; h: Integer): Boolean;stdcall;
  29. cutSavePPMub: function(const filename: PAnsiChar; data: PByte; w: Integer; h: Integer): Boolean;stdcall;
  30. cutSavePPM4ub: function(const filename: PAnsiChar; data: PByte; w: Integer; h: Integer): Boolean;stdcall;
  31. cutSavePGMi: function(const filename: PAnsiChar; data: PInteger; w: Integer; h: Integer): Boolean;stdcall;
  32. cutSavePGMs: function(const filename: PAnsiChar; data: PWord; w: Integer; h: Integer): Boolean;stdcall;
  33. cutComparef: function(const reference: PSingle; const data: PSingle; const len: Cardinal): Boolean;stdcall;
  34. cutComparei: function(const reference: PInteger; const data: PInteger; const len: Cardinal): Boolean;stdcall;
  35. cutCompareuit: function(const reference: PInteger; const data: PInteger; const len: Cardinal; const epsilon: Single;
  36. const threshold: Single): Boolean;stdcall;
  37. cutCompareub: function(const reference: PByte; const data: PByte; const len: Cardinal): Boolean;stdcall;
  38. cutCompareubt: function(const reference: PByte; const data: PByte; const len: Cardinal; const epsilon: Single;
  39. const threshold: Single): Boolean;stdcall;
  40. cutCompareube: function(const reference: PByte; const data: PByte; const len: Cardinal; const epsilon: Single): Boolean;stdcall;
  41. cutComparefe: function(const reference: PSingle; const data: PSingle; const len: Cardinal; const epsilon: Single): Boolean;stdcall;
  42. cutComparefet: function(const reference: PSingle; const data: PSingle; const len: Cardinal; const epsilon: Single;
  43. const threshold: Single): Boolean;stdcall;
  44. cutCompareL2fe: function(const reference: PSingle; const data: PSingle; const len: Cardinal; const epsilon: Single): Boolean;stdcall;
  45. cutCreateTimer: function(var name: Cardinal): Boolean;stdcall;
  46. cutStartTimer: function(const name: Cardinal): Boolean;stdcall;
  47. cutStopTimer: function(const name: Cardinal): Boolean;stdcall;
  48. cutResetTimer: function(const name: Cardinal): Boolean;stdcall;
  49. cutDeleteTimer: function(const name: Cardinal): Boolean;stdcall;
  50. cutGetTimerValue: function(const name: Cardinal): Single;stdcall;
  51. cutGetAverageTimerValue: function(const name: Cardinal): Single;stdcall;
  52. cutFree: procedure(ptr: Pointer);stdcall;
  53. function InitCUTIL: Boolean;
  54. procedure CloseCUTIL;
  55. function InitCUTILFromLibrary(const LibName: WideString): Boolean;
  56. function IsCUTILInitialized: Boolean;
  57. implementation // -------------------------------------------------------------
  58. const
  59. INVALID_MODULEHANDLE = 0;
  60. {$IFDEF MSWINDOWS}
  61. var
  62. CUTILHandle: HINST = INVALID_MODULEHANDLE;
  63. {$ELSE}
  64. // ************** UNIX specific ********************
  65. var
  66. CUTILHandle: TLibHandle = INVALID_MODULEHANDLE;
  67. {$ENDIF}
  68. function CUTILGetProcAddress(ProcName: PAnsiChar): Pointer;
  69. begin
  70. result := GetProcAddress(Cardinal(CUTILHandle), ProcName);
  71. end;
  72. function InitCUTIL: Boolean;
  73. begin
  74. if CUTILHandle = INVALID_MODULEHANDLE then
  75. result := InitCUTILFromLibrary(CUTILDLL)
  76. else
  77. result := True;
  78. end;
  79. procedure CloseCUTIL;
  80. begin
  81. if CUTILHandle <> INVALID_MODULEHANDLE then
  82. begin
  83. FreeLibrary(Cardinal(CUTILHandle));
  84. CUTILHandle := INVALID_MODULEHANDLE;
  85. end;
  86. end;
  87. function InitCUTILFromLibrary(const LibName: WideString): Boolean;
  88. begin
  89. result := False;
  90. CloseCUTIL;
  91. CUTILHandle := LoadLibraryW(PWideChar(LibName));
  92. if CUTILHandle = INVALID_MODULEHANDLE then
  93. Exit;
  94. cutFindFilePath := CUTILGetProcAddress('cutFindFilePath');
  95. cutLoadPGMf := CUTILGetProcAddress('cutLoadPGMf');
  96. cutSavePGMf := CUTILGetProcAddress('cutSavePGMf');
  97. cutLoadPGMub := CUTILGetProcAddress('cutLoadPGMub');
  98. cutLoadPPMub := CUTILGetProcAddress('cutLoadPPMub');
  99. cutLoadPPM4ub := CUTILGetProcAddress('cutLoadPPM4ub');
  100. cutLoadPGMi := CUTILGetProcAddress('cutLoadPGMi');
  101. cutLoadPGMs := CUTILGetProcAddress('cutLoadPGMs');
  102. cutSavePGMub := CUTILGetProcAddress('cutSavePGMub');
  103. cutSavePPMub := CUTILGetProcAddress('cutSavePPMub');
  104. cutSavePPM4ub := CUTILGetProcAddress('cutSavePPM4ub');
  105. cutSavePGMi := CUTILGetProcAddress('cutSavePGMi');
  106. cutSavePGMs := CUTILGetProcAddress('cutSavePGMs');
  107. cutComparef := CUTILGetProcAddress('cutComparef');
  108. cutComparei := CUTILGetProcAddress('cutComparei');
  109. cutCompareuit := CUTILGetProcAddress('cutCompareuit');
  110. cutCompareub := CUTILGetProcAddress('cutCompareub');
  111. cutCompareubt := CUTILGetProcAddress('cutCompareubt');
  112. cutCompareube := CUTILGetProcAddress('cutCompareube');
  113. cutComparefe := CUTILGetProcAddress('cutComparefe');
  114. cutComparefet := CUTILGetProcAddress('cutComparefet');
  115. cutCompareL2fe := CUTILGetProcAddress('cutCompareL2fe');
  116. cutCreateTimer := CUTILGetProcAddress('cutCreateTimer');
  117. cutStartTimer := CUTILGetProcAddress('cutStartTimer');
  118. cutStopTimer := CUTILGetProcAddress('cutStopTimer');
  119. cutResetTimer := CUTILGetProcAddress('cutResetTimer');
  120. cutDeleteTimer := CUTILGetProcAddress('cutDeleteTimer');
  121. cutGetTimerValue := CUTILGetProcAddress('cutGetTimerValue');
  122. cutGetAverageTimerValue := CUTILGetProcAddress('cutGetAverageTimerValue');
  123. cutFree := CUTILGetProcAddress('cutFree');
  124. result := True;
  125. end;
  126. function IsCUTILInitialized: Boolean;
  127. begin
  128. result := (CUTILHandle <> INVALID_MODULEHANDLE);
  129. end;
  130. //-----------------------------------------------
  131. initialization
  132. //-----------------------------------------------
  133. finalization
  134. CloseCUTIL;
  135. end.