本文介绍了NPP库函数参数* pDeviceBuffer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到一些npp函数有一个参数* pDeviceBuffer。我想知道这个参数是什么,以及如何使用函数时设置它。此外,函数的结果,如nppsMax_32f,被写回指针。主机或设备内存上的内存?谢谢。

I notice some of the npp functions has an argument *pDeviceBuffer. I am wondering what this argument is for and how I shall set it while using the functions. Also, the results of functions,such as nppsMax_32f, are written back to a pointer. Is the memory on host or device memory? Thank you.

推荐答案

pDeviceBuffer用作npp中的临时空间。划痕空间通常在内部分配(如在CUFFT中)。但是其中一些操作(sum,min,max)很快,所以分配临时空间本身可能会成为瓶颈。

pDeviceBuffer is used as scratch space inside npp. Scratch space is usually allocated internally (like in CUFFT). But some of these operations (sum, min, max) are so quick that allocating the scratch space itself might become a bottleneck. Querying for the scratch space required and then allocating it once before re-using it multiple times would be a good idea.

例如:
假设你有一个需要的临时空间,然后再分配一次,然后重新使用它多次。

Example:Let's say you have a very large array that you want to get min max and sum from, you will need to do the following.

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);

这篇关于NPP库函数参数* pDeviceBuffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 08:59