我正在尝试对图像中的所有像素求和,并使用 CUDA NPP 库获取所有像素的平均值。我的图像是8-bit unsigned char grayscale
维度的图像w256 x h1024
。我试图遵循声明指针并将相应的 NPP 类型指针传递给 NPP 函数的所有必需规则。
但是,unknown error
当我对我的代码执行 GPU 错误检查时,我得到了一个。我试图调试它,但我似乎无法弄清楚我哪里出错了,我需要一些帮助吗?
除此之外,我还使用 OpenCV 进行处理,因此会出现一些 OpenCV 代码。
编辑:代码已更新
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) getchar();
}
}
// process image here
// device_pointer initializations
unsigned char *device_input;
unsigned char *device_output;
size_t d_ipimgSize = input.step * input.rows;
size_t d_opimgSize = output.step * output.rows;
gpuErrchk( cudaMalloc( (void**) &device_input, d_ipimgSize) );
gpuErrchk( cudaMalloc( (void**) &device_output, d_opimgSize) );
gpuErrchk( cudaMemcpy(device_input, input.data, d_ipimgSize, cudaMemcpyHostToDevice) );
// Median filter the input image here
// .......
// start summing all pixels
Npp64s *partialSum = 0;
partialSum = (Npp64s *) malloc(sizeof(Npp64s));
int bytes = input.cols*input.rows;
Npp8u *scratch = nppsMalloc_8u(bytes);
int ostep = input.step;
NppiSize imSize;
imSize.width = input.cols;
imSize.height = input.rows;
// copy processed image data into a source_pointer
unsigned char *odata;
odata = (unsigned char*) malloc( sizeof(unsigned char) * input.rows * input.cols);
memcpy(odata, output.data, sizeof(unsigned char) * input.rows * input.cols);
// compute the sum over all the pixels
nppiSum_8u64s_C1R( odata, ostep, imSize, scratch, partialSum );
// print sum
printf( "\n Total Sum cuda %d \n", *partialSum) ;
gpuErrchk(cudaFree(device_input)); // <--- Unknown error here
gpuErrchk(cudaFree(device_output));