MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / CvtColor

Function CvtColor

bench/BenchCvtColor.cpp:103–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101
102template<typename BT>
103inline void CvtColor(nvbench::state &state, nvbench::type_list<BT>)
104try
105{
106 long3 shape = benchutils::GetShape<3>(state.get_string("shape"));
107 long varShape = state.get_int64("varShape");
108
109 ConvCodeToFormat formats = str2Frmt(state.get_string("code"));
110
111 NVCVColorConversionCode code = std::get<0>(formats);
112 nvcv::ImageFormat inFormat{std::get<1>(formats)};
113 nvcv::ImageFormat outFormat{std::get<2>(formats)};
114
115 state.add_global_memory_reads(shape.x * shape.y * shape.z * bytesPerPixel<BT>(inFormat));
116 state.add_global_memory_writes(shape.x * shape.y * shape.z * bytesPerPixel<BT>(outFormat));
117
118 cvcuda::CvtColor op;
119
120 if (varShape < 0) // negative var shape means use Tensor
121 {
122 nvcv::Tensor src = CreateTensor(shape.x, shape.z, shape.y, inFormat);
123 nvcv::Tensor dst = CreateTensor(shape.x, shape.z, shape.y, outFormat);
124
125 benchutils::FillTensor<BT>(src, benchutils::RandomValues<BT>());
126
127 state.exec(nvbench::exec_tag::sync,
128 [&op, &src, &dst, &code](nvbench::launch &launch) { op(launch.get_stream(), src, dst, code); });
129 }
130 else // zero and positive var shape means use ImageBatchVarShape
131 {
132 if (inFormat.chromaSubsampling() != nvcv::ChromaSubsampling::CSS_444
133 || outFormat.chromaSubsampling() != nvcv::ChromaSubsampling::CSS_444)
134 {
135 state.skip("Skipping formats that have subsampled planes for the varshape benchmark");
136 }
137
138 std::vector<nvcv::Image> imgSrc;
139 std::vector<nvcv::Image> imgDst;
140 nvcv::ImageBatchVarShape src(shape.x);
141 nvcv::ImageBatchVarShape dst(shape.x);
142 std::vector<std::vector<uint8_t>> srcVec(shape.x);
143
144 auto randomValuesU8 = benchutils::RandomValues<uint8_t>();
145
146 for (int i = 0; i < shape.x; i++)
147 {
148 imgSrc.emplace_back(nvcv::Size2D{(int)shape.z, (int)shape.y}, inFormat);
149 imgDst.emplace_back(nvcv::Size2D{(int)shape.z, (int)shape.y}, outFormat);
150
151 int srcRowStride = imgSrc[i].size().w * inFormat.planePixelStrideBytes(0);
152 int srcBufSize = imgSrc[i].size().h * srcRowStride;
153 srcVec[i].resize(srcBufSize);
154 for (int idx = 0; idx < srcBufSize; idx++)
155 {
156 srcVec[i][idx] = randomValuesU8();
157 }
158
159 auto imgData = imgSrc[i].exportData<nvcv::ImageDataStridedCuda>();
160 CUDA_CHECK_ERROR(cudaMemcpy2D(imgData->plane(0).basePtr, imgData->plane(0).rowStride, srcVec[i].data(),

Callers

nothing calls this directly

Calls 13

str2FrmtFunction · 0.85
chromaSubsamplingMethod · 0.80
whatMethod · 0.80
CreateTensorFunction · 0.70
emplace_backMethod · 0.45
sizeMethod · 0.45
planePixelStrideBytesMethod · 0.45
resizeMethod · 0.45
planeMethod · 0.45
dataMethod · 0.45
pushBackMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected