CUDA.Utility.pas 6.5 KB

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