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

Function Gaussian

bench/BenchGaussian.cpp:25–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24template<typename T>
25inline void Gaussian(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 double sigma = state.get_float64("sigma");
31
32 NVCVBorderType borderType = benchutils::GetBorderType(state.get_string("border"));
33
34 int kernelSize = (int)std::round(sigma * (std::is_same_v<nvcv::cuda::BaseType<T>, uint8_t> ? 3 : 4) * 2 + 1) | 1;
35 int2 ksize2{kernelSize, kernelSize};
36
37 nvcv::Size2D kernelSize2{kernelSize, kernelSize};
38 double2 sigma2{sigma, sigma};
39
40 state.add_global_memory_reads(shape.x * shape.y * shape.z * sizeof(T));
41 state.add_global_memory_writes(shape.x * shape.y * shape.z * sizeof(T));
42
43 cvcuda::Gaussian op(kernelSize2, shape.x);
44
45 // clang-format off
46
47 if (varShape < 0) // negative var shape means use Tensor
48 {
49 nvcv::Tensor src({{shape.x, shape.y, shape.z, 1}, "NHWC"}, benchutils::GetDataType<T>());
50 nvcv::Tensor dst({{shape.x, shape.y, shape.z, 1}, "NHWC"}, benchutils::GetDataType<T>());
51
52 benchutils::FillTensor<T>(src, benchutils::RandomValues<T>());
53
54 state.exec(nvbench::exec_tag::sync,
55 [&op, &src, &dst, &kernelSize2, &sigma2, &borderType](nvbench::launch &launch)
56 {
57 op(launch.get_stream(), src, dst, kernelSize2, sigma2, borderType);
58 });
59 }
60 else // zero and positive var shape means use ImageBatchVarShape
61 {
62 nvcv::ImageBatchVarShape src(shape.x);
63 nvcv::ImageBatchVarShape dst(shape.x);
64
65 benchutils::FillImageBatch<T>(src, long2{shape.z, shape.y}, long2{varShape, varShape},
66 benchutils::RandomValues<T>());
67 dst.pushBack(src.begin(), src.end());
68
69 nvcv::Tensor kernelSizeTensor({{shape.x}, "N"}, nvcv::TYPE_2S32);
70 nvcv::Tensor sigmaTensor({{shape.x}, "N"}, nvcv::TYPE_2F64);
71
72 benchutils::FillTensor<int2>(kernelSizeTensor, [&ksize2](const long4_16a &){ return ksize2; });
73 benchutils::FillTensor<double2>(sigmaTensor, [&sigma2](const long4_16a &){ return sigma2; });
74
75 state.exec(nvbench::exec_tag::sync,
76 [&op, &src, &dst, &kernelSizeTensor, &sigmaTensor, &borderType](nvbench::launch &launch)
77 {
78 op(launch.get_stream(), src, dst, kernelSizeTensor, sigmaTensor, borderType);
79 });
80 }
81}
82catch (const std::exception &err)

Callers

nothing calls this directly

Calls 6

GetBorderTypeFunction · 0.85
roundFunction · 0.85
whatMethod · 0.80
pushBackMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected