我注意到一些npp函数有一个参数*pDeviceBuffer。我想知道这个参数是用来做什么的,以及我在使用函数时应该如何设置它。此外,函数的结果(如nppsMax_32f )被写回指针。内存是在主机上还是在设备上?谢谢。
发布于 2011-06-14 13:08:53
pDeviceBuffer被用作核电厂内部的暂存空间。暂存空间通常在内部分配(就像在CUFFT中一样)。但其中一些操作(sum、min、max)速度太快,以至于分配暂存空间本身可能成为瓶颈。查询所需的暂存空间,然后在多次重用它之前分配一次,这将是一个好主意。
例如:假设你有一个非常大的数组,你想要从中得到min,max和sum,你需要做以下的事情。
int n = 1e6, bytes = 0;
nppsReductionGetBufferSize_32f(n, &bytes);
Npp8u *scratch = nppsMalloc_8f(bytes);
nppsMax_32f(in, n, max_val, nppAlgHintNone, scratch);
// Reusing scratch space for input of same size
nppsMin_32f(in, n, min_val, nppAlgHintNone, scratch);
// Reusing scratch space for input of smaller size
nppsSum_32f(in, 1e4, sum_val, nppAlgHintNone, scratch);
// Larger inputs may require more scratch space.
// So you may need to check and allocate appropriate space
int newBytes = 0; nppsReductionGetBufferSize_32f(5e6, &newBytes);
if (bytes != newBytes) {
nppsFree(scratch);
scratch = nppsMalloc_8u(bytes);
}
nppsSum_32f(in, 5e6, sum_val, nppAlgHintNone, scratch);https://stackoverflow.com/questions/6338690
复制相似问题