| 23 | |
| 24 | template<typename T> |
| 25 | inline void Reformat(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 | state.add_global_memory_reads(shape.x * shape.y * shape.z * sizeof(T)); |
| 32 | state.add_global_memory_writes(shape.x * shape.y * shape.z * sizeof(T)); |
| 33 | |
| 34 | cvcuda::Reformat op; |
| 35 | |
| 36 | // clang-format off |
| 37 | |
| 38 | if (varShape < 0) // negative var shape means use Tensor |
| 39 | { |
| 40 | nvcv::Tensor src({{shape.x, 1, shape.y, shape.z}, "NCHW"}, benchutils::GetDataType<T>()); |
| 41 | nvcv::Tensor dst({{shape.x, shape.y, shape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 42 | |
| 43 | benchutils::FillTensor<T>(src, benchutils::RandomValues<T>()); |
| 44 | |
| 45 | state.exec(nvbench::exec_tag::sync, [&op, &src, &dst](nvbench::launch &launch) |
| 46 | { |
| 47 | op(launch.get_stream(), src, dst); |
| 48 | }); |
| 49 | } |
| 50 | else // zero and positive var shape means use ImageBatchVarShape |
| 51 | { |
| 52 | throw std::invalid_argument("ImageBatchVarShape not implemented for this operator"); |
| 53 | } |
| 54 | } |
| 55 | catch (const std::exception &err) |
| 56 | { |
| 57 | state.skip(err.what()); |
| 58 | } |
| 59 | |
| 60 | // clang-format on |
| 61 | |