| 24 | |
| 25 | template<typename T> |
| 26 | inline void BndBox(nvbench::state &state, nvbench::type_list<T>) |
| 27 | try |
| 28 | { |
| 29 | long3 shape = benchutils::GetShape<3>(state.get_string("shape")); |
| 30 | long varShape = state.get_int64("varShape"); |
| 31 | int numBoxes = static_cast<int>(state.get_int64("numBoxes")); |
| 32 | |
| 33 | using BT = typename nvcv::cuda::BaseType<T>; |
| 34 | |
| 35 | int ch = nvcv::cuda::NumElements<T>; |
| 36 | |
| 37 | NVCVBndBoxI bndBox{ |
| 38 | {43, 21, 12, 34}, // box x, y position w, h size |
| 39 | 2, // box thickness |
| 40 | { 0, 0, 0, 255}, // box border color |
| 41 | { 0, 0, 0, 0} // box fill color |
| 42 | }; |
| 43 | |
| 44 | std::vector<std::vector<NVCVBndBoxI>> bndBoxesVec; |
| 45 | |
| 46 | for (int i = 0; i < shape.x; i++) |
| 47 | { |
| 48 | std::vector<NVCVBndBoxI> curVec; |
| 49 | for (int j = 0; j < numBoxes; j++) |
| 50 | { |
| 51 | curVec.push_back(bndBox); |
| 52 | } |
| 53 | bndBoxesVec.push_back(curVec); |
| 54 | } |
| 55 | |
| 56 | std::shared_ptr<cvcuda::priv::NVCVBndBoxesImpl> bndBoxesImpl |
| 57 | = std::make_shared<cvcuda::priv::NVCVBndBoxesImpl>(bndBoxesVec); |
| 58 | NVCVBndBoxesI bndBoxes = (NVCVBndBoxesI)bndBoxesImpl.get(); |
| 59 | |
| 60 | state.add_global_memory_reads(shape.x * shape.y * shape.z * sizeof(T) + shape.x * numBoxes * sizeof(NVCVBndBoxI)); |
| 61 | state.add_global_memory_writes(shape.x * shape.y * shape.z * sizeof(T)); |
| 62 | |
| 63 | cvcuda::BndBox op; |
| 64 | |
| 65 | // clang-format off |
| 66 | |
| 67 | if (varShape < 0) // negative var shape means use Tensor |
| 68 | { |
| 69 | nvcv::Tensor src({{shape.x, shape.y, shape.z, ch}, "NHWC"}, benchutils::GetDataType<BT>()); |
| 70 | nvcv::Tensor dst({{shape.x, shape.y, shape.z, ch}, "NHWC"}, benchutils::GetDataType<BT>()); |
| 71 | |
| 72 | benchutils::FillTensor<BT>(src, benchutils::RandomValues<BT>()); |
| 73 | |
| 74 | state.exec(nvbench::exec_tag::sync, [&op, &src, &dst, &bndBoxes](nvbench::launch &launch) |
| 75 | { |
| 76 | op(launch.get_stream(), src, dst, bndBoxes); |
| 77 | }); |
| 78 | } |
| 79 | else // zero and positive var shape means use ImageBatchVarShape |
| 80 | { |
| 81 | throw std::invalid_argument("ImageBatchVarShape not implemented for this operator"); |
| 82 | } |
| 83 | } |