| 23 | |
| 24 | template<typename T> |
| 25 | inline void CenterCrop(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 | nvcv::Size2D cropSize; |
| 32 | |
| 33 | if (state.get_string("cropType") == "SAME") |
| 34 | { |
| 35 | cropSize = nvcv::Size2D{(int)srcShape.z, (int)srcShape.y}; |
| 36 | } |
| 37 | else if (state.get_string("cropType") == "QUARTER") |
| 38 | { |
| 39 | cropSize = nvcv::Size2D{(int)srcShape.z / 2, (int)srcShape.y / 2}; |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | throw std::invalid_argument("Invalid resizeType = " + state.get_string("resizeType")); |
| 44 | } |
| 45 | |
| 46 | long3 dstShape{srcShape.x, cropSize.h, cropSize.w}; |
| 47 | |
| 48 | state.add_global_memory_reads(dstShape.x * dstShape.y * dstShape.z * sizeof(T)); |
| 49 | state.add_global_memory_writes(dstShape.x * dstShape.y * dstShape.z * sizeof(T)); |
| 50 | |
| 51 | cvcuda::CenterCrop op; |
| 52 | |
| 53 | // clang-format off |
| 54 | |
| 55 | if (varShape < 0) // negative var shape means use Tensor |
| 56 | { |
| 57 | nvcv::Tensor src({{srcShape.x, srcShape.y, srcShape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 58 | nvcv::Tensor dst({{dstShape.x, dstShape.y, dstShape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 59 | |
| 60 | benchutils::FillTensor<T>(src, benchutils::RandomValues<T>()); |
| 61 | |
| 62 | state.exec(nvbench::exec_tag::sync, [&op, &src, &dst, &cropSize](nvbench::launch &launch) |
| 63 | { |
| 64 | op(launch.get_stream(), src, dst, cropSize); |
| 65 | }); |
| 66 | } |
| 67 | else // zero and positive var shape means use ImageBatchVarShape |
| 68 | { |
| 69 | throw std::invalid_argument("ImageBatchVarShape not implemented for this operator"); |
| 70 | } |
| 71 | } |
| 72 | catch (const std::exception &err) |
| 73 | { |
| 74 | state.skip(err.what()); |
| 75 | } |
| 76 | |
| 77 | // clang-format on |
| 78 | |