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