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. JavaScript中两种类型的全局对象/函数【转】

    Snandy Stop, thinking is the essence of progress. JavaScript中两种类型的全局对象/函数 这里所说的JavaScript指浏览器环境中的包括宿 ...

  2. CSS中的三种基本的定位机制(普通流、定位、浮动)

    一.普通流 普通流中元素框的位置由元素在XHTML中的位置决定.块级元素从上到下依次排列,框之间的垂直距离由框的垂直margin计算得到.行内元素在一行中水平布置. 普通流就是html文档中的元素如块 ...

  3. 企业搜索引擎开发之连接器connector(十六)

    本人有一段时间没有接触企业搜索引擎之连接器的开发了,连接器是涉及企业搜索引擎一个重要的组件,在数据源与企业搜索引擎中间起一个桥梁的作用,类似于数据库之JDBC,通过连接器将不同数据源的数据适配到企业搜 ...

  4. Sed的使用方法简介

    =============Sed================== Sed:是一款流编辑工具,用来对文本进行过滤与替换工作,特别是当你想对几十个配置文件进行统一修改时,你会体会到它的魅力:Sed通过 ...

  5. Linq扩展最后遗留之SelectMany,Zip,SequenceEqual源码分析

    Linq扩展最后遗留之SelectMany,Zip,SequenceEqual源码分析 一: AsParallel [并行化查询] 这个函数的功效就是将计算结果多线程化.[并行计算] =>[多核 ...

  6. sh脚本

    通过. xxx.sh执行 经常在第一行加上#!/bin/bash,表示需要使用的bash shell环境 关于#!/bin/bash和#!/bin/sh 可以直接放linux命令 使用for循环 使用 ...

  7. 三个数组求中位数,并且求最后中位数的中位数-----C++算法实现

    文件Median.h #include <list> class CMedian { public: explicit CMedian(); virtual ~CMedian(); voi ...

  8. OCP题库升级,iZ0-052新加的考题及答案整理-18

    18.You want to Install Oracle 11g database software and create a database on ASM Immediately after t ...

  9. [Swift实际操作]八、实用进阶-(9)Swift中的链表LinkedList详解

    链表是一种物理存储单元上的非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针连接次序实现的.相比于线性表的顺序结构,链表比较方便插入和删除操作.本文将讲解如何模拟一个链表. //链表的节点 ...

  10. Setup "EQGRP_Lost_in_Translation" Of NAS

    Setup "EQGRP_Lost_in_Translation" Of NAS 1.前言: 北京时间4月14号晚,TheShadowBrokers在steemit.com博客上放 ...