| 23 | |
| 24 | template<typename ST> |
| 25 | inline void Label(nvbench::state &state, nvbench::type_list<ST>) |
| 26 | try |
| 27 | { |
| 28 | using DT = uint32_t; |
| 29 | |
| 30 | long3 srcShape = benchutils::GetShape<3>(state.get_string("shape")); |
| 31 | long3 dstShape = srcShape; |
| 32 | |
| 33 | std::string runChoice = state.get_string("runChoice"); |
| 34 | |
| 35 | // Use [BG][MIN][MAX][ISLAND][COUNT][STAT][MASK] in runChoice to run Label with: |
| 36 | // background; minThreshold; maxThreshold; island removal; count; statistics; mask |
| 37 | |
| 38 | long3 staShape{srcShape.x, 10000, 7}; // using fixed 10K max. cap. and 2D problem |
| 39 | |
| 40 | NVCVConnectivityType conn = NVCV_CONNECTIVITY_4_2D; |
| 41 | NVCVLabelType alab = NVCV_LABEL_FAST; |
| 42 | NVCVLabelMaskType mType = NVCV_REMOVE_ISLANDS_OUTSIDE_MASK_ONLY; |
| 43 | |
| 44 | nvcv::Tensor bgT, minT, maxT, countT, statsT, mszT, maskT; |
| 45 | |
| 46 | cvcuda::Label op; |
| 47 | |
| 48 | state.add_global_memory_reads(srcShape.x * srcShape.y * srcShape.z * sizeof(ST)); |
| 49 | state.add_global_memory_writes(dstShape.x * dstShape.y * dstShape.z * sizeof(DT)); |
| 50 | |
| 51 | // clang-format off |
| 52 | |
| 53 | if (runChoice.find("BG") != std::string::npos) |
| 54 | { |
| 55 | bgT = nvcv::Tensor({{srcShape.x}, "N"}, benchutils::GetDataType<ST>()); |
| 56 | |
| 57 | benchutils::FillTensor<ST>(bgT, benchutils::RandomValues<ST>()); |
| 58 | } |
| 59 | if (runChoice.find("MIN") != std::string::npos) |
| 60 | { |
| 61 | minT = nvcv::Tensor({{srcShape.x}, "N"}, benchutils::GetDataType<ST>()); |
| 62 | |
| 63 | benchutils::FillTensor<ST>(minT, benchutils::RandomValues<ST>()); |
| 64 | } |
| 65 | if (runChoice.find("MAX") != std::string::npos) |
| 66 | { |
| 67 | maxT = nvcv::Tensor({{srcShape.x}, "N"}, benchutils::GetDataType<ST>()); |
| 68 | |
| 69 | benchutils::FillTensor<ST>(maxT, benchutils::RandomValues<ST>()); |
| 70 | } |
| 71 | if (runChoice.find("ISLAND") != std::string::npos) |
| 72 | { |
| 73 | mszT = nvcv::Tensor({{srcShape.x}, "N"}, benchutils::GetDataType<DT>()); |
| 74 | |
| 75 | benchutils::FillTensor<DT>(mszT, benchutils::RandomValues<DT>()); |
| 76 | } |
| 77 | if (runChoice.find("COUNT") != std::string::npos) |
| 78 | { |
| 79 | countT = nvcv::Tensor({{srcShape.x}, "N"}, benchutils::GetDataType<DT>()); |
| 80 | } |
| 81 | if (runChoice.find("STAT") != std::string::npos) |
| 82 | { |