| 23 | |
| 24 | template<typename T> |
| 25 | inline void ChannelReorder(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::ChannelReorder op; |
| 35 | |
| 36 | // clang-format off |
| 37 | |
| 38 | nvcv::Tensor orders({{shape.x, 4}, "NC"}, nvcv::TYPE_S32); |
| 39 | |
| 40 | benchutils::FillTensor<int>(orders, benchutils::RandomValues<int>(0, nvcv::cuda::NumElements<T>)); |
| 41 | |
| 42 | if (varShape < 0) // negative var shape means use Tensor |
| 43 | { |
| 44 | throw std::invalid_argument("Tensor not implemented for this operator"); |
| 45 | } |
| 46 | else // zero and positive var shape means use ImageBatchVarShape |
| 47 | { |
| 48 | nvcv::ImageBatchVarShape src(shape.x); |
| 49 | nvcv::ImageBatchVarShape dst(shape.x); |
| 50 | |
| 51 | benchutils::FillImageBatch<T>(src, long2{shape.z, shape.y}, long2{varShape, varShape}, |
| 52 | benchutils::RandomValues<T>()); |
| 53 | dst.pushBack(src.begin(), src.end()); |
| 54 | |
| 55 | state.exec(nvbench::exec_tag::sync, [&op, &src, &dst, &orders](nvbench::launch &launch) |
| 56 | { |
| 57 | op(launch.get_stream(), src, dst, orders); |
| 58 | }); |
| 59 | } |
| 60 | } |
| 61 | catch (const std::exception &err) |
| 62 | { |
| 63 | state.skip(err.what()); |
| 64 | } |
| 65 | |
| 66 | // clang-format on |
| 67 | |