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

Function MinMaxLoc

bench/BenchMinMaxLoc.cpp:25–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24template<typename T>
25inline void MinMaxLoc(nvbench::state &state, nvbench::type_list<T>)
26try
27{
28 long3 shape = benchutils::GetShape<3>(state.get_string("shape"));
29 long varShape = state.get_int64("varShape");
30 long maxLocs = state.get_int64("maxLocations");
31
32 // clang-format off
33
34 nvcv::Tensor minVal({{shape.x}, "N"}, nvcv::TYPE_U32);
35 nvcv::Tensor minLoc({{shape.x, maxLocs}, "NM"}, nvcv::TYPE_2S32);
36 nvcv::Tensor numMin({{shape.x}, "N"}, nvcv::TYPE_S32);
37
38 nvcv::Tensor maxVal({{shape.x}, "N"}, nvcv::TYPE_U32);
39 nvcv::Tensor maxLoc({{shape.x, maxLocs}, "NM"}, nvcv::TYPE_2S32);
40 nvcv::Tensor numMax({{shape.x}, "N"}, nvcv::TYPE_S32);
41
42 // clang-format on
43
44 // R/W bandwidth rationale:
45 // 1 read to find min/max + 1 read to collect their locations
46 // 2 writes of min/max values (U32), locations (2S32) and quantity (S32)
47 state.add_global_memory_reads(shape.x * shape.y * shape.z * sizeof(T) * 2);
48 state.add_global_memory_writes(shape.x * (sizeof(uint32_t) + maxLocs * sizeof(int2) + sizeof(int)) * 2);
49
50 cvcuda::MinMaxLoc op;
51
52 // clang-format off
53
54 if (varShape < 0) // negative var shape means use Tensor
55 {
56 nvcv::Tensor src({{shape.x, shape.y, shape.z, 1}, "NHWC"}, benchutils::GetDataType<T>());
57
58 benchutils::FillTensorWithMinMax<T>(src, maxLocs);
59
60 state.exec(nvbench::exec_tag::sync,
61 [&op, &src, &minVal, &minLoc, &numMin, &maxVal, &maxLoc, &numMax](nvbench::launch &launch)
62 {
63 op(launch.get_stream(), src, minVal, minLoc, numMin, maxVal, maxLoc, numMax);
64 });
65 }
66 else // zero and positive var shape means use ImageBatchVarShape
67 {
68 nvcv::ImageBatchVarShape src(shape.x);
69
70 benchutils::FillImageBatchWithMinMax<T>(src, long2{shape.z, shape.y}, long2{varShape, varShape}, maxLocs);
71
72 state.exec(nvbench::exec_tag::sync,
73 [&op, &src, &minVal, &minLoc, &numMin, &maxVal, &maxLoc, &numMax](nvbench::launch &launch)
74 {
75 op(launch.get_stream(), src, minVal, minLoc, numMin, maxVal, maxLoc, numMax);
76 });
77 }
78}
79catch (const std::exception &err)
80{
81 state.skip(err.what());
82}

Callers

nothing calls this directly

Calls 1

whatMethod · 0.80

Tested by

no test coverage detected