我正在尝试基于 NVIDIA GPU Computing SDK 4.2 中的 cudaDecodeD3D9 示例开发多流 H.264 视频播放器。
应用程序可以在几个流中正常工作,但它会在 cuvidCreateDecoder 函数中为 12 个分辨率为 800x600 的流或 9 个分辨率为 1920x1080 的流引发断言 (CUDA_ERROR_OUT_OF_MEMORY)。cudaMemGetInfo 返回 387MB(1GB 显卡)和 1.3Gb(2GB 显卡)可用内存。内存碎片会导致这种情况吗?如何使用可用内存?
VideoDecoder::VideoDecoder(const CUVIDEOFORMAT & rVideoFormat,
CUcontext &rContext,
cudaVideoCreateFlags eCreateFlags,
CUvideoctxlock &vidCtxLock)
: m_VidCtxLock(vidCtxLock)
{
// get a copy of the CUDA context
m_Context = rContext;
m_VideoCreateFlags = eCreateFlags;
// Fill the decoder-create-info struct from the given video-format struct.
memset(&oVideoDecodeCreateInfo_, 0, sizeof(CUVIDDECODECREATEINFO));
// Create video decoder
oVideoDecodeCreateInfo_.CodecType = rVideoFormat.codec;
oVideoDecodeCreateInfo_.ulWidth = rVideoFormat.coded_width;
oVideoDecodeCreateInfo_.ulHeight = rVideoFormat.coded_height;
oVideoDecodeCreateInfo_.ulNumDecodeSurfaces = FrameQueue::cnMaximumSize;
// Limit decode memory to 24MB (16M pixels at 4:2:0 = 24M bytes)
while (oVideoDecodeCreateInfo_.ulNumDecodeSurfaces * rVideoFormat.coded_width * rVideoFormat.coded_height > 16*1024*1024)
{
oVideoDecodeCreateInfo_.ulNumDecodeSurfaces--;
}
oVideoDecodeCreateInfo_.ChromaFormat = rVideoFormat.chroma_format;
oVideoDecodeCreateInfo_.OutputFormat = cudaVideoSurfaceFormat_NV12;
oVideoDecodeCreateInfo_.DeinterlaceMode = cudaVideoDeinterlaceMode_Adaptive;
// No scaling
oVideoDecodeCreateInfo_.ulTargetWidth = oVideoDecodeCreateInfo_.ulWidth;
oVideoDecodeCreateInfo_.ulTargetHeight = oVideoDecodeCreateInfo_.ulHeight;
oVideoDecodeCreateInfo_.ulNumOutputSurfaces = MAX_FRAME_COUNT; // We won't simultaneously map more than 8 surfaces
oVideoDecodeCreateInfo_.ulCreationFlags = m_VideoCreateFlags;
oVideoDecodeCreateInfo_.vidLock = m_VidCtxLock;
size_t available, total;
cudaMemGetInfo(&available, &total);
// create the decoder
CUresult oResult = cuvidCreateDecoder(&oDecoder_, &oVideoDecodeCreateInfo_);
assert(CUDA_SUCCESS == oResult);
}
cuvidCreateDecoder 可以在超过 1920x1080 的分辨率下工作吗?当我尝试 2560x1920 流时 cuvidCreateDecoder 断言 CUDA_ERROR_INVALID_SOURCE。
我的环境
- 硬件:NVidia GTX 550 Ti 1Gb、NVidia GT 610 2Gb、驱动程序版本 306.23
- 视窗 7 x64
- 视觉工作室 2010 SP1
- 视窗 SDK 7.1
- NVIDIA GPU 计算工具包 v.4.2、v.5.0
- NVIDIA GPU 计算 SDK 4.2。