我正在尝试使用GpuMat数据编写自定义内核来查找图像像素的反余弦.当GPU上传数据时,我可以上传,下载和更改值,CV_8UC1但字符不能用于计算反余弦值.但是,当我尝试将GPU转换为CV_32FC1类型(浮点数)时,在下载部分期间出现非法内存访问错误.这是我的代码:
//.cu code
#include <cuda_runtime.h>
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
__global__ void funcKernel(const float* srcptr, float* dstptr, size_t srcstep, const size_t dststep, int cols, int rows){
int rowInd = blockIdx.y*blockDim.y+threadIdx.y;
int colInd = blockIdx.x*blockDim.x+threadIdx.x;
if(rowInd >= rows || colInd >= cols)
return;
const float* rowsrcptr=srcptr+rowInd*srcstep;
float* rowdstPtr= dstptr+rowInd*dststep;
float val = rowsrcptr[colInd];
if((int) val % 90 == 0)
rowdstPtr[colInd] = -1 ;
else{
float acos_val = acos(val);
rowdstPtr[colInd] = acos_val;
}
}
int …Run Code Online (Sandbox Code Playgroud)