| 23 | |
| 24 | template<typename T> |
| 25 | inline void ConvertTo(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 | double alpha = 0.123; |
| 32 | double beta = 0.456; |
| 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::ConvertTo 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, &alpha, &beta](nvbench::launch &launch) |
| 49 | { |
| 50 | op(launch.get_stream(), src, dst, alpha, beta); |
| 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 | |