NPP Copy issue


I am having an issue with Npp channel copy giving me back the -14 error (NPP_STEP_ERROR), even though debugging shows that these are correctly assigned.

        Npp8u* meanDevBuf;
        Npp32f* cudaPtr;
        Npp32f* cudaC1Ptr;
        Npp64f *mean, *dev;

        NppiSize size{ w, h };

        int bufSize{ 0 };
        nppiMeanStdDevGetBufferHostSize_32f_C1R(size, &bufSize);

        cudaMalloc((void **)(&meanDevBuf), bufSize);
        cudaMallocManaged( ( void ** )( &mean ), sizeof(Npp64f) );
        cudaMallocManaged( ( void ** )( &dev ), sizeof(Npp64f) );

        int stepBytes{ 0 };
        cudaPtr = nppiMalloc_32f_C4(size.width, size.height, &stepBytes);

        // this code is copying our source data from our buffer, I verified it and it works
        auto cuSource = std::dynamic_pointer_cast<CudaImage>(source);
        cuSource->getCuImage()->copyToDevice(cudaPtr, stepBytes);

        int stepBytesC1{ 0 };
        cudaC1Ptr = nppiMalloc_32f_C1(size.width, size.height, &stepBytesC1);

        std::vector<float> avgVector(4), devVector(4);

        for (int i = 0; i < 3; i++) {
            // this copy throws an error
            nppiCopy_32f_C4CR(cudaPtr + i, stepBytes, cudaC1Ptr, stepBytesC1, size);
            nppiMean_StdDev_32f_C1R(cudaC1Ptr, stepBytesC1, size, meanDevBuf, mean, dev);
            avgVector[i] = static_cast<float>( *mean );
            devVector[i] = static_cast<float>( *dev );

Any suggestions would be welcome.

It seems you are trying to copy a selected channel of a 4-channel image into a single channel image.

nppiCopy32f_C4CR doesn’t do that. It expects that both source and destination are 4 channel images.

I think what you want is called an “extract channel copy” ?

If I change the function call in your code from nppiCopy_32f_C4CR to nppiCopy_32f_C4C1R I get no errors.

1 Like

Yes, that worked perfectly. Thank you very much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.