| 28 | namespace { |
| 29 | |
| 30 | Tensor HistogramInto(Tensor &histogram, Tensor &input, std::optional<Tensor> mask, std::optional<Stream> pstream) |
| 31 | { |
| 32 | if (!pstream) |
| 33 | { |
| 34 | pstream = Stream::Current(); |
| 35 | } |
| 36 | |
| 37 | if (mask) |
| 38 | { |
| 39 | if (mask->shape() != input.shape()) |
| 40 | { |
| 41 | throw std::invalid_argument("Mask must have the same shape as input"); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | auto op = CreateOperator<cvcuda::Histogram>(); |
| 46 | |
| 47 | ResourceGuard guard(*pstream); |
| 48 | guard.add(LockMode::LOCK_MODE_READ, {input}); |
| 49 | guard.add(LockMode::LOCK_MODE_WRITE, {histogram}); |
| 50 | guard.add(LockMode::LOCK_MODE_NONE, {*op}); |
| 51 | |
| 52 | if (mask) |
| 53 | { |
| 54 | guard.add(LockMode::LOCK_MODE_READ, {*mask}); |
| 55 | op->submit(pstream->cudaHandle(), input, *mask, histogram); |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | op->submit(pstream->cudaHandle(), input, nvcv::NullOpt, histogram); |
| 60 | } |
| 61 | return std::move(histogram); |
| 62 | } |
| 63 | |
| 64 | Tensor Histogram(Tensor &input, std::optional<Tensor> mask, std::optional<Stream> pstream) |
| 65 | { |
no test coverage detected