added aligned memory allocation to CudaMem (if allocation type is ZERO_COPY)

fixed bugs in gpu::cvtColor
This commit is contained in:
Vladislav Vinogradov
2011-05-03 09:09:05 +00:00
parent 727fbd5376
commit c21a783646
2 changed files with 22 additions and 5 deletions

View File

@@ -590,10 +590,21 @@ void cv::gpu::ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m)
bool cv::gpu::CudaMem::canMapHostMemory()
{
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, 0);
cudaGetDeviceProperties(&prop, getDevice());
return (prop.canMapHostMemory != 0) ? true : false;
}
namespace
{
int alignUp(int what, int alignment)
{
int alignMask = alignment-1;
int inverseAlignMask = ~alignMask;
int res = (what + alignMask) & inverseAlignMask;
return res;
}
}
void cv::gpu::CudaMem::create(int _rows, int _cols, int _type, int _alloc_type)
{
if (_alloc_type == ALLOC_ZEROCOPY && !canMapHostMemory())
@@ -611,6 +622,12 @@ void cv::gpu::CudaMem::create(int _rows, int _cols, int _type, int _alloc_type)
rows = _rows;
cols = _cols;
step = elemSize()*cols;
if (_alloc_type == ALLOC_ZEROCOPY)
{
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, getDevice());
step = alignUp(step, prop.textureAlignment);
}
int64 _nettosize = (int64)step*rows;
size_t nettosize = (size_t)_nettosize;
if( _nettosize != (int64)nettosize )