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

Function TEST_P

tools/mkop/CppTest.cpp:41–100  ·  view source on GitHub ↗

clang-format on

Source from the content-addressed store, hash-verified

39
40// clang-format on
41TEST_P(Op__OPNAME__, __OPNAME___sanity)
42{
43 cudaStream_t stream;
44 ASSERT_EQ(cudaSuccess, cudaStreamCreate(&stream));
45
46 int width = GetParamValue<0>();
47 int height = GetParamValue<1>();
48 nvcv::ImageFormat format{GetParamValue<2>()};
49 int batches = GetParamValue<3>();
50
51 nvcv::Tensor inTensor = nvcv::util::CreateTensor(batches, width, height, format);
52 nvcv::Tensor outTensor = nvcv::util::CreateTensor(batches, width, height, format);
53
54 auto input = inTensor.exportData<nvcv::TensorDataStridedCuda>();
55 auto output = outTensor.exportData<nvcv::TensorDataStridedCuda>();
56
57 ASSERT_NE(input, nullptr);
58 ASSERT_NE(output, nullptr);
59
60 auto inAccess = nvcv::TensorDataAccessStridedImagePlanar::Create(*input);
61 ASSERT_TRUE(inAccess);
62
63 auto outAccess = nvcv::TensorDataAccessStridedImagePlanar::Create(*output);
64 ASSERT_TRUE(outAccess);
65
66 long inSampleStride = inAccess->numRows() * inAccess->rowStride();
67 long outSampleStride = outAccess->numRows() * outAccess->rowStride();
68
69 int inBufSize = inSampleStride * inAccess->numSamples();
70 int outBufSize = outSampleStride * outAccess->numSamples();
71
72 std::vector<uint8_t> inVec(inBufSize);
73
74 std::vector<uint8_t> goldVec(outBufSize);
75
76 std::default_random_engine randEng(0);
77 std::uniform_int_distribution rand(0u, 255u);
78
79 // TODO populate gold vector with expected results
80 std::generate(goldVec.begin(), goldVec.end(), [&]() { return rand(randEng); });
81 // populate input with random
82 std::generate(inVec.begin(), inVec.end(), [&]() { return rand(randEng); });
83
84 // copy random input to device
85 ASSERT_EQ(cudaSuccess, cudaMemcpy(input->basePtr(), inVec.data(), inBufSize, cudaMemcpyHostToDevice));
86
87 // run operator
88 cvcuda::__OPNAME__ op;
89 EXPECT_NO_THROW(op(stream, inTensor, outTensor));
90
91 ASSERT_EQ(cudaSuccess, cudaStreamSynchronize(stream));
92 ASSERT_EQ(cudaSuccess, cudaStreamDestroy(stream));
93
94 // copy output back to host
95 std::vector<uint8_t> testVec(outBufSize);
96 ASSERT_EQ(cudaSuccess, cudaMemcpy(testVec.data(), output->basePtr(), outBufSize, cudaMemcpyDeviceToHost));
97
98 // TODO make test pass

Callers

nothing calls this directly

Calls 8

CreateTensorFunction · 0.50
numRowsMethod · 0.45
rowStrideMethod · 0.45
numSamplesMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
basePtrMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected