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

Function StartTestVarShape

tests/cvcuda/system/TestOpCopyMakeBorder.cpp:351–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349
350template<typename T>
351void StartTestVarShape(int srcWidthBase, int srcHeightBase, int numBatches, int topPad, int bottomPad, int leftPad,
352 int rightPad, NVCVBorderType borderType, float4 borderValue, nvcv::ImageFormat format)
353{
354 cudaStream_t stream;
355 ASSERT_EQ(cudaSuccess, cudaStreamCreate(&stream));
356
357 std::default_random_engine randEng{0};
358 std::uniform_int_distribution<int> rndSrcWidth(srcWidthBase * 0.8, srcWidthBase * 1.2);
359 std::uniform_int_distribution<int> rndSrcHeight(srcHeightBase * 0.8, srcHeightBase * 1.2);
360
361 std::uniform_int_distribution<int> rndTop(topPad * 0.8, topPad * 1.2);
362 std::uniform_int_distribution<int> rndBottom(bottomPad * 0.8, bottomPad * 1.2);
363
364 std::uniform_int_distribution<int> rndLeft(leftPad * 0.8, leftPad * 1.2);
365 std::uniform_int_distribution<int> rndRight(rightPad * 0.8, rightPad * 1.2);
366
367 //Prepare input and output buffer
368 std::vector<nvcv::Image> imgSrcVec, imgDstVec;
369 std::vector<std::vector<T>> hImgSrcVec, hImgDstVec, batchGoldVec;
370 std::vector<int> topVec(numBatches);
371 std::vector<int> leftVec(numBatches);
372 for (int i = 0; i < numBatches; ++i)
373 {
374 int srcWidth = rndSrcWidth(randEng);
375 int srcHeight = rndSrcHeight(randEng);
376 int top = rndTop(randEng);
377 int left = rndLeft(randEng);
378 int bottom = rndBottom(randEng);
379 int right = rndRight(randEng);
380
381 int dstWidth = srcWidth + left + right;
382 int dstHeight = srcHeight + top + bottom;
383 topVec[i] = top;
384 leftVec[i] = left;
385 //prepare input buffers
386 imgSrcVec.emplace_back(nvcv::Size2D{srcWidth, srcHeight}, format);
387
388 auto imgSrcData = imgSrcVec.back().exportData<nvcv::ImageDataStridedCuda>();
389 int srcStride = imgSrcData->plane(0).rowStride;
390 int srcRowStride = srcStride / sizeof(T);
391 int srcBufSize = srcRowStride * imgSrcData->plane(0).height;
392
393 std::vector<T> srcVec(srcBufSize);
394 std::uniform_int_distribution<uint8_t> srcRand{0u, 255u};
395 if (std::is_same<T, float>::value)
396 std::generate(srcVec.begin(), srcVec.end(), [&]() { return srcRand(randEng) / 255.0f; });
397 else
398 std::generate(srcVec.begin(), srcVec.end(), [&]() { return srcRand(randEng); });
399
400 // Copy each input image with random data to the GPU
401 ASSERT_EQ(cudaSuccess, cudaMemcpyAsync(imgSrcData->plane(0).basePtr, srcVec.data(), srcBufSize * sizeof(T),
402 cudaMemcpyHostToDevice, stream));
403 hImgSrcVec.push_back(std::move(srcVec));
404
405 //prepare output Buffers
406 imgDstVec.emplace_back(nvcv::Size2D{dstWidth, dstHeight}, format);
407 auto imgDstData = imgDstVec.back().exportData<nvcv::ImageDataStridedCuda>();
408 int dstStride = imgDstData->plane(0).rowStride;

Callers

nothing calls this directly

Calls 12

backMethod · 0.80
CopyMakeBorderFunction · 0.70
emplace_backMethod · 0.45
planeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45
push_backMethod · 0.45
pushBackMethod · 0.45
basePtrMethod · 0.45
sizeMethod · 0.45
rowStrideMethod · 0.45

Tested by

no test coverage detected