Hello everybody,
I’m getting really stuck with building an Argus → VPI → NPP interop chain, as I’m trying to implement [0].
Main question is that after allocating a VPIImage with CUDA memory, just like this:
VPIStatus initCudaBackedImage(VPIImage& image, Size2D<uint32_t> frame_size) {
int image_data_pitch = -1;
Npp8u* image_cuda_data = nppiMalloc_8u_C1(frame_size.width(), frame_size.height(), &image_data_pitch);
if (image_cuda_data == nullptr) {
throw std::runtime_error{"Cannot allocate CUDA memory"};
}
VPIImageData image_data;
memset(&image_data, 0, sizeof(image_data));
image_data.numPlanes = 1;
image_data.format = VPI_IMAGE_FORMAT_U8;
image_data.planes[0].width = frame_size.width();
image_data.planes[0].height = frame_size.height();
image_data.planes[0].pixelType = VPI_PIXEL_TYPE_U8;
image_data.planes[0].pitchBytes = image_data_pitch;
image_data.planes[0].data = image_cuda_data;
return vpiImageCreateCUDAMemWrapper(&image_data, 0, &image);
}
How can you execute an NPP function?
So far, I can see two feasible options:
- Have to lock the VPI image to get the CUDA pointer out - but that involves quite a boilerplate
- Store the pointer next to the VPIImage - but then lose sync between VPI functions down in the line.
My main processing loops looks like this, after I’ve grabbed the frame from Argus:
if (input_fd == -1) {
input_fd = iImageNativeBuffer->createNvBuffer(
iOutputStream->getResolution(),
NvBufferColorFormat_NV12_ER,
NvBufferLayout_Pitch
);
} else {
iImageNativeBuffer->copyToNvBuffer(input_fd);
}
VPI_SAFE_CALL(vpiImageCreateNvBufferWrapper(input_fd, nullptr, 0, &input_image));
VPI_SAFE_CALL(vpiSubmitConvertImageFormat(vpi_stream, VPI_BACKEND_CUDA, input_image, gray_image, nullptr));
// Do here an e.g. nppiAlphaCompC_8u_C1R_Ctx call
// Continoue with VPI rescale algorithms
VPI_SAFE_CALL(vpiStreamSync(vpi_stream));
What’s the suggested way to interop this pieces?
Can we except that samples and documentation will be expanded with more interop examples (as VPI is not as featureful as VisionWorks)?
Thanks!
[0] - Background subtraction and object detection - ScienceDirect