Please note that cv::cuda::GpuMat and cv::Mat using different memory allocation method. cv::cuda::GpuMat the data in is Nvidia Gpu Ram, but cv::Mat store in normal Ram.

The cv::Mat allocated memory normally is continuous, but cv::cuda::GpuMat may have gap between row and row data. Because cv::cuda::GpuMat is using cuda function cudaMallocPitch, which make the step size different from COLS.

So when passing the row data of cv::cuda::GpuMat into a CUDA kernel function, should also pass in the step size into it, so the function can access the row data correctly. If using COLS instead of step, it will easily get wrong, and it is a headache to debug the problem.

For example:

__global__
void kernel_select_cmp_point(
float* dMap,
float* dPhase,
uint8_t* matResult,
uint32_t step,
const int ROWS,
const int COLS,
const int span) {
int start = blockIdx.x * blockDim.x + threadIdx.x;
int stride = blockDim.x * gridDim.x; for (int row = start; row < ROWS; row += stride) {
int offsetOfInput = row * step;
int offsetOfResult = row * step;
}
}

Pitfalls of using opencv GpuMat data in CUDA kernel code的更多相关文章

  1. 关于keil中data,idata,xdata,pdata,code的问题

    转自关于keil中data,idata,xdata,pdata,code的问题 ‍从数据存储类型来说,8051系列有片内.片外程序存储器,片内.片外数据存储器,片内程序存储器还分直接寻址区和间接寻址类 ...

  2. [OpenCV] Basic data types - Matrix

    http://docs.opencv.org/2.4.13/ Basis 矩形 "modules/core/src/drawing.cpp" CV_IMPL void cvRect ...

  3. [OpenCV] GpuMat and Mat, compare cvtColor perforemence

    Introduction I am going to measure the performence of my two GT650M and compare GPU with CPU version ...

  4. opencv 源码分析 CUDA可分离滤波器设计 ( 发现OpenCV的cuda真TM慢 )

    1. 主函数 void SeparableLinearFilter::apply(InputArray _src, OutputArray _dst, Stream& _stream) { G ...

  5. opencv 4.0 + linux + cuda静态编译

    #下载最新的opencv git clone "https://github.com/opencv/opencv.git" git clone "https://gith ...

  6. 关于keil单片机编程中的data,idata,xdata,pdata,code数据类型

    从数据存储类型来说,8051系列有片内.片外程序存储器,片内.片外数据存储器,片内程序存储器还分直接寻址区和间接寻址类型,分别对应code.data.xdata.idata以及根据51系列特点而设定的 ...

  7. 转:单片机C语言中的data,idata,xdata,pdata,code

    从数据存储类型来说,8051系列有片内.片外程序存储器,片内.片外数据存储器,片内程序存储器还分直接寻址区和间接寻址类型,分别对应code.data.xdata.idata以及根据51系列特点而设定的 ...

  8. CUDA ---- Kernel性能调节

    Exposing Parallelism 这部分主要介绍并行分析,涉及掌握nvprof的几个metric参数,具体的这些调节为什么会影响性能会在后续博文解释. 代码准备 下面是我们的kernel函数s ...

  9. Data Types in the Kernel &lt;LDD3 学习笔记&gt;

    Data Types in the Kernel Use of Standard C Types /* * datasize.c -- print the size of common data it ...

随机推荐

  1. google/protobuf hello world

    /(ㄒoㄒ)/~~ 官网被墙 1. github > Search > protobuf or protocol buffers 2.https://github.com/google/p ...

  2. IE6,7,8 CSS HACK

    1.区别IE和非IE浏览器CSS HACK代码 #divcss5{ background:blue; /*非IE 背景藍色*/ background:red \9; /*IE6.IE7.IE8背景紅色 ...

  3. 洛谷P4172 [WC2006]水管局长(lct求动态最小生成树)

    SC省MY市有着庞大的地下水管网络,嘟嘟是MY市的水管局长(就是管水管的啦),嘟嘟作为水管局长的工作就是:每天供水公司可能要将一定量的水从x处送往y处,嘟嘟需要为供水公司找到一条从A至B的水管的路径, ...

  4. Rational Rose简明实用教程

    转载 https://blog.csdn.net/gz153016/article/details/49641847 求下列算法的时间复杂度 void aFunc(int n) { ; i < ...

  5. Vue.js的库,包,资源的列表大全。

    官方资源 外部资源 社区 播客 官方示例 入门 开发工具 语法高亮 代码片段 自动补全 组件集合 库和插件 路由 ajax/数据 状态管理 校验 UI组件 i18n 示例 模板 脚手架 整合 插件/指 ...

  6. C# 调用带输入输出参数的存储过程

    //调用存储过程执行类似于2//select count(*) from userinfo where username=username and pwd=pwd and grade=grade3// ...

  7. zookeeper 开机启动

    第一种:直接修改/etc/rc.d/rc.local文件 在/etc/rc.d/rc.local文件中需要输入两行,其中export JAVA_HOME=/usr/java/jdk1.8.0_112是 ...

  8. centos7 minimal 安装 &网络配置

    1.下载centos7manimal.iso  下载地址: http://isoredirect.centos.org/centos/7/isos/x86_64/CentOS-7-x86_64-Min ...

  9. Javascript:splice() 方法浅析

    定义和用法: splice()方法用于插入.删除或替换数组的元素. 注:该方法会改变原始数组,splice() 方法与 slice() 方法的作用是不同的,splice() 方法会直接对数组进行修改 ...

  10. Python在Android系统上运行

    下载 Scripting Layer for Android (SL4A) https://github.com/damonkohler/sl4a https://www.tutorialspoint ...