The aConstants parameter does not work when using the planar twist API

Hello,

While testing the NPP twist API on CUDA 12.3, I noticed something unusual and would like to ask a question.

Why does processing the same input values produce different results between the planar in-place method and the packed in-place API?

result:


                            R   G   B  |  Twist_IP3R  |  Twist_C3IR
TestCase                             |  Y  Cb  Cr   |  Y  Cb  Cr
------------------------------------------------------------------
DarkRed (  2,  0,  0)        2   0   0 |   0 127 129  |   1 128 129

source code:

#include "gtest/gtest.h"



#include <cuda_runtime.h>

#include <npp.h>



class TwistIP3RvsC3IRTest : public ::testing::Test {

protected:

static void SetUpTestSuite() {

    }

};



// POC: Compare nppiColorTwist32f_8u_IP3R_Ctx vs nppiColorTwist32f_8u_C3IR_Ctx

TEST_F(TwistIP3RvsC3IRTest, POC_TWIST_IP3R_VS_C3IR) {

struct TestCase {

const char* name;

uint8_t r, g, b;

    };



std::vector<TestCase> testCases = {

        {"DarkRed (  2,  0,  0)", 2,   0,   0},

    };



NppStreamContext nppCtx = {};

int deviceId = 0;

cudaGetDevice(&deviceId);

nppCtx.hStream = nullptr;

nppCtx.nCudaDeviceId = deviceId;

cudaDeviceGetAttribute(&nppCtx.nMultiProcessorCount, cudaDevAttrMultiProcessorCount, deviceId);

cudaDeviceGetAttribute(&nppCtx.nMaxThreadsPerMultiProcessor, cudaDevAttrMaxThreadsPerMultiProcessor, deviceId);

cudaDeviceGetAttribute(&nppCtx.nMaxThreadsPerBlock, cudaDevAttrMaxThreadsPerBlock, deviceId);

int sharedMem = 0;

cudaDeviceGetAttribute(&sharedMem, cudaDevAttrMaxSharedMemoryPerBlock, deviceId);

nppCtx.nSharedMemPerBlock = static_cast<size_t>(sharedMem);

cudaDeviceGetAttribute(&nppCtx.nCudaDevAttrComputeCapabilityMajor, cudaDevAttrComputeCapabilityMajor, deviceId);

cudaDeviceGetAttribute(&nppCtx.nCudaDevAttrComputeCapabilityMinor, cudaDevAttrComputeCapabilityMinor, deviceId);

NppiSize roi = {1, 1};



static const Npp32f aTwist[3][4] = {

        { 0.299f,     0.587f,     0.114f,    0.5f},

        {-0.168736f, -0.331264f,  0.5f,    128.5f},

        { 0.5f,      -0.418688f, -0.081312f, 128.5f}

    };



printf("\n%-26s  R   G   B  |  Twist_IP3R  |  Twist_C3IR\n", "");

printf("%-26s           |  Y  Cb  Cr   |  Y  Cb  Cr\n", "TestCase");

printf("------------------------------------------------------------------\n");



for (const auto& tc : testCases) {

        // --- nppiColorTwist32f_8u_IP3R_Ctx (planar, in-place) ---

Npp8u *dIP3R[3];

for (int i = 0; i < 3; i++) cudaMalloc(&dIP3R[i], 1);

cudaMemcpy(dIP3R[0], &tc.r, 1, cudaMemcpyHostToDevice);

cudaMemcpy(dIP3R[1], &tc.g, 1, cudaMemcpyHostToDevice);

cudaMemcpy(dIP3R[2], &tc.b, 1, cudaMemcpyHostToDevice);



NppStatus ip3rStatus = nppiColorTwist32f_8u_IP3R_Ctx(dIP3R, 1, roi, aTwist, nppCtx);

ASSERT_EQ(ip3rStatus, NPP_SUCCESS) << "IP3R failed for " << tc.name;



uint8_t tIP3Ry = 0, tIP3Rcb = 0, tIP3Rcr = 0;

cudaMemcpy(&tIP3Ry,  dIP3R[0], 1, cudaMemcpyDeviceToHost);

cudaMemcpy(&tIP3Rcb, dIP3R[1], 1, cudaMemcpyDeviceToHost);

cudaMemcpy(&tIP3Rcr, dIP3R[2], 1, cudaMemcpyDeviceToHost);

for (int i = 0; i < 3; i++) cudaFree(dIP3R[i]);



        // --- nppiColorTwist32f_8u_C3IR_Ctx (packed, in-place) ---

uint8_t hC3IR[3] = {tc.r, tc.g, tc.b};

Npp8u *dC3IR;

cudaMalloc(&dC3IR, 3);

cudaMemcpy(dC3IR, hC3IR, 3, cudaMemcpyHostToDevice);



NppStatus c3irStatus = nppiColorTwist32f_8u_C3IR_Ctx(dC3IR, 3, roi, aTwist, nppCtx);

ASSERT_EQ(c3irStatus, NPP_SUCCESS) << "C3IR failed for " << tc.name;



uint8_t tC3IRy = 0, tC3IRcb = 0, tC3IRcr = 0;

cudaMemcpy(&tC3IRy,  dC3IR + 0, 1, cudaMemcpyDeviceToHost);

cudaMemcpy(&tC3IRcb, dC3IR + 1, 1, cudaMemcpyDeviceToHost);

cudaMemcpy(&tC3IRcr, dC3IR + 2, 1, cudaMemcpyDeviceToHost);

cudaFree(dC3IR);



printf("%-26s %3d %3d %3d | %3d %3d %3d  | %3d %3d %3d\n",

tc.name, tc.r, tc.g, tc.b,

tIP3Ry, tIP3Rcb, tIP3Rcr,

tC3IRy, tC3IRcb, tC3IRcr);

    }

}