NmsVpu#

Fully qualified name: pvaApl::NmsVpu

Defined in public/src/primitive/pvaAplNmsVpu.hpp

template<int32_t NmsSize, typename DataType>
class NmsVpu#

Non-Maximum Suppression (NMS) primitive template class.

For every pixel of the valid output region an NmsSize x NmsSize window centered on that pixel is searched. If the pixel is the maximum of the window it is copied to the output, otherwise the output pixel is set to zero. Ties are resolved by position: among equal maxima within the window, the pixel that appears last in raster order (left to right, top to bottom) wins, that is, the one with the largest row index and, if those are equal, the largest column index. A rectangular plateau of equal values therefore leaves exactly one surviving pixel, at its bottom-right corner, rather than keeping all of them.

Note

The center is never the bottom-right pixel of its own window, so it loses every tie and a constant tile I(y, x) = k produces an all-zero output. A gradient tile I(y, x) = x does too, because the window always reaches a larger value to the right.

Note

The tie-break is implemented by biasing each tap by its rank in the window, so the decision is exact only where the center differs from every other pixel of its window by more than B = (NmsSize * NmsSize - 1) / 2 (4 for 3x3, 12 for 5x5). Within that margin it can err in either direction: a lower neighbor can suppress the center, or a higher one can fail to.

Note

The output is NmsSize - 1 pixels smaller than the input in both dimensions and offset by NmsSize / 2, i.e. output(0, 0) corresponds to input(NmsSize / 2, NmsSize / 2). Callers wanting a full-size result must supply a halo of NmsSize / 2 around the region they want.

Template Parameters:
  • NmsSize – Suppression window size. (Square shape: NmsSize x NmsSize) Must be 3 or 5.

  • DataType – Input/output data type. Must be int32_t.

Public Functions

inline void Update(DataType *input, DataType *output)#

Update the input and output buffer pointers for the Nms algorithm.

Parameters:
  • input – Pointer to the input buffer. Points at the top-left of the padded region, not at the first valid output pixel.

  • output – Pointer to the output buffer where the result is written to.

inline void Init(
DataType *input,
int32_t width,
int32_t height,
int32_t inputLinePitch,
int32_t outputLinePitch,
DataType *output,
DataType *cbStart,
int32_t cbLen,
DataType *scratch,
)#

Initialize the Nms algorithm parameters, setup agens for the Execute method.

Preconditions, none of which are checked at run time:

  • width >= NmsSize - 1 and height >= NmsSize - 1, both <= 0xFFFF.

  • inputLinePitch and outputLinePitch are in elements, >= 0 and <= 0xFFFF.

  • outputLinePitch >= width - (NmsSize - 1).

  • output holds height - (NmsSize - 1) rows rounded up to a multiple of 16, because the inner loops over-run to the unroll factor and rely on agen wraparound.

  • scratch holds at least ScratchElements(width, height) DataType elements.

  • input is reachable by agen port A, scratch by port C and output by port B, so they must be placed in the matching VMEM superbanks.

  • when the input is a circular buffer, cbStart / cbLen describe the whole ring and input points somewhere inside it; both source agens then wrap, so a tile whose rows straddle the end of the ring is read correctly.

Parameters:
  • input – Pointer to the input buffer, at the top-left of the padded region.

  • width – Input tile width in pixels.

  • height – Input tile height in pixels.

  • inputLinePitch – Line pitch of the input buffer in elements.

  • outputLinePitch – Line pitch of the output buffer in elements.

  • output – Pointer to the output buffer where the result is written to.

  • cbStart – Base of the input circular buffer, or nullptr when the input is not circular.

  • cbLen – Length of the input circular buffer in elements, or 0 when not circular.

  • scratch – Pointer to the intermediate buffer holding the horizontal pass result.

inline void Execute()#

Execute the Nms algorithm: horizontal pass followed by vertical pass.

Public Static Functions

static inline constexpr int32_t ScratchElements(
int32_t width,
int32_t height,
)#

Number of DataType elements the scratch buffer must hold for a given input tile size.

Parameters:
  • width – Input tile width in pixels.

  • height – Input tile height in pixels.

Returns:

Required scratch element count.

Public Static Attributes

static constexpr int32_t Radius = kRadius#

Half window size, i.e.

the halo the caller must supply around the valid output region.