| 23 | |
| 24 | template<typename T> |
| 25 | inline void Remap(nvbench::state &state, nvbench::type_list<T>) |
| 26 | try |
| 27 | { |
| 28 | long3 srcShape = benchutils::GetShape<3>(state.get_string("shape")); |
| 29 | long varShape = state.get_int64("varShape"); |
| 30 | long3 dstShape = srcShape; |
| 31 | long3 mapShape; |
| 32 | |
| 33 | NVCVInterpolationType srcInterp, mapInterp; |
| 34 | NVCVBorderType borderType; |
| 35 | NVCVRemapMapValueType mapValueType; |
| 36 | |
| 37 | bool alignCorners{true}; |
| 38 | float4 borderValue{0, 0, 0, 0}; |
| 39 | |
| 40 | if (state.get_string("mapType") == "DENSE") |
| 41 | { |
| 42 | srcInterp = NVCV_INTERP_NEAREST; |
| 43 | mapInterp = NVCV_INTERP_NEAREST; |
| 44 | borderType = NVCV_BORDER_CONSTANT; |
| 45 | mapValueType = NVCV_REMAP_ABSOLUTE_NORMALIZED; |
| 46 | mapShape = srcShape; |
| 47 | } |
| 48 | else if (state.get_string("mapType") == "RELATIVE") |
| 49 | { |
| 50 | srcInterp = NVCV_INTERP_CUBIC; |
| 51 | mapInterp = NVCV_INTERP_CUBIC; |
| 52 | borderType = NVCV_BORDER_REFLECT101; |
| 53 | mapValueType = NVCV_REMAP_RELATIVE_NORMALIZED; |
| 54 | mapShape = long3{srcShape.x, 4, 4}; |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | throw std::invalid_argument("Invalid mapType = " + state.get_string("mapType")); |
| 59 | } |
| 60 | |
| 61 | state.add_global_memory_reads(srcShape.x * srcShape.y * srcShape.z * sizeof(T) |
| 62 | + mapShape.x * mapShape.y * mapShape.z * sizeof(float2)); |
| 63 | state.add_global_memory_writes(dstShape.x * dstShape.y * dstShape.z * sizeof(T)); |
| 64 | |
| 65 | cvcuda::Remap op; |
| 66 | |
| 67 | // clang-format off |
| 68 | |
| 69 | nvcv::Tensor map({{mapShape.x, mapShape.y, mapShape.z, 1}, "NHWC"}, nvcv::TYPE_2F32); |
| 70 | |
| 71 | benchutils::FillTensor<float2>(map, benchutils::RandomValues<float2>()); |
| 72 | |
| 73 | if (varShape < 0) // negative var shape means use Tensor |
| 74 | { |
| 75 | nvcv::Tensor src({{srcShape.x, srcShape.y, srcShape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 76 | nvcv::Tensor dst({{dstShape.x, dstShape.y, dstShape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 77 | |
| 78 | benchutils::FillTensor<T>(src, benchutils::RandomValues<T>()); |
| 79 | |
| 80 | state.exec(nvbench::exec_tag::sync, |
| 81 | [&op, &src, &dst, &map, &srcInterp, &mapInterp, &mapValueType, &alignCorners, &borderType, |
| 82 | &borderValue](nvbench::launch &launch) |