本文整理汇总了C++中DeviceInfo::canMapHostMemory方法的典型用法代码示例。如果您正苦于以下问题:C++ DeviceInfo::canMapHostMemory方法的具体用法?C++ DeviceInfo::canMapHostMemory怎么用?C++ DeviceInfo::canMapHostMemory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeviceInfo
的用法示例。
在下文中一共展示了DeviceInfo::canMapHostMemory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: release
void cv::cuda::CudaMem::create(int rows_, int cols_, int type_)
{
#ifndef HAVE_CUDA
(void) rows_;
(void) cols_;
(void) type_;
throw_no_cuda();
#else
if (alloc_type == SHARED)
{
DeviceInfo devInfo;
CV_Assert( devInfo.canMapHostMemory() );
}
type_ &= Mat::TYPE_MASK;
if (rows == rows_ && cols == cols_ && type() == type_ && data)
return;
if (data)
release();
CV_DbgAssert( rows_ >= 0 && cols_ >= 0 );
if (rows_ > 0 && cols_ > 0)
{
flags = Mat::MAGIC_VAL + Mat::CONTINUOUS_FLAG + type_;
rows = rows_;
cols = cols_;
step = elemSize() * cols;
if (alloc_type == SHARED)
{
DeviceInfo devInfo;
step = alignUpStep(step, devInfo.textureAlignment());
}
int64 _nettosize = (int64)step*rows;
size_t nettosize = (size_t)_nettosize;
if (_nettosize != (int64)nettosize)
CV_Error(cv::Error::StsNoMem, "Too big buffer is allocated");
size_t datasize = alignSize(nettosize, (int)sizeof(*refcount));
void* ptr = 0;
switch (alloc_type)
{
case PAGE_LOCKED: cudaSafeCall( cudaHostAlloc(&ptr, datasize, cudaHostAllocDefault) ); break;
case SHARED: cudaSafeCall( cudaHostAlloc(&ptr, datasize, cudaHostAllocMapped) ); break;
case WRITE_COMBINED: cudaSafeCall( cudaHostAlloc(&ptr, datasize, cudaHostAllocWriteCombined) ); break;
default: CV_Error(cv::Error::StsBadFlag, "Invalid alloc type");
}
datastart = data = (uchar*)ptr;
dataend = data + nettosize;
refcount = (int*)cv::fastMalloc(sizeof(*refcount));
*refcount = 1;
}
#endif
}