You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

nvOpticalFlowCommon.h 28 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /*
  2. * Copyright(c) 2020, NVIDIA CORPORATION.All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met :
  6. *
  7. * 1. Redistributions of source code must retain the above copyright notice, this
  8. * list of conditions and the following disclaimer.
  9. *
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and / or other materials provided with the distribution.
  13. *
  14. * 3. Neither the name of the copyright holder nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /**
  30. * \file nvOpticalFlowCommon.h
  31. * NVIDIA GPUs - Turing and above contains a hardware-based optical flow engine
  32. * which provides fully-accelerated hardware-based optical flow and stereo estimation.
  33. * nvOpticalFlowCommon.h provides enums, structure definitions and function prototypes which are common across different devices,
  34. * nvOpticalFlowCommon.h uses #pragma directives to pack structure members with one byte alignment.
  35. * \date 2018
  36. * nvOpticalFlowCommon.h provides common enums, structure definitions and function prototypes.
  37. */
  38. /**
  39. * \file src/opr/impl/nvof/nvOpticalFlowCommon.h
  40. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  41. *
  42. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  43. *
  44. * Unless required by applicable law or agreed to in writing,
  45. * software distributed under the License is distributed on an
  46. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
  47. * implied.
  48. */
  49. #include "megbrain_build_config.h"
  50. #if MGB_CUDA
  51. #ifndef _NV_OPTICALFLOW_COMMON_H_
  52. #define _NV_OPTICALFLOW_COMMON_H_
  53. #if defined(_MSC_VER_) && (_MSC_VER_ < 1600)
  54. #ifndef _STDINT
  55. typedef __int32 int32_t;
  56. typedef unsigned __int32 uint32_t;
  57. typedef __int64 int64_t;
  58. typedef unsigned __int64 uint64_t;
  59. typedef signed char int8_t;
  60. typedef unsigned char uint8_t;
  61. typedef short int16_t;
  62. typedef unsigned short uint16_t;
  63. #endif
  64. #else
  65. #include <stdint.h>
  66. #endif
  67. #ifdef _WIN32
  68. #define NVOFAPI __stdcall
  69. #else
  70. #define NVOFAPI
  71. #endif
  72. #define NV_OF_API_MAJOR_VERSION 2
  73. #define NV_OF_API_MINOR_VERSION 0
  74. #define NV_OF_API_VERSION (uint16_t)((NV_OF_API_MAJOR_VERSION << 4) | NV_OF_API_MINOR_VERSION)
  75. #define MIN_ERROR_STRING_SIZE 80
  76. #if defined(__cplusplus)
  77. extern "C"
  78. {
  79. #endif /* __cplusplus */
  80. typedef struct NvOFHandle_st *NvOFHandle;
  81. typedef struct NvOFGPUBufferHandle_st *NvOFGPUBufferHandle;
  82. typedef struct NVOFPrivDataHandle_st *NvOFPrivDataHandle;
  83. /**
  84. * Supported error codes
  85. */
  86. typedef enum _NV_OF_STATUS
  87. {
  88. /**
  89. * This indicates that API call returned with no errors.
  90. */
  91. NV_OF_SUCCESS,
  92. /**
  93. * This indicates that HW Optical flow functionality is not supported
  94. */
  95. NV_OF_ERR_OF_NOT_AVAILABLE,
  96. /**
  97. * This indicates that device passed by the client is not supported.
  98. */
  99. NV_OF_ERR_UNSUPPORTED_DEVICE,
  100. /**
  101. * This indicates that device passed to the API call is no longer available and
  102. * needs to be reinitialized.
  103. */
  104. NV_OF_ERR_DEVICE_DOES_NOT_EXIST,
  105. /**
  106. * This indicates that one or more of the pointers passed to the API call
  107. * is invalid.
  108. */
  109. NV_OF_ERR_INVALID_PTR,
  110. /**
  111. * This indicates that one or more of the parameter passed to the API call
  112. * is invalid.
  113. */
  114. NV_OF_ERR_INVALID_PARAM,
  115. /**
  116. * This indicates that an API call was made in wrong sequence/order.
  117. */
  118. NV_OF_ERR_INVALID_CALL,
  119. /**
  120. * This indicates that an invalid struct version was used by the client.
  121. */
  122. NV_OF_ERR_INVALID_VERSION,
  123. /**
  124. * This indicates that the API call failed because it was unable to allocate
  125. * enough memory to perform the requested operation.
  126. */
  127. NV_OF_ERR_OUT_OF_MEMORY,
  128. /**
  129. * This indicates that the OF session has not been initialized with
  130. * ::NvOFInit() or that initialization has failed.
  131. */
  132. NV_OF_ERR_NOT_INITIALIZED,
  133. /**
  134. * This indicates that an unsupported parameter was passed by the client.
  135. */
  136. NV_OF_ERR_UNSUPPORTED_FEATURE,
  137. /**
  138. * This indicates that an unknown internal error has occurred.
  139. */
  140. NV_OF_ERR_GENERIC,
  141. } NV_OF_STATUS;
  142. /**
  143. * Supported bool values
  144. */
  145. typedef enum _NV_OF_BOOL
  146. {
  147. NV_OF_FALSE = 0, /* < Represents false bool value */
  148. NV_OF_TRUE = !NV_OF_FALSE /* < Represents true bool value */
  149. } NV_OF_BOOL;
  150. /**
  151. * Supported optical flow and stereo disparity capability values.
  152. */
  153. typedef enum _NV_OF_CAPS
  154. {
  155. NV_OF_CAPS_SUPPORTED_OUTPUT_GRID_SIZES, /**< Indicates supported values of ::NV_OF_OUTPUT_VECTOR_GRID_SIZE,
  156. ::NV_OF_INIT_PARAMS::outGridSize should be set with a supported output gridsize. */
  157. NV_OF_CAPS_SUPPORTED_HINT_GRID_SIZES, /**< Indicates supported values of ::NV_OF_HINT_VECTOR_GRID_SIZE,
  158. ::NV_OF_INIT_PARAMS::hintGridSize should be set with a supported hint gridsize. */
  159. NV_OF_CAPS_SUPPORT_HINT_WITH_OF_MODE, /**< Indicates external hint support for ::NV_OF_MODE_OPTICALFLOW mode.
  160. 0: External hint not supported for ::NV_OF_MODE_OPTICALFLOW mode.
  161. 1: External hint is supported for ::NV_OF_MODE_OPTICALFLOW mode. */
  162. NV_OF_CAPS_SUPPORT_HINT_WITH_ST_MODE, /**< Indicates external hint support for ::NV_OF_MODE_STEREODISPARITY mode.
  163. 0: External hint not supported for ::NV_OF_MODE_STEREODISPARITY mode.
  164. 1: External hint is supported for ::NV_OF_MODE_STEREODISPARITY mode. */
  165. NV_OF_CAPS_WIDTH_MIN, /**< Minimum input width supported. */
  166. NV_OF_CAPS_HEIGHT_MIN, /**< Minimum input height supported. */
  167. NV_OF_CAPS_WIDTH_MAX, /**< Maximum input width supported. */
  168. NV_OF_CAPS_HEIGHT_MAX, /**< Maximum input height supported. */
  169. NV_OF_CAPS_SUPPORT_ROI, /**< Indicates ROI support.
  170. 0: ROIs cannot be specified.
  171. 1: One or more ROIs can be specified. */
  172. NV_OF_CAPS_SUPPORT_ROI_MAX_NUM, /**< Indicates maximum number of ROIs supported. */
  173. NV_OF_CAPS_SUPPORT_MAX
  174. } NV_OF_CAPS;
  175. /**
  176. * Supported optical flow/stereo disparity performance levels.
  177. */
  178. typedef enum _NV_OF_PERF_LEVEL
  179. {
  180. NV_OF_PERF_LEVEL_UNDEFINED,
  181. NV_OF_PERF_LEVEL_SLOW = 5, /**< Slow perf level results in lowest performance and best quality */
  182. NV_OF_PERF_LEVEL_MEDIUM = 10, /**< Medium perf level results in low performance and medium quality */
  183. NV_OF_PERF_LEVEL_FAST = 20, /**< Fast perf level results in high performance and low quality */
  184. NV_OF_PERF_LEVEL_MAX
  185. } NV_OF_PERF_LEVEL;
  186. /**
  187. * Supported grid size for output buffer ::NV_OF_EXECUTE_PARAMS::outputBuffer.
  188. * Client should set ::NV_OF_INIT_PARAMS::outGridSize with ::NV_OF_OUTPUT_VECTOR_GRID_SIZE values.
  189. */
  190. typedef enum _NV_OF_OUTPUT_VECTOR_GRID_SIZE
  191. {
  192. NV_OF_OUTPUT_VECTOR_GRID_SIZE_UNDEFINED,
  193. NV_OF_OUTPUT_VECTOR_GRID_SIZE_1 = 1, /**< Output buffer grid size is 1x1 */
  194. NV_OF_OUTPUT_VECTOR_GRID_SIZE_2 = 2, /**< Output buffer grid size is 2x2 */
  195. NV_OF_OUTPUT_VECTOR_GRID_SIZE_4 = 4, /**< Output buffer grid size is 4x4 */
  196. NV_OF_OUTPUT_VECTOR_GRID_SIZE_MAX
  197. } NV_OF_OUTPUT_VECTOR_GRID_SIZE;
  198. /**
  199. * Expected grid size for optional paramater ::NV_OF_EXECUTE_PARAMS::externalHints buffer.
  200. * Client should set ::NV_OF_INIT_PARAMS::hintGridSize with ::NV_OF_HINT_VECTOR_GRID_SIZE values.
  201. */
  202. typedef enum _NV_OF_HINT_VECTOR_GRID_SIZE
  203. {
  204. NV_OF_HINT_VECTOR_GRID_SIZE_UNDEFINED,
  205. NV_OF_HINT_VECTOR_GRID_SIZE_1 = 1, /**< Hint buffer grid size is 1x1.*/
  206. NV_OF_HINT_VECTOR_GRID_SIZE_2 = 2, /**< Hint buffer grid size is 2x2.*/
  207. NV_OF_HINT_VECTOR_GRID_SIZE_4 = 4, /**< Hint buffer grid size is 4x4.*/
  208. NV_OF_HINT_VECTOR_GRID_SIZE_8 = 8, /**< Hint buffer grid size is 8x8.*/
  209. NV_OF_HINT_VECTOR_GRID_SIZE_MAX
  210. } NV_OF_HINT_VECTOR_GRID_SIZE;
  211. /**
  212. * ::NV_OF_MODE enum define values for Optical flow and Stereo disparity modes.
  213. * Client need to set ::NV_OF_INIT_PARAMS::mode with ::NV_OF_MODE values.
  214. * For the ::NV_OF_MODE_OPTICALFLOW mode, the buffer format for ::NV_OF_EXECUTE_PARAMS::externalHints
  215. * and ::NV_OF_EXECUTE_PARAMS::outputBuffer is ::NV_OF_FLOW_VECTOR.
  216. * For the ::NV_OF_MODE_STEREODISPARITY mode, the buffer format for ::NV_OF_EXECUTE_PARAMS::externalHints
  217. * and ::NV_OF_EXECUTE_PARAMS::outputBuffer is ::NV_OF_STEREO_DISPARITY.
  218. */
  219. typedef enum _NV_OF_MODE
  220. {
  221. NV_OF_MODE_UNDEFINED,
  222. NV_OF_MODE_OPTICALFLOW, /**< Calculate optical flow between two frames. */
  223. NV_OF_MODE_STEREODISPARITY, /**< Calculate disparity between Stereo view pair. */
  224. NV_OF_MODE_MAX
  225. } NV_OF_MODE;
  226. /**
  227. * Supported buffer type for ::NvOFGPUBufferHandle allocation.
  228. * Client need to set NV_OF_CREATE_BUFFER::bufferUsage with ::NV_OF_BUFFER_USAGE enum values.
  229. */
  230. typedef enum _NV_OF_BUFFER_USAGE
  231. {
  232. NV_OF_BUFFER_USAGE_UNDEFINED,
  233. NV_OF_BUFFER_USAGE_INPUT, /**< Input buffer type is used to allocate ::NV_OF_INPUT_EXECUTE_PARAMS::inputFrame,
  234. ::NV_OF_INPUT_EXECUTE_PARAMS::referenceFrame. */
  235. NV_OF_BUFFER_USAGE_OUTPUT, /**< Output buffer type is used to allocate ::NV_OF_OUTPUT_EXECUTE_PARAMS::outputBuffer. */
  236. NV_OF_BUFFER_USAGE_HINT, /**< Hint buffer type is used to allocate ::NV_OF_INPUT_EXECUTE_PARAMS::externalHints.*/
  237. NV_OF_BUFFER_USAGE_COST, /**< Cost buffer type is used to allocate ::NV_OF_OUTPUT_EXECUTE_PARAMS::outputCostBuffer.*/
  238. NV_OF_BUFFER_USAGE_MAX
  239. } NV_OF_BUFFER_USAGE;
  240. /**
  241. * Supported buffer formats
  242. */
  243. typedef enum _NV_OF_BUFFER_FORMAT
  244. {
  245. NV_OF_BUFFER_FORMAT_UNDEFINED,
  246. NV_OF_BUFFER_FORMAT_GRAYSCALE8, /**< Input buffer format with 8 bit planar format */
  247. NV_OF_BUFFER_FORMAT_NV12, /**< Input buffer format with 8 bit plannar, UV interleaved */
  248. NV_OF_BUFFER_FORMAT_ABGR8, /**< Input buffer format with 8 bit packed A8B8G8R8 */
  249. NV_OF_BUFFER_FORMAT_SHORT, /**< Output or hint buffer format for stereo disparity */
  250. NV_OF_BUFFER_FORMAT_SHORT2, /**< Output or hint buffer format for optical flow vector */
  251. NV_OF_BUFFER_FORMAT_UINT, /**< Legacy 32-bit Cost buffer format for optical flow vector / stereo disparity.
  252. This cost buffer format is not performance efficient and results in additional GPU usage.
  253. Hence users are strongly recommended to use the 8-bit cost buffer format.
  254. Legacy 32-bit cost buffer format is also planned to be deprecated in future. */
  255. NV_OF_BUFFER_FORMAT_UINT8, /**< 8-bit Cost buffer format for optical flow vector / stereo disparity. */
  256. NV_OF_BUFFER_FORMAT_MAX
  257. } NV_OF_BUFFER_FORMAT;
  258. /**
  259. * Supported stereo disparity range. Avaialble for GPUs later than Turing
  260. */
  261. typedef enum _NV_OF_STEREO_DISPARITY_RANGE
  262. {
  263. NV_OF_STEREO_DISPARITY_RANGE_UNDEFINED,
  264. NV_OF_STEREO_DISPARITY_RANGE_128 = 128,
  265. NV_OF_STEREO_DISPARITY_RANGE_256 = 256,
  266. NV_OF_STEREO_DISPARITY_RANGE_MAX,
  267. } NV_OF_STEREO_DISPARITY_RANGE;
  268. /**
  269. * \struct NV_OF_FLOW_VECTOR
  270. * Struct needed for optical flow. ::NV_OF_EXECUTE_OUTPUT_PARAMS::outputBuffer will be populated with optical flow
  271. * in ::NV_OF_FLOW_VECTOR format for each ::NV_OF_INIT_PARAMS::outGridSize.
  272. * Flow vectors flowx and flowy are 16-bit values with the lowest 5 bits holding fractional value,
  273. * followed by a 10-bit integer value and the most significant bit being a sign bit.
  274. */
  275. typedef struct _NV_OF_FLOW_VECTOR
  276. {
  277. int16_t flowx; /**< x component of flow in S10.5 format */
  278. int16_t flowy; /**< y component of flow in S10.5 format */
  279. } NV_OF_FLOW_VECTOR;
  280. /**
  281. * \struct NV_OF_STEREO_DISPARITY
  282. * Struct needed for stereo /disparity. ::NV_OF_OUTPUT_EXECUTE_PARAMS::outputBuffer will be populated
  283. * with stereo disparity in ::NV_OF_STEREO_DISPARITY format for each ::NV_OF_INIT_PARAMS::outGridSize.
  284. * Stereo disparity is a 16-bit value with the lowest 5 bits holding fractional value,
  285. * followed by a 11-bit unsigned integer value.
  286. */
  287. typedef struct _NV_OF_STEREO_DISPARITY
  288. {
  289. uint16_t disparity; /**< Horizontal displacement[in pixels] in 11.5 format. */
  290. } NV_OF_STEREO_DISPARITY;
  291. /**
  292. * \struct NV_OF_INIT_PARAMS
  293. * Optical flow/stereo disparity session initialization parameters.
  294. */
  295. typedef struct _NV_OF_INIT_PARAMS
  296. {
  297. uint32_t width; /**< [in]: Specifies input buffer width */
  298. uint32_t height; /**< [in]: Specifies input buffer height */
  299. NV_OF_OUTPUT_VECTOR_GRID_SIZE outGridSize; /**< [in]: Specifies flow vector grid size for ::NV_OF_EXECUTE_PARAMS::outputBuffer buffer.*/
  300. NV_OF_HINT_VECTOR_GRID_SIZE hintGridSize; /**< [in]: Specifies flow vector grid size for ::NV_OF_EXECUTE_PARAMS::externalHints buffer.
  301. This field is only considered if ::NV_OF_INIT_PARAMS::enableExternalHints is set.
  302. hintGridSize should be equal or greater than outGridSize. */
  303. NV_OF_MODE mode; /**< [in]: Operating mode for NVOF. Set to a value defined by enum ::NV_OF_MODE. */
  304. NV_OF_PERF_LEVEL perfLevel; /**< [in]: Specifies perf level. */
  305. NV_OF_BOOL enableExternalHints; /**< [in]: Set to 1 to enable external hints for optical flow session. */
  306. NV_OF_BOOL enableOutputCost; /**< [in]: Set to 1 to enable output cost calculation for optical flow session. */
  307. NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data. It is reserved field and should be set to NULL. */
  308. NV_OF_STEREO_DISPARITY_RANGE disparityRange; /**< [in]: Speicifies maximum disparity range.
  309. Set to NV_OF_STEREO_DISPARITY_RANGE_UNDEFINED for Turing GPUs. */
  310. NV_OF_BOOL enableRoi; /**< [in]: Set to 1 to enable estimation of optical flow/stereo for roi. */
  311. } NV_OF_INIT_PARAMS;
  312. /**
  313. * \struct NV_OF_BUFFER_DESCRIPTOR
  314. * Creation parameters for optical flow buffers.
  315. */
  316. typedef struct _NV_OF_BUFFER_DESCRIPTOR
  317. {
  318. uint32_t width; /**< [in]: Buffer width. */
  319. uint32_t height; /**< [in]: Buffer height. */
  320. NV_OF_BUFFER_USAGE bufferUsage; /**< [in]: To specify buffer usage type.
  321. ::NV_OF_BUFFER_USAGE_OUTPUT buffer usage type accepts ::NV_OF_CREATE_BUFFER::width,
  322. ::NV_OF_BUFFER_DESCRIPTOR::height in ::NV_OF_INIT_PARAMS::outGridSize units.
  323. ::NV_OF_BUFFER_USAGE_HINT buffer usage type accepts ::NV_OF_BUFFER_DESCRIPTOR::width,
  324. ::NV_OF_BUFFER_DESCRIPTOR::height in ::NV_OF_INIT_PARAMS::hintGridSize units. */
  325. NV_OF_BUFFER_FORMAT bufferFormat; /**< [in]: Buffer format. */
  326. } NV_OF_BUFFER_DESCRIPTOR;
  327. /**
  328. * \struct NV_OF_ROI_RECT
  329. * Specifies the co-ordinates of the Region Of Interest (ROI)
  330. * ROI rects should satisfy below requirements:
  331. * 1. NV_OF_ROI_RECT::start_x should align to (32 * NV_OF_INIT_PARAMS::outGridSize)
  332. * 2. NV_OF_ROI_RECT::width should align to (32 * NV_OF_INIT_PARAMS::outGridSize)
  333. * 3. NV_OF_ROI_RECT::start_y should align to (8 * max(NV_OF_INIT_PARAMS::outGridSize, 2))
  334. * 4. NV_OF_ROI_RECT::height should align to (8 * NV_OF_INIT_PARAMS::outGridSize)
  335. * 5. NV_OF_ROI_RECT::width >= 32 && NV_OF_ROI_RECT::height >= 16; maximum size 8192x8192
  336. * 6. Whole ROI region should be inside of the image
  337. * Optical flow/stereo disparity vectors out side of ROI are invalid and should not be used.
  338. */
  339. struct NV_OF_ROI_RECT
  340. {
  341. uint32_t start_x; /**< [in]: ROI start position in x-direction. */
  342. uint32_t start_y; /**< [in]: ROI start position in y-direction. */
  343. uint32_t width; /**< [in]: Width of ROI. */
  344. uint32_t height; /**< [in]: Height of ROI. */
  345. };
  346. /**
  347. * \struct NV_OF_EXECUTE_INPUT_PARAMS
  348. * Parameters which are sent per frame for optical flow/stereo disparity execution.
  349. */
  350. typedef struct _NV_OF_EXECUTE_INPUT_PARAMS
  351. {
  352. NvOFGPUBufferHandle inputFrame; /**< [in]: If ::NV_OF_INIT_PARAMS::mode is ::NV_OF_MODE_OPTICALFLOW, this specifies the handle to the buffer containing the input frame.
  353. If ::NV_OF_INIT_PARAMS::mode is ::NV_OF_MODE_STEREODISPARITY, this specifies the handle to the buffer containing the rectified left view. */
  354. NvOFGPUBufferHandle referenceFrame; /**< [in]: If ::NV_OF_INIT_PARAMS::mode is ::NV_OF_MODE_OPTICALFLOW, this specifies the handle to the buffer containing the reference frame.
  355. If ::NV_OF_INIT_PARAMS::mode is ::NV_OF_MODE_STEREODISPARITY, this specifies the handle to the buffer containing the rectified right view. */
  356. NvOFGPUBufferHandle externalHints; /**< [in]: It is an optional input, This field will be considered if client had set ::NV_OF_INIT_PARAMS::enableExternalHint flag.
  357. Client can pass some available predictors as hints.
  358. Optical flow driver will search around those hints to optimize flow vectors quality.
  359. Expected hint buffer format is ::NV_OF_FLOW_VECTOR, ::NV_OF_STEREO_DISPARITY
  360. for ::NV_OF_MODE_OPTICALFLOW, ::NV_OF_MODE_STEREODISPARITY modes respectively for
  361. each ::NV_OF_INIT_PARAMS::hintGridSize in a frame. */
  362. NV_OF_BOOL disableTemporalHints; /**< [in]: Temporal hints yield better accuracy flow vectors when running on successive frames of a continuous video (without major scene changes).
  363. When disableTemporalHints = 0, optical flow vectors from previous NvOFExecute call are automatically used as hints for the current NvOFExecute call.
  364. However, when running optical flow on pairs of images which are completely independent of each other, temporal hints are useless
  365. and in fact, they will degrade the quality. Therefore, it is recommended to set disableTemporalHints = 1 in this case.*/
  366. uint32_t padding; /**< [in]: Padding. Must be set to 0. */
  367. NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data handle. It is reserved field and should be set to NULL. */
  368. uint32_t padding2; /**< [in]: Padding. Must be set to 0. */
  369. uint32_t numRois; /**< [in]: Number of ROIs. */
  370. NV_OF_ROI_RECT* roiData; /**< [in]: Pointer to the NV_OF_ROI_RECTs data. Size of this buffer should be atleast numROIs * sizeof(NV_OF_ROI_RECT). */
  371. } NV_OF_EXECUTE_INPUT_PARAMS;
  372. /**
  373. * \struct NV_OF_EXECUTE_OUTPUT_PARAMS
  374. * Parameters which are received per frame for optical flow/stereo disparity execution.
  375. */
  376. typedef struct _NV_OF_EXECUTE_OUTPUT_PARAMS
  377. {
  378. NvOFGPUBufferHandle outputBuffer; /**< [in]: Specifies the pointer to optical flow or stereo disparity buffer handle.
  379. ::outputBuffer will be populated with optical flow in
  380. ::NV_OF_FLOW_VECTOR format or stereo disparity in
  381. ::NV_OF_STEREO_DISPARITY format for each
  382. ::NV_OF_VECTOR_GRID_SIZE::outGridSize in a frame.*/
  383. NvOFGPUBufferHandle outputCostBuffer; /**< [in]: Specifies the pointer to output cost calculation buffer handle. */
  384. NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data handle. It is reserved field and should be set to NULL. */
  385. } NV_OF_EXECUTE_OUTPUT_PARAMS;
  386. /**
  387. * \brief Initialize NVIDIA Video Optical Flow Interface and validates input params.
  388. *
  389. * Initializes NVIDIA Video Optical Flow Interface and validates input params.
  390. * It also initializes NVIDIA Video Optical Flow driver with the init value passed in ::NV_OF_INIT_PARAMS
  391. * structure.
  392. *
  393. * \param [in] hOf
  394. * Object of ::NvOFHandle type.
  395. * \param [in] initParams
  396. * Pointer to the ::NV_OF_INIT_PARAMS structure.
  397. *
  398. * \return
  399. * ::NV_OF_SUCCESS \n
  400. * ::NV_OF_ERR_INVALID_PTR \n
  401. * ::NV_OF_ERR_UNSUPPORTED_DEVICE \n
  402. * ::NV_OF_ERR_DEVICE_DOES_NOT_EXIST \n
  403. * ::NV_OF_ERR_UNSUPPORTED_PARAM \n
  404. * ::NV_OF_ERR_OUT_OF_MEMORY \n
  405. * ::NV_OF_ERR_INVALID_PARAM \n
  406. * ::NV_OF_ERR_INVALID_VERSION \n
  407. * ::NV_OF_ERR_OF_NOT_INITIALIZED \n
  408. * ::NV_OF_ERR_GENERIC \n
  409. */
  410. typedef NV_OF_STATUS(NVOFAPI* PFNNVOFINIT) (NvOFHandle hOf, const NV_OF_INIT_PARAMS *initParams);
  411. /**
  412. * \brief Kick off computation of optical flow between input and reference frame.
  413. *
  414. * This is asynchronous function call which kicks off computation of optical flow or stereo disparity
  415. * between ::NV_OF_EXECUTE_INPUT_PARAMS::inputFrame and ::NV_OF_EXECUTE_INPUT_PARAMS::referenceFrame and returns
  416. * after submitting execute paramaters to optical flow engine.
  417. * ::NV_OF_EXECUTE_OUTPUT_PARAMS::outputBuffer will be populated with optical flow or stereo disparity
  418. * based on ::NV_OF_INIT_PARAMS:mode is NV_OF_MODE_OPTICALFLOW or NV_OF_MODE_STEREODISPARITY respectively.
  419. *
  420. * \param [in] hOf
  421. * Object of ::NvOFHandle type.
  422. * \param [in] executeInParams
  423. * pointer to the ::NV_OF_EXECUTE_INPUT_PARAMS structure.
  424. * \param [out] executeOutParams
  425. * pointer to the ::NV_OF_EXECUTE_OUTPUT_PARAMS structure.
  426. *
  427. * \return
  428. * ::NV_OF_SUCCESS \n
  429. * ::NV_OF_ERR_INVALID_PTR \n
  430. * ::NV_OF_ERR_INVALID_DEVICE \n
  431. * ::NV_OF_ERR_DEVICE_DOES_NOT_EXIST \n
  432. * ::NV_OF_ERR_UNSUPPORTED_PARAM \n
  433. * ::NV_OF_ERR_OUT_OF_MEMORY \n
  434. * ::NV_OF_ERR_INVALID_PARAM \n
  435. * ::NV_OF_ERR_INVALID_VERSION \n
  436. * ::NV_OF_ERR_OF_NOT_INITIALIZED \n
  437. * ::NV_OF_ERR_GENERIC \n
  438. */
  439. typedef NV_OF_STATUS(NVOFAPI* PFNNVOFEXECUTE) (NvOFHandle hOf, const NV_OF_EXECUTE_INPUT_PARAMS *executeInParams, NV_OF_EXECUTE_OUTPUT_PARAMS *executeOutParams);
  440. /**
  441. * \brief Release optical flow API and driver resources.
  442. *
  443. * Releases resources and waits until all resources are gracefully released.
  444. *
  445. * \param [in] hOf
  446. * Object of ::NvOFHandle type.
  447. *
  448. * \return
  449. * ::NV_OF_SUCCESS \n
  450. * ::NV_OF_ERR_INVALID_PTR \n
  451. * ::NV_OF_ERR_DEVICE_DOES_NOT_EXIST \n
  452. * ::NV_OF_ERR_OF_NOT_INITIALIZED \n
  453. * ::NV_OF_ERR_GENERIC \n
  454. */
  455. typedef NV_OF_STATUS(NVOFAPI* PFNNVOFDESTROY) (NvOFHandle hOf);
  456. /**
  457. * \brief Populate error buffer with the description of last failure.
  458. *
  459. * Populates lastError[] with the description of last failure.
  460. *
  461. * \param [in] hOf
  462. * Object of ::NvOFHandle type.
  463. * \param [in/out] lastError
  464. * lastError is a char array, minimum expected size of lastError[] is MIN_ERROR_STRING_SIZE characters.
  465. * After execution of this function call, lastError[] is populated with error string.
  466. * \param [in/out] As an input parameter, "size" indicates the size of the array provided by the client.
  467. * After execution of this function call, "size" field indicates the number of characters written into
  468. * "lastError" excluding null character.
  469. * \return
  470. * ::NV_OF_SUCCESS \n
  471. * ::NV_OF_ERR_INVALID_PTR \n
  472. * ::NV_OF_ERR_DEVICE_DOES_NOT_EXIST \n
  473. * ::NV_OF_ERR_OF_NOT_INITIALIZED \n
  474. * ::NV_OF_ERR_GENERIC \n
  475. */
  476. typedef NV_OF_STATUS(NVOFAPI* PFNNVOFGETLASTERROR) (NvOFHandle hOf, char lastError[], uint32_t *size);
  477. /**
  478. * \brief Populate capability array for specified ::NV_OF_CAPS value.
  479. * This is to be called in two stages.
  480. * It returns the number of capability values for specified ::NV_OF_CAPS value when
  481. * queried with "capsVal" set to NULL.
  482. * It populates capsVal array with capability values for specified ::NV_OF_CAPS value
  483. * when queried with "capsVal" set to non-NULL value.
  484. *
  485. * \param [in] hOf
  486. * Object of ::NvOFHandle type.
  487. * \param [in] capsParam
  488. * object of ::NV_OF_CAPS type.
  489. * \param [out] capsVal
  490. * Pointer to uint32_t, minimum expected size of capsVal is the "size" returned by the this function call
  491. * queried with "capsVal" set to NULL.
  492. * \param [out] size
  493. * Pointer to uint32_t, which stores size of populated capsVal.
  494. *
  495. * \return
  496. * ::NV_OF_SUCCESS \n
  497. * ::NV_OF_ERR_INVALID_PTR \n
  498. * ::NV_OF_ERR_DEVICE_DOES_NOT_EXIST \n
  499. * ::NV_OF_ERR_OF_NOT_INITIALIZED \n
  500. * ::NV_OF_ERR_GENERIC \n
  501. */
  502. typedef NV_OF_STATUS(NVOFAPI* PFNNVOFGETCAPS) (NvOFHandle hOf, NV_OF_CAPS capsParam, uint32_t *capsVal, uint32_t *size);
  503. /**
  504. * \brief Get the largest API version supported by the driver.
  505. *
  506. * This function can be used by clients to determine if the driver supports
  507. * the API header the application was compiled with.
  508. *
  509. * \param [out] version
  510. * Pointer to the requested value. The 4 least significant bits in the returned
  511. * indicate the minor version and the rest of the bits indicate the major
  512. * version of the largest supported version.
  513. *
  514. * \return
  515. * ::NV_OF_SUCCESS \n
  516. * ::NV_OF_ERR_INVALID_PTR \n
  517. */
  518. NV_OF_STATUS NVOFAPI NvOFGetMaxSupportedApiVersion(uint32_t* version);
  519. #if defined(__cplusplus)
  520. }
  521. #endif /* __cplusplus */
  522. #endif
  523. #endif

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台