2

I'm attempting to use the Nvidia performance primatives library to resize an image, but the nppiResize_8u_C3R function is throwing a NPP_RESIZE_FACTOR_ERROR that is not listed in the documentation as one of the error return codes for that function. Here is my hopefully simple code:

#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, image_a_size, image_a_roi, image_b, image_b_pitch, image_b_size, image_b_roi, NPPI_INTER_SUPER);

if (result != NPP_SUCCESS) {
    std::cerr << "Error executing Resize -- code: " << result << std::endl;
}

You might note I'm not actually resizing the image, and yes, that is true, but I'm attempting to create the simplest case for this error. From what I've been testing, it doesn't seem to matter what sizes I use for the images, I still get the same return error code, which does not seem to be a valid error code for that function, but rather an error code for the depreciated nppiResizeSqrPixel_8u_C3R.

I'd definitely appreciate some help pointing out whatever error I'm doing in setting up the library calls that is causing this error.

1 Answer 1

5

Looking at the jpegNPP CUDA sample code, I observe this sequence:

    NppiInterpolationMode eInterploationMode = NPPI_INTER_SUPER;

    if (nScaleFactor >= 1.f)
        eInterploationMode = NPPI_INTER_LANCZOS;

    NPP_CHECK_NPP(nppiResize_8u_C1R(..., eInterploationMode));
}

When I switch your interpolation mode from NPPI_INTER_SUPER to NPPI_INTER_LANCZOS in your example, the error goes away for me (CUDA 9.1, linux). I suspect there is some undocumented (AFAICT) requirement in NPP library for this function, that the NPPI_INTER_SUPER interpolation mode not be used when the resize scale factor is 1.0 or greater (yours is 1.0, it is the ratio of the sourceROI/destROI).

I suggest you study the usage in that sample code, and put a similar mechanism in place in your code.

I've already put in a request to have the CUDA documentation updated with appropriate information. I don't have any further details. You're welcome to file your own bug at http://developer.nvidia.com

update: I've confirmed with the CUDA team that a documentation update for this is planned in a future CUDA release. In a nutshell, the requirement to use NPPI_INTER_SUPER is that you must be doing downscaling. That is, the ratio of X source ROI dimension divided by the X destination ROI dimension must be greater than 1.0. Likewise the ratio of the Y source ROI dimension divided by the Y destination ROI dimension must be greater than 1.0. If either of these conditions are not met, the NPPI_INTER_SUPER interpolation mode cannot be used. For example, the NPPI_INTER_LANCZOS mode can be used instead.

1
  • That is an awesome find! I did see that code in the jpegNPP example, but it never occurred to me that was the issue, and the error response was making things confusing as well... NPP_RESIZE_FACTOR_ERROR isn't documented as being an error return value from the nppiResize family of functions, and furthermore it's documented as being a scale-by-zero or negative-scale error, which I didn't see where that would have occurred.
    – Jason
    Mar 22, 2018 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.