我开发了一个天真的功能,使用CUDA C++水平或垂直镜像图像.
然后我才知道NVIDIA Performance Primitives Library还提供了图像镜像功能.
仅仅为了比较,我计算了我对NPP的功能.令人惊讶的是,我的功能表现优异(尽管差距很小,但仍然......).
我使用Windows计时器和CUDA计时器多次确认了结果.
我的问题是:NPP功能是否完全针对NVIDIA GPU进行了优化?
我正在使用CUDA 5.0,GeForce GTX460M(Compute 2.1)和Windows 8进行开发.
Nvidia Performance Primitives(NPP)提供了nppiFilter
将用户提供的图像与用户提供的内核进行卷积的功能.对于1D卷积内核,nppiFilter
可以正常工作.但是,nppiFilter
正在为2D内核生成垃圾图像.
我使用典型的Lena图像作为输入:
这是我使用1D卷积内核的实验,它可以产生良好的输出.
#include <npp.h> // provided in CUDA SDK
#include <ImagesCPU.h> // these image libraries are also in CUDA SDK
#include <ImagesNPP.h>
#include <ImageIO.h>
void test_nppiFilter()
{
npp::ImageCPU_8u_C1 oHostSrc;
npp::loadImage("Lena.pgm", oHostSrc);
npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc); // malloc and memcpy to GPU
NppiSize kernelSize = {3, 1}; // dimensions of convolution kernel (filter)
NppiSize oSizeROI = {oHostSrc.width() - kernelSize.width + 1, oHostSrc.height() - kernelSize.height + 1};
npp::ImageNPP_8u_C1 oDeviceDst(oSizeROI.width, oSizeROI.height); // allocate …
Run Code Online (Sandbox Code Playgroud) CUDA NPP库支持使用nppiFilter_8u_C1R命令过滤图像,但不断出现错误.启动boxFilterNPP示例代码并没有问题.
eStatusNPP = nppiFilterBox_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(),
oDeviceDst.data(), oDeviceDst.pitch(),
oSizeROI, oMaskSize, oAnchor);
Run Code Online (Sandbox Code Playgroud)
但是,如果我将其更改为使用nppiFilter_8u_C1R,则eStatusNPP将返回错误-24(NPP_TEXTURE_BIND_ERROR).下面的代码是我对原始boxFilterNPP样本所做的更改.
NppiSize oMaskSize = {5,5};
npp::ImageCPU_32s_C1 hostKernel(5,5);
for(int x = 0 ; x < 5; x++){
for(int y = 0 ; y < 5; y++){
hostKernel.pixels(x,y)[0].x = 1;
}
}
npp::ImageNPP_32s_C1 pKernel(hostKernel);
Npp32s nDivisor = 1;
eStatusNPP = nppiFilter_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(),
oDeviceDst.data(), oDeviceDst.pitch(),
oSizeROI,
pKernel.data(),
oMaskSize, oAnchor,
nDivisor);
Run Code Online (Sandbox Code Playgroud)
这已在CUDA 4.2和5.0上尝试过,结果相同.
当oMaskSize = {1,1}时,代码以预期结果运行
用于CUDA构建的NPP库是仅使用freeImage还是我可以使用其他结构或仅使用unsigned char*image作为NPP函数中的输入.
我提出这个问题的原因是NPP的所有样本都有freeImage的大包装器.
我已经仔细研究了NVIDIA Performance Primitives(NPP),但是只提到了一个图像,而不是特别使用哪种图像格式.
如果你有一个如何在没有freeImage的情况下使用NPP的例子,或者只是没有从磁盘加载图像,那么我会谨慎开心.
OpenCV原语是否基于CUDA Nvidia Performance Primitives(NPP)?
原语我的意思是在NPP库中实现的相同,例如:boxFilter,Mirror,Convolution ......
我想知道这个问题,因为我正计划使用NPP库.但是,OpenCV具有更多功能,可以帮助我进行图像处理的边界处理.
我正在尝试使用 Nvidia 性能基元库来调整图像大小,但该nppiResize_8u_C3R
函数抛出NPP_RESIZE_FACTOR_ERROR
的错误未在文档中列出作为该函数的错误返回代码之一。这是我希望简单的代码:
#include <iostream>
#include <nppi.h>
int image_a_pitch;
NppiSize image_a_size = {.width = 960, .height = 540};
NppiRect image_a_roi = {.x = 0, .y = 0, .width = 960, .height = 540};
Npp8u* image_a = nppiMalloc_8u_C3(960, 540, &image_a_pitch);
int image_b_pitch;
NppiSize image_b_size = {.width = 960, .height = 540};
NppiRect image_b_roi = {.x = 0, .y = 0, .width = 960, .height = 540};
Npp8u* image_b = nppiMalloc_8u_C3(960, 540, &image_b_pitch);
NppStatus result = nppiResize_8u_C3R(image_a, image_a_pitch, …
Run Code Online (Sandbox Code Playgroud) 我正在使用Cuda 7.5和GeForce GTX 650 Ti进行图像处理项目.我决定使用2个流,一个是我应用负责增强图像的算法,另一个是我从其余处理中应用独立算法的流.
我写了一个例子来说明我的问题.在这个例子中,我创建了一个流,然后我使用了nppSetStream.
我调用了函数nppiThreshold_LTValGTVal_32f_C1R,但在执行函数时使用了2个流.
这里有一个代码示例:
#include <npp.h>
#include <cuda_runtime.h>
#include <cuda_profiler_api.h>
int main(void) {
int srcWidth = 1344;
int srcHeight = 1344;
int paddStride = 0;
float* srcArrayDevice;
float* srcArrayDevice2;
unsigned char* dstArrayDevice;
int status = cudaMalloc((void**)&srcArrayDevice, srcWidth * srcHeight * 4);
status = cudaMalloc((void**)&srcArrayDevice2, srcWidth * srcHeight * 4);
status = cudaMalloc((void**)&dstArrayDevice, srcWidth * srcHeight );
cudaStream_t testStream;
cudaStreamCreateWithFlags(&testStream, cudaStreamNonBlocking);
nppSetStream(testStream);
NppiSize roiSize = { srcWidth,srcHeight };
//status = cudaMemcpyAsync(srcArrayDevice, &srcArrayHost, srcWidth*srcHeight*4, cudaMemcpyHostToDevice, testStream);
int yRect …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 NPP 互相关库实现图像置换方法。
我尝试通过在内存中生成几个简单的图像来创建一个简单的解决方案,输出 Npp8u 或 Npp32f 数组。然而,互相关库会产生无意义或无效(即 NAN)的结果。
int main(int argc, char* argv[])
{
Npp8u* gpuImg1, * gpuImg2;
Npp32f *gpuDest;
cudaDeviceInit(argc, (const char**)argv);
long dataSize1 = 128;
auto err = cudaMalloc((void**)&gpuImg1, dataSize1 * dataSize1 * sizeof(unsigned char));
auto img1Data = static_cast<unsigned char*>(malloc(dataSize1 * dataSize1 * sizeof(unsigned char)));
memset(img1Data, 0, dataSize1 * dataSize1);
for(auto y = 40; y < 60; y++)
{
for(auto x = 20; x < 40; x++)
{
img1Data[y * dataSize1 + x] = 0xff;
}
} …
Run Code Online (Sandbox Code Playgroud) 我尝试使用 CUDA 和 Qt 来模糊图像。我使用 NPP 库,nppiFilterGauss_8u_C1R 效果很好
void cuda_npp_gauss_filter_qt(uchar* pSourceData, uchar* pResultData, const int &ImageLineStep, const int &ImageWidth, const int &ImageHeight)
{
NppiSize oSizeROI;
oSizeROI.width = ImageWidth;
oSizeROI.height = ImageHeight;
Npp32s SourceStep = ImageLineStep;
Npp32s DestinationStep = ImageLineStep;
size_t AllocationSizeInBytes = ImageLineStep * ImageHeight;
Npp8u *pSource, *pDestination;
cudaMalloc<Npp8u>(&pSource,AllocationSizeInBytes);
cudaMalloc<Npp8u>(&pDestination,AllocationSizeInBytes);
cudaMemcpy(pSource, pSourceData, AllocationSizeInBytes, cudaMemcpyHostToDevice);
nppiFilterGauss_8u_C1R(pSource, SourceStep, pDestination, DestinationStep, oSizeROI, NPP_MASK_SIZE_15_X_15);
cudaMemcpy(pResultData, pDestination, AllocationSizeInBytes, cudaMemcpyDeviceToHost);
}
Run Code Online (Sandbox Code Playgroud)
但 nppiFilterGaussAdvanced_8u_C1R 会损坏图像
void cuda_npp_gauss_filter_qt_advanced(uchar* pSourceData, uchar* pResultData, const int &ImageLineStep, const int &ImageWidth, const …
Run Code Online (Sandbox Code Playgroud)