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

Function CropFlipNormalizeReformat

bench/BenchCropFlipNormalizeReformat.cpp:25–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24template<typename T>
25inline void CropFlipNormalizeReformat(nvbench::state &state, nvbench::type_list<T>)
26try
27{
28 long3 srcShape = benchutils::GetShape<3>(state.get_string("shape"));
29 long varShape = state.get_int64("varShape");
30 long3 dstShape = srcShape;
31
32 NVCVBorderType borderType = benchutils::GetBorderType(state.get_string("border"));
33
34 float borderValue{0.f};
35
36 float globalScale = 1.234f;
37 float globalShift = 2.345f;
38 float epsilon = 12.34f;
39 uint32_t flags = 0;
40
41 long3 baseShape{srcShape.x, 1, 1};
42 long3 scaleShape{srcShape.x, 1, 1};
43 long3 cropShape{srcShape.x, 1, 1};
44
45 state.add_global_memory_reads(srcShape.x * srcShape.y * srcShape.z * sizeof(T)
46 + baseShape.x * baseShape.y * baseShape.z * sizeof(float)
47 + scaleShape.x * scaleShape.y * scaleShape.z * sizeof(float)
48 + cropShape.x * cropShape.y * cropShape.z * sizeof(int) * 4);
49 state.add_global_memory_writes(dstShape.x * dstShape.y * dstShape.z * sizeof(T));
50
51 cvcuda::CropFlipNormalizeReformat op;
52
53 // clang-format off
54
55 nvcv::Tensor dst({{dstShape.x, dstShape.y, dstShape.z, 1}, "NHWC"}, benchutils::GetDataType<T>());
56
57 nvcv::Tensor flipCode({{srcShape.x}, "N"}, nvcv::TYPE_S32);
58
59 nvcv::Tensor base({{baseShape.x, baseShape.y, baseShape.z, 1}, "NHWC"}, nvcv::TYPE_F32);
60 nvcv::Tensor scale({{scaleShape.x, scaleShape.y, scaleShape.z, 1}, "NHWC"}, nvcv::TYPE_F32);
61
62 nvcv::Tensor crop({{cropShape.x, cropShape.y, cropShape.z, 4}, "NHWC"}, nvcv::TYPE_S32);
63
64 benchutils::FillTensor<int>(flipCode, [](auto &){ return -1; });
65
66 benchutils::FillTensor<float>(base, benchutils::RandomValues<T>());
67 benchutils::FillTensor<float>(scale, benchutils::RandomValues<float>(0.f, 1.f));
68
69 // Always crop entire source image for easy bandwidth calculations
70 benchutils::FillTensor<int>(crop, [&srcShape](const long4_16a &c)
71 {
72 if (c.w == 2)
73 {
74 return (int)srcShape.z;
75 }
76 else if (c.w == 3)
77 {
78 return (int)srcShape.y;
79 }
80 return 0;
81 });
82

Callers

nothing calls this directly

Calls 2

GetBorderTypeFunction · 0.85
whatMethod · 0.80

Tested by

no test coverage detected