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

Function OSD

bench/BenchOSD.cpp:26–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25template<typename T>
26inline void OSD(nvbench::state &state, nvbench::type_list<T>)
27try
28{
29 long3 shape = benchutils::GetShape<3>(state.get_string("shape"));
30 long varShape = state.get_int64("varShape");
31 int numElem = static_cast<int>(state.get_int64("numElem"));
32
33 int ch = nvcv::cuda::NumElements<T>;
34
35 using BT = nvcv::cuda::BaseType<T>;
36
37 std::vector<std::vector<std::shared_ptr<cvcuda::priv::NVCVElement>>> elementVec;
38
39 for (int n = 0; n < (int)shape.x; n++)
40 {
41 std::vector<std::shared_ptr<cvcuda::priv::NVCVElement>> curVec;
42 for (int i = 0; i < numElem; i++)
43 {
44 NVCVPoint point;
45 point.centerPos.x = shape.z / 2;
46 point.centerPos.y = shape.y / 2;
47 point.radius = std::min(shape.z, shape.y) / 2;
48 point.color = {0, 0, 0, 255};
49 auto element = std::make_shared<cvcuda::priv::NVCVElement>(NVCVOSDType::NVCV_OSD_POINT, &point);
50 curVec.push_back(element);
51 }
52 elementVec.push_back(curVec);
53 }
54
55 std::shared_ptr<cvcuda::priv::NVCVElementsImpl> ctx = std::make_shared<cvcuda::priv::NVCVElementsImpl>(elementVec);
56
57 state.add_global_memory_reads(shape.x * shape.y * shape.z * sizeof(T) + numElem * sizeof(int) * 16);
58 state.add_global_memory_writes(shape.x * shape.y * shape.z * sizeof(T));
59
60 cvcuda::OSD op;
61
62 // clang-format off
63
64 if (varShape < 0) // negative var shape means use Tensor
65 {
66 nvcv::Tensor src({{shape.x, shape.y, shape.z, ch}, "NHWC"}, benchutils::GetDataType<BT>());
67 nvcv::Tensor dst({{shape.x, shape.y, shape.z, ch}, "NHWC"}, benchutils::GetDataType<BT>());
68
69 benchutils::FillTensor<BT>(src, benchutils::RandomValues<BT>());
70
71 state.exec(nvbench::exec_tag::sync, [&op, &src, &dst, &ctx](nvbench::launch &launch)
72 {
73 op(launch.get_stream(), src, dst, (NVCVElements)ctx.get());
74 });
75 }
76 else // zero and positive var shape means use ImageBatchVarShape
77 {
78 throw std::invalid_argument("ImageBatchVarShape not implemented for this operator");
79 }
80}
81catch (const std::exception &err)
82{
83 state.skip(err.what());

Callers

nothing calls this directly

Calls 4

minFunction · 0.85
whatMethod · 0.80
push_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected