NhwcToNchwLetterboxNormalize#

Enumerations#

PVANhwcToNchwLetterboxNormalizePaddingPolicy

Defines how the letterbox padding region of the output tensor is initialized.

Functions#

NVCVStatus pvaNhwcToNchwLetterboxNormalizeCreate(NVCVOperatorHandle *handle, NVCVTensorRequirements const *inTensorReqs, NVCVTensorRequirements const *outTensorReqs, float scale, float padValue, PVANhwcToNchwLetterboxNormalizePaddingPolicy paddingPolicy)

Constructs an instance of the NhwcToNchwLetterboxNormalize operator.

NVCVStatus pvaNhwcToNchwLetterboxNormalizeSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVTensorHandle in, NVCVTensorHandle out)

Submits the NhwcToNchwLetterboxNormalize operator to a CUDA stream.

NVCVStatus pvaNhwcToNchwLetterboxNormalizeSubmit(NVCVOperatorHandle handle, cupvaStream_t stream, NVCVTensorHandle in, NVCVTensorHandle out)

Submits the NhwcToNchwLetterboxNormalize operator to a cuPVA stream.

Enumerations#

enum PVANhwcToNchwLetterboxNormalizePaddingPolicy#

Defines how the letterbox padding region of the output tensor is initialized.

Values:

enumerator PVA_NHWC_TO_NCHW_PADDING_RESTORE_ON_SUBMIT#

The operator writes padValue into the padding region on every submission, before the PVA image-region write and after earlier work on the supplied stream.

The fill is done on the host through the output tensor’s host mapping. On a CUDA stream it is enqueued with cudaLaunchHostFunc() and Submit stays asynchronous. cuPVA has no host-callback command, so on a cuPVA stream Submit submits a fence, waits for earlier stream work to complete, fills the padding and then submits the PVA command; Submit is therefore synchronous with respect to earlier work on that stream.

enumerator PVA_NHWC_TO_NCHW_PADDING_PREFILLED#

The caller initializes the padding region of every output tensor with the padding value before submitting it.

The operator writes only the image region and padValue is unused.

Functions#

NVCVStatus pvaNhwcToNchwLetterboxNormalizeCreate(
NVCVOperatorHandle *handle,
NVCVTensorRequirements const *inTensorReqs,
NVCVTensorRequirements const *outTensorReqs,
float scale,
float padValue,
PVANhwcToNchwLetterboxNormalizePaddingPolicy paddingPolicy,
)#

Constructs an instance of the NhwcToNchwLetterboxNormalize operator.

Converts a single interleaved uint8 RGB image into a planar float32 tensor, centering it in a larger output (letterboxing) and scaling its values. The input must already be resized to imgWidth x imgHeight; the operator does not resize. Given an input of shape [imgHeight, imgWidth, 3] and an output of shape [3, outHeight, outWidth],

padTop  = (outHeight - imgHeight) / 2
padLeft = (outWidth  - imgWidth)  / 2

out[c, y + padTop, x + padLeft] = (float)in[y, x, c] * scale
for 0 <= y < imgHeight, 0 <= x < imgWidth, 0 <= c < 3. Every other output element is padding and holds padValue. An odd leftover row or column goes to the bottom or right padding. No mean or standard-deviation normalization and no channel swap is applied: input channel c is written to output plane c.

Limitations: Both tensors are rank 3 and describe a single image; there is no batch (N) dimension.

  • Input pixels are tightly packed within each row: strides[2] must be 1 and strides[1] must be 3. Rows may be followed by padding: strides[0] must be at least imgWidth * 3.

  • The output tensor must be tightly packed.

  • imgWidth must not exceed outWidth and imgHeight must not exceed outHeight.

  • scale and padValue must be finite.

With PVA_NHWC_TO_NCHW_PADDING_RESTORE_ON_SUBMIT, Submit on a cuPVA stream waits for earlier work on that stream before returning.

Input: Data Layout: [HWC] interleaved Dimensions: imgHeight x imgWidth x 3 Data Type: 8bit Unsigned (NVCV_DATA_TYPE_U8)

Output: Data Layout: [CHW] planar Dimensions: 3 x outHeight x outWidth Data Type: 32bit Float (NVCV_DATA_TYPE_F32)

Parameters:
  • handle – [out] Where the operator instance handle will be written to.

    • Must not be NULL.

  • inTensorReqs – [in] Requirements of the input tensor (imgHeight x imgWidth x 3, U8, HWC).

    • Must not be NULL.

  • outTensorReqs – [in] Requirements of the output tensor (3 x outHeight x outWidth, F32, CHW).

    • Must not be NULL.

  • scale – [in] Multiplier applied to every image pixel (e.g. 1.0 / 255.0).

  • padValue – [in] Value written to padding elements (e.g. 114.0 / 255.0). Unused with PVA_NHWC_TO_NCHW_PADDING_PREFILLED.

  • paddingPolicy – [in] How the padding region is initialized, see PVANhwcToNchwLetterboxNormalizePaddingPolicy.

Return values:
  • NVCV_ERROR_INVALID_ARGUMENT – The possible cases might be the following: 1) handle, inTensorReqs or outTensorReqs is NULL, or points to an invalid address. 2) paddingPolicy is not a PVANhwcToNchwLetterboxNormalizePaddingPolicy value. 3) scale or padValue is not finite. 4) A tensor does not have rank 3, the documented layout or data type, or 3 channels, or has a non-positive extent. 5) The tensors violate a documented limitation above: input larger than the output, an input row pitch below imgWidth * 3, or a non-packed pixel or output layout.

  • NVCV_ERROR_OUT_OF_MEMORY – Not enough memory to create the operator.

  • NVCV_ERROR_INTERNAL – Internal error in the operator.

  • NVCV_SUCCESS – Operation executed successfully.

NVCVStatus pvaNhwcToNchwLetterboxNormalizeSubmit(
NVCVOperatorHandle handle,
cudaStream_t stream,
NVCVTensorHandle in,
NVCVTensorHandle out,
)#

Submits the NhwcToNchwLetterboxNormalize operator to a CUDA stream.

With PVA_NHWC_TO_NCHW_PADDING_RESTORE_ON_SUBMIT this path enqueues the padding fill with cudaLaunchHostFunc(), so it uses the CUDA runtime.

Note

CUDA stream support requirements:

  • PVA SDK 2.7.0 or later

  • Jetpack 7 or later

  • DriveOS 7 or later

  • x86 Emulator is not supported

Parameters:
  • handle – [in] Handle to the operator.

    • Must not be NULL.

  • stream – [in] Handle to a valid CUDA stream.

  • in – [in] Input tensor handle. Must match the input tensor requirements passed to pvaNhwcToNchwLetterboxNormalizeCreate().

    • Must not be NULL.

  • out – [out] Output tensor handle. Must match the output tensor requirements passed to pvaNhwcToNchwLetterboxNormalizeCreate().

    • Must not be NULL.

Return values:
  • NVCV_ERROR_NOT_IMPLEMENTED – CUDA stream submission is not supported on this platform.

  • NVCV_ERROR_INVALID_ARGUMENT – The possible cases might be the following: 1) handle, in or out is NULL, or points to an invalid address. 2) The input or output tensor does not meet the requirements used to create the operator handle.

  • NVCV_ERROR_INTERNAL – Internal error in the operator, including a failure to map the output tensor to the host or to enqueue the padding fill.

  • NVCV_SUCCESS – Operation executed successfully.

NVCVStatus pvaNhwcToNchwLetterboxNormalizeSubmit(
NVCVOperatorHandle handle,
cupvaStream_t stream,
NVCVTensorHandle in,
NVCVTensorHandle out,
)#

Submits the NhwcToNchwLetterboxNormalize operator to a cuPVA stream.

Parameters:
  • handle – [in] Handle to the operator.

    • Must not be NULL.

  • stream – [in] Handle to a valid cuPVA stream.

  • in – [in] Input tensor handle. Must match the input tensor requirements passed to pvaNhwcToNchwLetterboxNormalizeCreate().

    • Must not be NULL.

  • out – [out] Output tensor handle. Must match the output tensor requirements passed to pvaNhwcToNchwLetterboxNormalizeCreate().

    • Must not be NULL.

Return values:
  • NVCV_ERROR_INVALID_ARGUMENT – The possible cases might be the following: 1) handle, in or out is NULL, or points to an invalid address. 2) The input or output tensor does not meet the requirements used to create the operator handle.

  • NVCV_ERROR_INTERNAL – Internal error in the operator, including a failure to map the output tensor to the host or to wait for earlier stream work.

  • NVCV_SUCCESS – Operation executed successfully.