| 23 | |
| 24 | template<typename T> |
| 25 | inline void AdaptiveThreshold(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 | int blockSize = static_cast<int>(state.get_int64("blockSize")); |
| 31 | |
| 32 | NVCVThresholdType threshType = NVCV_THRESH_BINARY; |
| 33 | NVCVAdaptiveThresholdType adaptType = NVCV_ADAPTIVE_THRESH_GAUSSIAN_C; |
| 34 | |
| 35 | double maxValue = 123.; |
| 36 | double c = -2.3; |
| 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::AdaptiveThreshold op(blockSize, shape.x); |
| 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, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 48 | nvcv::Tensor dst({{shape.x, shape.y, shape.z, 1}, "NHWC"}, benchutils::GetDataType<T>()); |
| 49 | |
| 50 | benchutils::FillTensor<T>(src, benchutils::RandomValues<T>()); |
| 51 | |
| 52 | state.exec(nvbench::exec_tag::sync, |
| 53 | [&op, &src, &dst, &maxValue, &adaptType, &threshType, &blockSize, &c](nvbench::launch &launch) |
| 54 | { |
| 55 | op(launch.get_stream(), src, dst, maxValue, adaptType, threshType, blockSize, c); |
| 56 | }); |
| 57 | } |
| 58 | else // zero and positive var shape means use ImageBatchVarShape |
| 59 | { |
| 60 | nvcv::ImageBatchVarShape src(shape.x); |
| 61 | nvcv::ImageBatchVarShape dst(shape.x); |
| 62 | |
| 63 | benchutils::FillImageBatch<T>(src, long2{shape.z, shape.y}, long2{varShape, varShape}, |
| 64 | benchutils::RandomValues<T>()); |
| 65 | dst.pushBack(src.begin(), src.end()); |
| 66 | |
| 67 | nvcv::Tensor maxValueTensor({{shape.x}, "N"}, nvcv::TYPE_F64); |
| 68 | nvcv::Tensor blockSizeTensor({{shape.x}, "N"}, nvcv::TYPE_S32); |
| 69 | nvcv::Tensor cTensor({{shape.x}, "N"}, nvcv::TYPE_F64); |
| 70 | |
| 71 | benchutils::FillTensor<double>(maxValueTensor, [&maxValue](const long4_16a &){ return maxValue; }); |
| 72 | benchutils::FillTensor<int>(blockSizeTensor, [&blockSize](const long4_16a &){ return blockSize; }); |
| 73 | benchutils::FillTensor<double>(cTensor, [&c](const long4_16a &){ return c; }); |
| 74 | |
| 75 | state.exec(nvbench::exec_tag::sync, |
| 76 | [&op, &src, &dst, &maxValueTensor, &adaptType, &threshType, &blockSizeTensor, &cTensor] |
| 77 | (nvbench::launch &launch) |
| 78 | { |
| 79 | op(launch.get_stream(), src, dst, maxValueTensor, adaptType, threshType, blockSizeTensor, cTensor); |
| 80 | }); |
| 81 | } |
| 82 | } |