| 23 | |
| 24 | template<typename T> |
| 25 | inline void CustomCrop(nvbench::state &state, nvbench::type_list<T>) |
| 26 | try |
| 27 | { |
| 28 | long3 shape = benchutils::GetShape<3>(state.get_string("shape")); |
| 29 | long varShape = state.get_int64("varShape"); |
| 30 | |
| 31 | // Always crop entire source image for easy bandwidth calculations |
| 32 | NVCVRectI cropRect{0, 0, (int)shape.z, (int)shape.y}; |
| 33 | |
| 34 | state.add_global_memory_reads(shape.x * shape.y * shape.z * sizeof(T)); |
| 35 | state.add_global_memory_writes(shape.x * shape.y * shape.z * sizeof(T)); |
| 36 | |
| 37 | cvcuda::CustomCrop op; |
| 38 | |
| 39 | // clang-format off |
| 40 | |
| 41 | if (varShape < 0) // negative var shape means use Tensor |
| 42 | { |
| 43 | nvcv::Tensor src({{shape.x, shape.y, shape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 44 | nvcv::Tensor dst({{shape.x, shape.y, shape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 45 | |
| 46 | benchutils::FillTensor<T>(src, benchutils::RandomValues<T>()); |
| 47 | |
| 48 | state.exec(nvbench::exec_tag::sync, [&op, &src, &dst, &cropRect](nvbench::launch &launch) |
| 49 | { |
| 50 | op(launch.get_stream(), src, dst, cropRect); |
| 51 | }); |
| 52 | } |
| 53 | else // zero and positive var shape means use ImageBatchVarShape |
| 54 | { |
| 55 | throw std::invalid_argument("ImageBatchVarShape not implemented for this operator"); |
| 56 | } |
| 57 | } |
| 58 | catch (const std::exception &err) |
| 59 | { |
| 60 | state.skip(err.what()); |
| 61 | } |
| 62 | |
| 63 | // clang-format on |
| 64 | |