| 32 | |
| 33 | namespace { |
| 34 | Tensor MorphologyInto(Tensor &output, Tensor &input, NVCVMorphologyType morph_type, |
| 35 | const std::tuple<int, int> &maskSize, const std::tuple<int, int> &anchor, |
| 36 | std::optional<Tensor> workspace, int32_t iteration, NVCVBorderType border, |
| 37 | std::optional<Stream> pstream) |
| 38 | { |
| 39 | if (!pstream) |
| 40 | { |
| 41 | pstream = Stream::Current(); |
| 42 | } |
| 43 | |
| 44 | auto morphology = CreateOperator<cvcuda::Morphology>(); |
| 45 | |
| 46 | ResourceGuard guard(*pstream); |
| 47 | guard.add(LockMode::LOCK_MODE_READ, {input}); |
| 48 | guard.add(LockMode::LOCK_MODE_WRITE, {output}); |
| 49 | guard.add(LockMode::LOCK_MODE_NONE, {*morphology}); |
| 50 | |
| 51 | nvcv::Size2D maskSizeArg{std::get<0>(maskSize), std::get<1>(maskSize)}; |
| 52 | int2 anchorArg; |
| 53 | anchorArg.x = std::get<0>(anchor); |
| 54 | anchorArg.y = std::get<1>(anchor); |
| 55 | |
| 56 | if (workspace) |
| 57 | { |
| 58 | guard.add(LockMode::LOCK_MODE_READ, {*workspace}); |
| 59 | morphology->submit(pstream->cudaHandle(), input, output, *workspace, morph_type, maskSizeArg, anchorArg, |
| 60 | iteration, border); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | morphology->submit(pstream->cudaHandle(), input, output, nvcv::NullOpt, morph_type, maskSizeArg, anchorArg, |
| 65 | iteration, border); |
| 66 | } |
| 67 | |
| 68 | return output; |
| 69 | } |
| 70 | |
| 71 | Tensor Morphology(Tensor &input, NVCVMorphologyType morph_type, const std::tuple<int, int> &maskSize, |
| 72 | const std::tuple<int, int> &anchor, std::optional<Tensor> workspace, int32_t iteration, |
no test coverage detected