我正在使用下面的代码来测试CUDA NPP max函数。
#include <string.h>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <assert.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "cuComplex.h"
#include <cufft.h>
#include <cuda_runtime.h>
#include <npp.h>
#define Nz 256
#define Ny 280
int main(int argc, char** argv) {
struct cudaDeviceProp p;
cudaGetDeviceProperties(&p, 0);
printf("Device Name: %s\n", p.name);
Npp32f* d_img;
cudaMalloc((void**)&d_img, Nz*Ny * sizeof(Npp32f));
nppsSet_32f(1.0f, d_img, Nz*Ny);
int BufferSize;
Npp32f Max;
Npp32f Min;
nppsMinMaxGetBufferSize_32f(Nz*Ny,&BufferSize);
Npp8u *pScratch;
cudaMalloc((void **)(&pScratch), BufferSize);
nppsMinMax_32f(d_img,Nz*Ny,&Min,&Max,pScratch);
printf("Max:%g, Min:%g\n", (float)Max, (float)Min);
cudaFree(d_img);
cudaFree(pScratch);
}设备数组中的所有元素都设置为1,但我得到以下输出。
Max:1.12104e-44, Min:0发布于 2021-08-21 13:59:07
对于NPP文件,Min和Max必须存储在设备内存上(或者至少可以从设备中访问),而不是存储在主机内存中,就像代码中那样。在修复的过程中,需要分配一些内存来存储min/max值,然后将值传输回主机,以打印它们,如文档示例中所示。
https://stackoverflow.com/questions/68873415
复制相似问题