GLS.CUDAUtility.pas 8.0 KB

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