| 103 | // clang-format on |
| 104 | |
| 105 | TEST_P(OpNormalize, tensor_correct_output) |
| 106 | { |
| 107 | cudaStream_t stream; |
| 108 | EXPECT_EQ(cudaSuccess, cudaStreamCreate(&stream)); |
| 109 | |
| 110 | int width = GetParamValue<0>(); |
| 111 | int height = GetParamValue<1>(); |
| 112 | int numImages = GetParamValue<2>(); |
| 113 | bool scalarBase = GetParamValue<3>(); |
| 114 | bool scalarScale = GetParamValue<4>(); |
| 115 | uint32_t flags = GetParamValue<5>(); |
| 116 | float globalScale = GetParamValue<6>(); |
| 117 | float globalShift = GetParamValue<7>(); |
| 118 | float epsilon = GetParamValue<8>(); |
| 119 | |
| 120 | int baseWidth = (scalarBase ? 1 : width); |
| 121 | int scaleWidth = (scalarScale ? 1 : width); |
| 122 | int baseHeight = (scalarBase ? 1 : height); |
| 123 | int scaleHeight = (scalarScale ? 1 : height); |
| 124 | int baseNumImages = (scalarBase ? 1 : numImages); |
| 125 | int scaleNumImages = (scalarScale ? 1 : numImages); |
| 126 | |
| 127 | nvcv::ImageFormat baseFormat = (scalarBase ? nvcv::FMT_F32 : nvcv::FMT_RGBAf32); |
| 128 | nvcv::ImageFormat scaleFormat = (scalarScale ? nvcv::FMT_F32 : nvcv::FMT_RGBAf32); |
| 129 | |
| 130 | nvcv::ImageFormat fmt = nvcv::FMT_RGBA8; |
| 131 | |
| 132 | std::default_random_engine rng; |
| 133 | |
| 134 | // Create input tensor |
| 135 | nvcv::Tensor imgSrc = nvcv::util::CreateTensor(numImages, width, height, fmt); |
| 136 | auto srcData = imgSrc.exportData<nvcv::TensorDataStridedCuda>(); |
| 137 | ASSERT_NE(nullptr, srcData); |
| 138 | auto srcAccess = nvcv::TensorDataAccessStridedImagePlanar::Create(*srcData); |
| 139 | ASSERT_TRUE(srcAccess); |
| 140 | |
| 141 | std::vector<std::vector<uint8_t>> srcVec(numImages); |
| 142 | int srcVecRowStride = width * fmt.numChannels(); |
| 143 | for (int i = 0; i < numImages; ++i) |
| 144 | { |
| 145 | std::uniform_int_distribution<uint8_t> udist(0, 255); |
| 146 | |
| 147 | srcVec[i].resize(height * srcVecRowStride); |
| 148 | generate(srcVec[i].begin(), srcVec[i].end(), [&]() { return udist(rng); }); |
| 149 | |
| 150 | // Copy input data to the GPU |
| 151 | ASSERT_EQ(cudaSuccess, |
| 152 | cudaMemcpy2D(srcAccess->sampleData(i), srcAccess->rowStride(), srcVec[i].data(), srcVecRowStride, |
| 153 | srcVecRowStride, // vec has no padding |
| 154 | height, cudaMemcpyHostToDevice)); |
| 155 | } |
| 156 | |
| 157 | // Create base tensor |
| 158 | nvcv::Tensor imgBase(baseNumImages, {baseWidth, baseHeight}, baseFormat); |
| 159 | auto baseData = imgBase.exportData<nvcv::TensorDataStridedCuda>(); |
| 160 | ASSERT_NE(nullptr, baseData); |
| 161 | auto baseAccess = nvcv::TensorDataAccessStridedImagePlanar::Create(*baseData); |
| 162 | ASSERT_TRUE(baseAccess); |
nothing calls this directly
no test coverage detected