提交 e3fc7836 编写于 作者: M Megvii Engine Team

fix(mgb/opr): fix nvof shape error

fix(mgb/opr): fix format error

fix(mgb/opr): update nvof opr to 1.3 fix (compared to 2.0)

fix(mgb/opr): add try catch to solve test error

GitOrigin-RevId: b688745b36fce509aac857a9b2682a7ba17ddccf
上级 3f3a256e
...@@ -125,7 +125,7 @@ def correlation( ...@@ -125,7 +125,7 @@ def correlation(
:param stride1: (int (non-negative), optional, default=1) – stride1 quantize data1 globally :param stride1: (int (non-negative), optional, default=1) – stride1 quantize data1 globally
:param stride2: (int (non-negative), optional, default=1) – stride2 quantize data2 within the neighborhood centered around data1 :param stride2: (int (non-negative), optional, default=1) – stride2 quantize data2 within the neighborhood centered around data1
:param pad_size: (int (non-negative), optional, default=0) – pad for Correlation :param pad_size: (int (non-negative), optional, default=0) – pad for Correlation
:param is_multiply: (boolean, optional, default=True) – operation type is either multiplication or absolute difference :param is_multiply: (boolean, optional, default=True) – operation type is either multiplication or absolute difference
""" """
......
...@@ -128,9 +128,32 @@ void NvOFCuda::DoExecute(const NV_OF_EXECUTE_INPUT_PARAMS& executeInParams, ...@@ -128,9 +128,32 @@ void NvOFCuda::DoExecute(const NV_OF_EXECUTE_INPUT_PARAMS& executeInParams,
NVOF_API_CALL(m_NvOFAPI->GetAPI()->nvOFExecute(m_NvOFAPI->GetHandle(), &executeInParams, &executeOutParams)); NVOF_API_CALL(m_NvOFAPI->GetAPI()->nvOFExecute(m_NvOFAPI->GetHandle(), &executeInParams, &executeOutParams));
} }
void NvOFCuda::DoInit(const NV_OF_INIT_PARAMS& initParams) void NvOFCuda::DoInit(const NV_OF_INIT_PARAMS& initParams) {
{ uint32_t minWidth = _QuerySupportCaps(NV_OF_CAPS_WIDTH_MIN);
NVOF_API_CALL(m_NvOFAPI->GetAPI()->nvOFInit(m_NvOFAPI->GetHandle(), &initParams)); uint32_t maxWidth = _QuerySupportCaps(NV_OF_CAPS_WIDTH_MAX);
uint32_t minHeight = _QuerySupportCaps(NV_OF_CAPS_HEIGHT_MIN);
uint32_t maxHeight = _QuerySupportCaps(NV_OF_CAPS_HEIGHT_MAX);
if (!(initParams.width <= maxWidth && initParams.width >= minWidth &&
initParams.height <= maxHeight && initParams.height >= minHeight)) {
mgb_throw(
MegBrainError,
"the input height must between [%d,%d] and width must between "
"[%d,%d]. your (h,w) is (%d,%d)\n",
minHeight, maxHeight, minWidth, maxWidth, initParams.height,
initParams.width);
}
NVOF_API_CALL(
m_NvOFAPI->GetAPI()->nvOFInit(m_NvOFAPI->GetHandle(), &initParams));
}
uint32_t NvOFCuda::_QuerySupportCaps(const NV_OF_CAPS& cap) {
uint32_t size = 0;
NVOF_API_CALL(m_NvOFAPI->GetAPI()->nvOFGetCaps(m_NvOFAPI->GetHandle(), cap,
nullptr, &size));
std::unique_ptr<uint32_t[]> capsVal(new uint32_t[size]);
NVOF_API_CALL(m_NvOFAPI->GetAPI()->nvOFGetCaps(m_NvOFAPI->GetHandle(), cap,
capsVal.get(), &size));
return capsVal[0];
} }
NV_OF_CUDA_BUFFER_TYPE NvOFCuda::GetBufferType(NV_OF_BUFFER_USAGE usage) NV_OF_CUDA_BUFFER_TYPE NvOFCuda::GetBufferType(NV_OF_BUFFER_USAGE usage)
...@@ -140,7 +163,7 @@ NV_OF_CUDA_BUFFER_TYPE NvOFCuda::GetBufferType(NV_OF_BUFFER_USAGE usage) ...@@ -140,7 +163,7 @@ NV_OF_CUDA_BUFFER_TYPE NvOFCuda::GetBufferType(NV_OF_BUFFER_USAGE usage)
{ {
bufferType = m_eInBufType; bufferType = m_eInBufType;
} }
else if ((usage == NV_OF_BUFFER_USAGE_OUTPUT) || else if ((usage == NV_OF_BUFFER_USAGE_OUTPUT) ||
(usage == NV_OF_BUFFER_USAGE_COST) || (usage == NV_OF_BUFFER_USAGE_COST) ||
(usage == NV_OF_BUFFER_USAGE_HINT)) (usage == NV_OF_BUFFER_USAGE_HINT))
{ {
......
...@@ -89,7 +89,7 @@ private: ...@@ -89,7 +89,7 @@ private:
uint32_t nHeight, uint32_t nHeight,
NV_OF_BUFFER_FORMAT eInBufFmt, NV_OF_BUFFER_FORMAT eInBufFmt,
NV_OF_CUDA_BUFFER_TYPE eInBufType, NV_OF_CUDA_BUFFER_TYPE eInBufType,
NV_OF_CUDA_BUFFER_TYPE eOutBufType, NV_OF_CUDA_BUFFER_TYPE eOutBufType,
NV_OF_MODE eMode, NV_OF_MODE eMode,
NV_OF_PERF_LEVEL preset, NV_OF_PERF_LEVEL preset,
CUstream inputStream = nullptr, CUstream inputStream = nullptr,
...@@ -113,7 +113,7 @@ private: ...@@ -113,7 +113,7 @@ private:
virtual void DoExecute(const NV_OF_EXECUTE_INPUT_PARAMS& executeInParams, NV_OF_EXECUTE_OUTPUT_PARAMS& executeOutParams) override; virtual void DoExecute(const NV_OF_EXECUTE_INPUT_PARAMS& executeInParams, NV_OF_EXECUTE_OUTPUT_PARAMS& executeOutParams) override;
/** /**
* @brief This function is used to allocate buffers used for optical flow estimation * @brief This function is used to allocate buffers used for optical flow estimation
* using the cuda interface. This function is an override of pure virtual function * using the cuda interface. This function is an override of pure virtual function
* NvOF::DoAllocBuffers(). * NvOF::DoAllocBuffers().
*/ */
...@@ -132,6 +132,13 @@ private: ...@@ -132,6 +132,13 @@ private:
std::shared_ptr<NvOFCudaAPI> m_NvOFAPI; std::shared_ptr<NvOFCudaAPI> m_NvOFAPI;
NV_OF_CUDA_BUFFER_TYPE m_eInBufType; NV_OF_CUDA_BUFFER_TYPE m_eInBufType;
NV_OF_CUDA_BUFFER_TYPE m_eOutBufType; NV_OF_CUDA_BUFFER_TYPE m_eOutBufType;
/**
* @brief This function is used to query support params that is used for
* optical flow estimation using the cuda interface. This function can only
* be called within the private class
*/
uint32_t _QuerySupportCaps(const NV_OF_CAPS& cap);
}; };
/* /*
......
/* /*
* This copyright notice applies to this header file only: * Copyright(c) 2020, NVIDIA CORPORATION.All rights reserved.
* *
* Copyright (c) 2018 NVIDIA Corporation * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met :
* *
* Permission is hereby granted, free of charge, to any person * 1. Redistributions of source code must retain the above copyright notice, this
* obtaining a copy of this software and associated documentation * list of conditions and the following disclaimer.
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the software, and to permit persons to whom the
* software is furnished to do so, subject to the following
* conditions:
* *
* The above copyright notice and this permission notice shall be * 2. Redistributions in binary form must reproduce the above copyright notice,
* included in all copies or substantial portions of the Software. * this list of conditions and the following disclaimer in the documentation
* and / or other materials provided with the distribution.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * 3. Neither the name of the copyright holder nor the names of its
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * contributors may be used to endorse or promote products derived from
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * this software without specific prior written permission.
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* OTHER DEALINGS IN THE SOFTWARE. * DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
* \file nvOpticalFlowCommon.h * \file nvOpticalFlowCommon.h
* NVIDIA GPUs - Turing and above contains a hardware-based optical flow engine * NVIDIA GPUs - Turing and above contains a hardware-based optical flow engine
...@@ -34,6 +37,7 @@ ...@@ -34,6 +37,7 @@
* nvOpticalFlowCommon.h provides common enums, structure definitions and function prototypes. * nvOpticalFlowCommon.h provides common enums, structure definitions and function prototypes.
*/ */
/** /**
* \file src/opr/impl/nvof/nvOpticalFlowCommon.h * \file src/opr/impl/nvof/nvOpticalFlowCommon.h
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License") * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
...@@ -46,9 +50,11 @@ ...@@ -46,9 +50,11 @@
* implied. * implied.
*/ */
#include "megbrain_build_config.h" #include "megbrain_build_config.h"
#if MGB_CUDA #if MGB_CUDA
#ifndef _NV_OPTICALFLOW_COMMON_H_ #ifndef _NV_OPTICALFLOW_COMMON_H_
#define _NV_OPTICALFLOW_COMMON_H_ #define _NV_OPTICALFLOW_COMMON_H_
#if defined(_MSC_VER_) && (_MSC_VER_ < 1600) #if defined(_MSC_VER_) && (_MSC_VER_ < 1600)
...@@ -71,13 +77,13 @@ typedef unsigned short uint16_t; ...@@ -71,13 +77,13 @@ typedef unsigned short uint16_t;
#else #else
#define NVOFAPI #define NVOFAPI
#endif #endif
#define NV_OF_API_MAJOR_VERSION 1 #define NV_OF_API_MAJOR_VERSION 2
#define NV_OF_API_MINOR_VERSION 1 #define NV_OF_API_MINOR_VERSION 0
#define NV_OF_API_VERSION (uint16_t)((NV_OF_API_MAJOR_VERSION << 4) | NV_OF_API_MINOR_VERSION) #define NV_OF_API_VERSION (uint16_t)((NV_OF_API_MAJOR_VERSION << 4) | NV_OF_API_MINOR_VERSION)
#define MIN_ERROR_STRING_SIZE 80 #define MIN_ERROR_STRING_SIZE 80
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" extern "C"
{ {
#endif /* __cplusplus */ #endif /* __cplusplus */
...@@ -170,16 +176,25 @@ typedef enum _NV_OF_BOOL ...@@ -170,16 +176,25 @@ typedef enum _NV_OF_BOOL
*/ */
typedef enum _NV_OF_CAPS typedef enum _NV_OF_CAPS
{ {
NV_OF_CAPS_SUPPORTED_OUTPUT_GRID_SIZES, /**< Indicates supported values of ::NV_OF_OUTPUT_VECTOR_GRID_SIZE, NV_OF_CAPS_SUPPORTED_OUTPUT_GRID_SIZES, /**< Indicates supported values of ::NV_OF_OUTPUT_VECTOR_GRID_SIZE,
::NV_OF_INIT_PARAMS::outGridSize should be set with a supported output gridsize. */ ::NV_OF_INIT_PARAMS::outGridSize should be set with a supported output gridsize. */
NV_OF_CAPS_SUPPORTED_HINT_GRID_SIZES, /**< Indicates supported values of ::NV_OF_HINT_VECTOR_GRID_SIZE, NV_OF_CAPS_SUPPORTED_HINT_GRID_SIZES, /**< Indicates supported values of ::NV_OF_HINT_VECTOR_GRID_SIZE,
::NV_OF_INIT_PARAMS::hintGridSize should be set with a supported hint gridsize. */ ::NV_OF_INIT_PARAMS::hintGridSize should be set with a supported hint gridsize. */
NV_OF_CAPS_SUPPORT_HINT_WITH_OF_MODE, /**< Indicates external hint support for ::NV_OF_MODE_OPTICALFLOW mode. NV_OF_CAPS_SUPPORT_HINT_WITH_OF_MODE, /**< Indicates external hint support for ::NV_OF_MODE_OPTICALFLOW mode.
0: External hint not supported for ::NV_OF_MODE_OPTICALFLOW mode. 0: External hint not supported for ::NV_OF_MODE_OPTICALFLOW mode.
1: External hint is supported for ::NV_OF_MODE_OPTICALFLOW mode. */ 1: External hint is supported for ::NV_OF_MODE_OPTICALFLOW mode. */
NV_OF_CAPS_SUPPORT_HINT_WITH_ST_MODE /**< Indicates external hint support for ::NV_OF_MODE_STEREODISPARITY mode. NV_OF_CAPS_SUPPORT_HINT_WITH_ST_MODE, /**< Indicates external hint support for ::NV_OF_MODE_STEREODISPARITY mode.
0: External hint not supported for ::NV_OF_MODE_STEREODISPARITY mode. 0: External hint not supported for ::NV_OF_MODE_STEREODISPARITY mode.
1: External hint is supported for ::NV_OF_MODE_STEREODISPARITY mode. */ 1: External hint is supported for ::NV_OF_MODE_STEREODISPARITY mode. */
NV_OF_CAPS_WIDTH_MIN, /**< Minimum input width supported. */
NV_OF_CAPS_HEIGHT_MIN, /**< Minimum input height supported. */
NV_OF_CAPS_WIDTH_MAX, /**< Maximum input width supported. */
NV_OF_CAPS_HEIGHT_MAX, /**< Maximum input height supported. */
NV_OF_CAPS_SUPPORT_ROI, /**< Indicates ROI support.
0: ROIs cannot be specified.
1: One or more ROIs can be specified. */
NV_OF_CAPS_SUPPORT_ROI_MAX_NUM, /**< Indicates maximum number of ROIs supported. */
NV_OF_CAPS_SUPPORT_MAX
} NV_OF_CAPS; } NV_OF_CAPS;
/** /**
...@@ -201,6 +216,8 @@ typedef enum _NV_OF_PERF_LEVEL ...@@ -201,6 +216,8 @@ typedef enum _NV_OF_PERF_LEVEL
typedef enum _NV_OF_OUTPUT_VECTOR_GRID_SIZE typedef enum _NV_OF_OUTPUT_VECTOR_GRID_SIZE
{ {
NV_OF_OUTPUT_VECTOR_GRID_SIZE_UNDEFINED, NV_OF_OUTPUT_VECTOR_GRID_SIZE_UNDEFINED,
NV_OF_OUTPUT_VECTOR_GRID_SIZE_1 = 1, /**< Output buffer grid size is 1x1 */
NV_OF_OUTPUT_VECTOR_GRID_SIZE_2 = 2, /**< Output buffer grid size is 2x2 */
NV_OF_OUTPUT_VECTOR_GRID_SIZE_4 = 4, /**< Output buffer grid size is 4x4 */ NV_OF_OUTPUT_VECTOR_GRID_SIZE_4 = 4, /**< Output buffer grid size is 4x4 */
NV_OF_OUTPUT_VECTOR_GRID_SIZE_MAX NV_OF_OUTPUT_VECTOR_GRID_SIZE_MAX
} NV_OF_OUTPUT_VECTOR_GRID_SIZE; } NV_OF_OUTPUT_VECTOR_GRID_SIZE;
...@@ -212,6 +229,8 @@ typedef enum _NV_OF_OUTPUT_VECTOR_GRID_SIZE ...@@ -212,6 +229,8 @@ typedef enum _NV_OF_OUTPUT_VECTOR_GRID_SIZE
typedef enum _NV_OF_HINT_VECTOR_GRID_SIZE typedef enum _NV_OF_HINT_VECTOR_GRID_SIZE
{ {
NV_OF_HINT_VECTOR_GRID_SIZE_UNDEFINED, NV_OF_HINT_VECTOR_GRID_SIZE_UNDEFINED,
NV_OF_HINT_VECTOR_GRID_SIZE_1 = 1, /**< Hint buffer grid size is 1x1.*/
NV_OF_HINT_VECTOR_GRID_SIZE_2 = 2, /**< Hint buffer grid size is 2x2.*/
NV_OF_HINT_VECTOR_GRID_SIZE_4 = 4, /**< Hint buffer grid size is 4x4.*/ NV_OF_HINT_VECTOR_GRID_SIZE_4 = 4, /**< Hint buffer grid size is 4x4.*/
NV_OF_HINT_VECTOR_GRID_SIZE_8 = 8, /**< Hint buffer grid size is 8x8.*/ NV_OF_HINT_VECTOR_GRID_SIZE_8 = 8, /**< Hint buffer grid size is 8x8.*/
NV_OF_HINT_VECTOR_GRID_SIZE_MAX NV_OF_HINT_VECTOR_GRID_SIZE_MAX
...@@ -259,10 +278,25 @@ typedef enum _NV_OF_BUFFER_FORMAT ...@@ -259,10 +278,25 @@ typedef enum _NV_OF_BUFFER_FORMAT
NV_OF_BUFFER_FORMAT_ABGR8, /**< Input buffer format with 8 bit packed A8B8G8R8 */ NV_OF_BUFFER_FORMAT_ABGR8, /**< Input buffer format with 8 bit packed A8B8G8R8 */
NV_OF_BUFFER_FORMAT_SHORT, /**< Output or hint buffer format for stereo disparity */ NV_OF_BUFFER_FORMAT_SHORT, /**< Output or hint buffer format for stereo disparity */
NV_OF_BUFFER_FORMAT_SHORT2, /**< Output or hint buffer format for optical flow vector */ NV_OF_BUFFER_FORMAT_SHORT2, /**< Output or hint buffer format for optical flow vector */
NV_OF_BUFFER_FORMAT_UINT, /**< Cost buffer format for optical flow vector / stereo disparity */ NV_OF_BUFFER_FORMAT_UINT, /**< Legacy 32-bit Cost buffer format for optical flow vector / stereo disparity.
This cost buffer format is not performance efficient and results in additional GPU usage.
Hence users are strongly recommended to use the 8-bit cost buffer format.
Legacy 32-bit cost buffer format is also planned to be deprecated in future. */
NV_OF_BUFFER_FORMAT_UINT8, /**< 8-bit Cost buffer format for optical flow vector / stereo disparity. */
NV_OF_BUFFER_FORMAT_MAX NV_OF_BUFFER_FORMAT_MAX
} NV_OF_BUFFER_FORMAT; } NV_OF_BUFFER_FORMAT;
/**
* Supported stereo disparity range. Avaialble for GPUs later than Turing
*/
typedef enum _NV_OF_STEREO_DISPARITY_RANGE
{
NV_OF_STEREO_DISPARITY_RANGE_UNDEFINED,
NV_OF_STEREO_DISPARITY_RANGE_128 = 128,
NV_OF_STEREO_DISPARITY_RANGE_256 = 256,
NV_OF_STEREO_DISPARITY_RANGE_MAX,
} NV_OF_STEREO_DISPARITY_RANGE;
/** /**
* \struct NV_OF_FLOW_VECTOR * \struct NV_OF_FLOW_VECTOR
* Struct needed for optical flow. ::NV_OF_EXECUTE_OUTPUT_PARAMS::outputBuffer will be populated with optical flow * Struct needed for optical flow. ::NV_OF_EXECUTE_OUTPUT_PARAMS::outputBuffer will be populated with optical flow
...@@ -298,12 +332,16 @@ typedef struct _NV_OF_INIT_PARAMS ...@@ -298,12 +332,16 @@ typedef struct _NV_OF_INIT_PARAMS
uint32_t height; /**< [in]: Specifies input buffer height */ uint32_t height; /**< [in]: Specifies input buffer height */
NV_OF_OUTPUT_VECTOR_GRID_SIZE outGridSize; /**< [in]: Specifies flow vector grid size for ::NV_OF_EXECUTE_PARAMS::outputBuffer buffer.*/ NV_OF_OUTPUT_VECTOR_GRID_SIZE outGridSize; /**< [in]: Specifies flow vector grid size for ::NV_OF_EXECUTE_PARAMS::outputBuffer buffer.*/
NV_OF_HINT_VECTOR_GRID_SIZE hintGridSize; /**< [in]: Specifies flow vector grid size for ::NV_OF_EXECUTE_PARAMS::externalHints buffer. NV_OF_HINT_VECTOR_GRID_SIZE hintGridSize; /**< [in]: Specifies flow vector grid size for ::NV_OF_EXECUTE_PARAMS::externalHints buffer.
This field is only considered if ::NV_OF_INIT_PARAMS::enableExternalHints is set */ This field is only considered if ::NV_OF_INIT_PARAMS::enableExternalHints is set.
hintGridSize should be equal or greater than outGridSize. */
NV_OF_MODE mode; /**< [in]: Operating mode for NVOF. Set to a value defined by enum ::NV_OF_MODE. */ NV_OF_MODE mode; /**< [in]: Operating mode for NVOF. Set to a value defined by enum ::NV_OF_MODE. */
NV_OF_PERF_LEVEL perfLevel; /**< [in]: Specifies perf level. */ NV_OF_PERF_LEVEL perfLevel; /**< [in]: Specifies perf level. */
NV_OF_BOOL enableExternalHints; /**< [in]: Set to 1 to enable external hints for optical flow session. */ NV_OF_BOOL enableExternalHints; /**< [in]: Set to 1 to enable external hints for optical flow session. */
NV_OF_BOOL enableOutputCost; /**< [in]: Set to 1 to enable output cost calculation for optical flow session. */ NV_OF_BOOL enableOutputCost; /**< [in]: Set to 1 to enable output cost calculation for optical flow session. */
NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data. It is reserved field and should be set to NULL. */ NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data. It is reserved field and should be set to NULL. */
NV_OF_STEREO_DISPARITY_RANGE disparityRange; /**< [in]: Speicifies maximum disparity range.
Set to NV_OF_STEREO_DISPARITY_RANGE_UNDEFINED for Turing GPUs. */
NV_OF_BOOL enableRoi; /**< [in]: Set to 1 to enable estimation of optical flow/stereo for roi. */
} NV_OF_INIT_PARAMS; } NV_OF_INIT_PARAMS;
/** /**
...@@ -323,6 +361,26 @@ typedef struct _NV_OF_BUFFER_DESCRIPTOR ...@@ -323,6 +361,26 @@ typedef struct _NV_OF_BUFFER_DESCRIPTOR
} NV_OF_BUFFER_DESCRIPTOR; } NV_OF_BUFFER_DESCRIPTOR;
/**
* \struct NV_OF_ROI_RECT
* Specifies the co-ordinates of the Region Of Interest (ROI)
* ROI rects should satisfy below requirements:
* 1. NV_OF_ROI_RECT::start_x should align to (32 * NV_OF_INIT_PARAMS::outGridSize)
* 2. NV_OF_ROI_RECT::width should align to (32 * NV_OF_INIT_PARAMS::outGridSize)
* 3. NV_OF_ROI_RECT::start_y should align to (8 * max(NV_OF_INIT_PARAMS::outGridSize, 2))
* 4. NV_OF_ROI_RECT::height should align to (8 * NV_OF_INIT_PARAMS::outGridSize)
* 5. NV_OF_ROI_RECT::width >= 32 && NV_OF_ROI_RECT::height >= 16; maximum size 8192x8192
* 6. Whole ROI region should be inside of the image
* Optical flow/stereo disparity vectors out side of ROI are invalid and should not be used.
*/
struct NV_OF_ROI_RECT
{
uint32_t start_x; /**< [in]: ROI start position in x-direction. */
uint32_t start_y; /**< [in]: ROI start position in y-direction. */
uint32_t width; /**< [in]: Width of ROI. */
uint32_t height; /**< [in]: Height of ROI. */
};
/** /**
* \struct NV_OF_EXECUTE_INPUT_PARAMS * \struct NV_OF_EXECUTE_INPUT_PARAMS
* Parameters which are sent per frame for optical flow/stereo disparity execution. * Parameters which are sent per frame for optical flow/stereo disparity execution.
...@@ -334,17 +392,20 @@ typedef struct _NV_OF_EXECUTE_INPUT_PARAMS ...@@ -334,17 +392,20 @@ typedef struct _NV_OF_EXECUTE_INPUT_PARAMS
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. 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.
If ::NV_OF_INIT_PARAMS::mode is ::NV_OF_MODE_STEREODISPARITY, this specifies the handle to the buffer containing the rectified right view. */ If ::NV_OF_INIT_PARAMS::mode is ::NV_OF_MODE_STEREODISPARITY, this specifies the handle to the buffer containing the rectified right view. */
NvOFGPUBufferHandle externalHints; /**< [in]: It is an optional input, This field will be considered if client had set ::NV_OF_INIT_PARAMS::enableExternalHint flag. NvOFGPUBufferHandle externalHints; /**< [in]: It is an optional input, This field will be considered if client had set ::NV_OF_INIT_PARAMS::enableExternalHint flag.
Client can pass some available predictors as hints. Client can pass some available predictors as hints.
Optical flow driver will search around those hints to optimize flow vectors quality. Optical flow driver will search around those hints to optimize flow vectors quality.
Expected hint buffer format is ::NV_OF_FLOW_VECTOR, ::NV_OF_STEREO_DISPARITY Expected hint buffer format is ::NV_OF_FLOW_VECTOR, ::NV_OF_STEREO_DISPARITY
for ::NV_OF_MODE_OPTICALFLOW, ::NV_OF_MODE_STEREODISPARITY modes respectively for for ::NV_OF_MODE_OPTICALFLOW, ::NV_OF_MODE_STEREODISPARITY modes respectively for
each ::NV_OF_INIT_PARAMS::hintGridSize in a frame. */ each ::NV_OF_INIT_PARAMS::hintGridSize in a frame. */
NV_OF_BOOL disableTemporalHints; /**< [in]: To disable temporal hints per optical flow/stereo disparity execution. 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).
Temporal Hints is set by default. When disableTemporalHints = 0, optical flow vectors from previous NvOFExecute call are automatically used as hints for the current NvOFExecute call.
User can choose to disable temporal hints if there is no However, when running optical flow on pairs of images which are completely independent of each other, temporal hints are useless
dependancy on previous optical flow execution. */ and in fact, they will degrade the quality. Therefore, it is recommended to set disableTemporalHints = 1 in this case.*/
uint32_t padding; /**< [in]: Padding. Must be set to 0. */ uint32_t padding; /**< [in]: Padding. Must be set to 0. */
NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data handle. It is reserved field and should be set to NULL. */ NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data handle. It is reserved field and should be set to NULL. */
uint32_t padding2; /**< [in]: Padding. Must be set to 0. */
uint32_t numRois; /**< [in]: Number of ROIs. */
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). */
} NV_OF_EXECUTE_INPUT_PARAMS; } NV_OF_EXECUTE_INPUT_PARAMS;
/** /**
...@@ -355,8 +416,8 @@ typedef struct _NV_OF_EXECUTE_OUTPUT_PARAMS ...@@ -355,8 +416,8 @@ typedef struct _NV_OF_EXECUTE_OUTPUT_PARAMS
{ {
NvOFGPUBufferHandle outputBuffer; /**< [in]: Specifies the pointer to optical flow or stereo disparity buffer handle. NvOFGPUBufferHandle outputBuffer; /**< [in]: Specifies the pointer to optical flow or stereo disparity buffer handle.
::outputBuffer will be populated with optical flow in ::outputBuffer will be populated with optical flow in
::NV_OF_FLOW_VECTOR format or stereo disparity in ::NV_OF_FLOW_VECTOR format or stereo disparity in
::NV_OF_STEREO_DISPARITY format for each ::NV_OF_STEREO_DISPARITY format for each
::NV_OF_VECTOR_GRID_SIZE::outGridSize in a frame.*/ ::NV_OF_VECTOR_GRID_SIZE::outGridSize in a frame.*/
NvOFGPUBufferHandle outputCostBuffer; /**< [in]: Specifies the pointer to output cost calculation buffer handle. */ NvOFGPUBufferHandle outputCostBuffer; /**< [in]: Specifies the pointer to output cost calculation buffer handle. */
NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data handle. It is reserved field and should be set to NULL. */ NvOFPrivDataHandle hPrivData; /**< [in]: Optical flow private data handle. It is reserved field and should be set to NULL. */
...@@ -393,7 +454,7 @@ typedef NV_OF_STATUS(NVOFAPI* PFNNVOFINIT) (NvOFHandle hOf, const NV_OF_INIT_PAR ...@@ -393,7 +454,7 @@ typedef NV_OF_STATUS(NVOFAPI* PFNNVOFINIT) (NvOFHandle hOf, const NV_OF_INIT_PAR
* *
* This is asynchronous function call which kicks off computation of optical flow or stereo disparity * This is asynchronous function call which kicks off computation of optical flow or stereo disparity
* between ::NV_OF_EXECUTE_INPUT_PARAMS::inputFrame and ::NV_OF_EXECUTE_INPUT_PARAMS::referenceFrame and returns * between ::NV_OF_EXECUTE_INPUT_PARAMS::inputFrame and ::NV_OF_EXECUTE_INPUT_PARAMS::referenceFrame and returns
* after submitting execute paramaters to optical flow engine. * after submitting execute paramaters to optical flow engine.
* ::NV_OF_EXECUTE_OUTPUT_PARAMS::outputBuffer will be populated with optical flow or stereo disparity * ::NV_OF_EXECUTE_OUTPUT_PARAMS::outputBuffer will be populated with optical flow or stereo disparity
* based on ::NV_OF_INIT_PARAMS:mode is NV_OF_MODE_OPTICALFLOW or NV_OF_MODE_STEREODISPARITY respectively. * based on ::NV_OF_INIT_PARAMS:mode is NV_OF_MODE_OPTICALFLOW or NV_OF_MODE_STEREODISPARITY respectively.
* *
......
/* /*
* This copyright notice applies to this header file only: * Copyright(c) 2020, NVIDIA CORPORATION.All rights reserved.
* *
* Copyright (c) 2018 NVIDIA Corporation * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met :
* *
* Permission is hereby granted, free of charge, to any person * 1. Redistributions of source code must retain the above copyright notice, this
* obtaining a copy of this software and associated documentation * list of conditions and the following disclaimer.
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the software, and to permit persons to whom the
* software is furnished to do so, subject to the following
* conditions:
* *
* The above copyright notice and this permission notice shall be * 2. Redistributions in binary form must reproduce the above copyright notice,
* included in all copies or substantial portions of the Software. * this list of conditions and the following disclaimer in the documentation
* and / or other materials provided with the distribution.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * 3. Neither the name of the copyright holder nor the names of its
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * contributors may be used to endorse or promote products derived from
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * this software without specific prior written permission.
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* OTHER DEALINGS IN THE SOFTWARE. * DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/** /**
* \file NvOpticalFlowCuda.h * \file NvOpticalFlowCuda.h
* NVIDIA GPUs - Turing and above contains a hardware-based optical flow engine * NVIDIA GPUs - Turing and above contains a hardware-based optical flow engine
...@@ -48,6 +51,7 @@ ...@@ -48,6 +51,7 @@
#include "megbrain_build_config.h" #include "megbrain_build_config.h"
#if MGB_CUDA #if MGB_CUDA
#ifndef _NV_OPTICALFLOW_CUDA_H_ #ifndef _NV_OPTICALFLOW_CUDA_H_
#define _NV_OPTICALFLOW_CUDA_H_ #define _NV_OPTICALFLOW_CUDA_H_
#include "nvOpticalFlowCommon.h" #include "nvOpticalFlowCommon.h"
...@@ -56,7 +60,7 @@ ...@@ -56,7 +60,7 @@
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" extern "C"
{ {
#endif /* __cplusplus */ #endif /* __cplusplus */
...@@ -125,7 +129,7 @@ typedef NV_OF_STATUS(NVOFAPI* PFNNVCREATEOPTICALFLOWCUDA) (CUcontext device, NvO ...@@ -125,7 +129,7 @@ typedef NV_OF_STATUS(NVOFAPI* PFNNVCREATEOPTICALFLOWCUDA) (CUcontext device, NvO
* CUstream type object which is used to process ::NV_OF_EXECUTE_PARAMS::inputFrame, * CUstream type object which is used to process ::NV_OF_EXECUTE_PARAMS::inputFrame,
* ::NV_OF_EXECUTE_PARAMS::referenceFrame and optional NV_OF_EXECUTE_PARAMS::externalHints. * ::NV_OF_EXECUTE_PARAMS::referenceFrame and optional NV_OF_EXECUTE_PARAMS::externalHints.
* \param [in] outputStream * \param [in] outputStream
* CUstream type object which is used to process ::NV_OF_EXECUTE_PARAMS::outputBuffer and * CUstream type object which is used to process ::NV_OF_EXECUTE_PARAMS::outputBuffer and
* optional NV_OF_EXECUTE_PARAMS::costBuffer. * optional NV_OF_EXECUTE_PARAMS::costBuffer.
* *
* \return * \return
...@@ -171,7 +175,7 @@ typedef NV_OF_STATUS(NVOFAPI* PFNNVOFCREATEGPUBUFFERCUDA) (NvOFHandle hOf, const ...@@ -171,7 +175,7 @@ typedef NV_OF_STATUS(NVOFAPI* PFNNVOFCREATEGPUBUFFERCUDA) (NvOFHandle hOf, const
* \param [in] ofGpuBuffer * \param [in] ofGpuBuffer
* Object of type NvOFGPUBufferHandle, created by a call to NvOFCreateGPUBufferCuda() with bufferType set to ::NV_OF_CUDA_BUFFER_TYPE_CUARRAY. * Object of type NvOFGPUBufferHandle, created by a call to NvOFCreateGPUBufferCuda() with bufferType set to ::NV_OF_CUDA_BUFFER_TYPE_CUARRAY.
* *
* \return * \return
* Object of CUarray type. * Object of CUarray type.
* If ofGpubuffer corresponds to a GPU buffer that was not created with buffer type NV_OF_CUDA_BUFFER_TYPE_CUARRAY, * If ofGpubuffer corresponds to a GPU buffer that was not created with buffer type NV_OF_CUDA_BUFFER_TYPE_CUARRAY,
* this function returns NULL * this function returns NULL
...@@ -184,7 +188,7 @@ typedef CUarray(NVOFAPI* PFNNVOFGPUBUFFERGETCUARRAY) (NvOFGPUBufferHandle ofGpuB ...@@ -184,7 +188,7 @@ typedef CUarray(NVOFAPI* PFNNVOFGPUBUFFERGETCUARRAY) (NvOFGPUBufferHandle ofGpuB
* \param [in] ofGpuBuffer * \param [in] ofGpuBuffer
* Object of type NvOFGPUBufferHandle, created by a call to NvOFCreateGPUBufferCuda() with bufferType set to ::NV_OF_CUDA_BUFFER_TYPE_CUDEVICEPTR. * Object of type NvOFGPUBufferHandle, created by a call to NvOFCreateGPUBufferCuda() with bufferType set to ::NV_OF_CUDA_BUFFER_TYPE_CUDEVICEPTR.
* *
* \return * \return
* Object of the CUdeviceptr type. * Object of the CUdeviceptr type.
* If ofGpubuffer corresponds to a GPU buffer that was not created with buffer type NV_OF_CUDA_BUFFER_TYPE_CUDEVICEPTR, * If ofGpubuffer corresponds to a GPU buffer that was not created with buffer type NV_OF_CUDA_BUFFER_TYPE_CUDEVICEPTR,
* this function returns 0 * this function returns 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册