| 23 | |
| 24 | template<typename T> |
| 25 | inline void PillowResize(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 | |
| 31 | NVCVInterpolationType interpType = benchutils::GetInterpolationType(state.get_string("interpolation")); |
| 32 | |
| 33 | long3 dstShape; |
| 34 | |
| 35 | if (state.get_string("resizeType") == "EXPAND") |
| 36 | { |
| 37 | dstShape = long3{srcShape.x, srcShape.y * 2, srcShape.z * 2}; |
| 38 | } |
| 39 | else if (state.get_string("resizeType") == "CONTRACT") |
| 40 | { |
| 41 | dstShape = long3{srcShape.x, srcShape.y / 2, srcShape.z / 2}; |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | throw std::invalid_argument("Invalid resizeType = " + state.get_string("resizeType")); |
| 46 | } |
| 47 | |
| 48 | nvcv::Size2D srcSize{(int)srcShape.z, (int)srcShape.y}; |
| 49 | nvcv::Size2D dstSize{(int)dstShape.z, (int)dstShape.y}; |
| 50 | |
| 51 | nvcv::DataType dtype{benchutils::GetDataType<T>()}; |
| 52 | nvcv::ImageFormat fmt(nvcv::MemLayout::PITCH_LINEAR, dtype.dataKind(), nvcv::Swizzle::S_X000, dtype.packing()); |
| 53 | |
| 54 | state.add_global_memory_reads(srcShape.x * srcShape.y * srcShape.z * sizeof(T)); |
| 55 | state.add_global_memory_writes(dstShape.x * dstShape.y * dstShape.z * sizeof(T)); |
| 56 | |
| 57 | cvcuda::PillowResize op; |
| 58 | cvcuda::UniqueWorkspace ws |
| 59 | = cvcuda::AllocateWorkspace(op.getWorkspaceRequirements(srcShape.x, srcSize, dstSize, fmt)); |
| 60 | |
| 61 | // clang-format off |
| 62 | |
| 63 | if (varShape < 0) // negative var shape means use Tensor |
| 64 | { |
| 65 | nvcv::Tensor src({{srcShape.x, srcShape.y, srcShape.z, 1}, "NHWC"}, dtype); |
| 66 | nvcv::Tensor dst({{dstShape.x, dstShape.y, dstShape.z, 1}, "NHWC"}, dtype); |
| 67 | |
| 68 | benchutils::FillTensor<T>(src, benchutils::RandomValues<T>()); |
| 69 | |
| 70 | state.exec(nvbench::exec_tag::sync, [&op, &ws, &src, &dst, &interpType](nvbench::launch &launch) |
| 71 | { |
| 72 | op(launch.get_stream(), ws.get(), src, dst, interpType); |
| 73 | }); |
| 74 | } |
| 75 | else // zero and positive var shape means use ImageBatchVarShape |
| 76 | { |
| 77 | nvcv::ImageBatchVarShape src(srcShape.x); |
| 78 | nvcv::ImageBatchVarShape dst(dstShape.x); |
| 79 | |
| 80 | benchutils::FillImageBatch<T>(src, long2{srcShape.z, srcShape.y}, long2{varShape, varShape}, |
| 81 | benchutils::RandomValues<T>()); |
| 82 | benchutils::FillImageBatch<T>(dst, long2{dstShape.z, dstShape.y}, long2{varShape, varShape}, |
nothing calls this directly
no test coverage detected