Channel Reorder

group Channel Reorder

Functions

NVCVStatus cvcudaChannelReorderCreate(NVCVOperatorHandle *handle)

Constructs an instance of the channel reorder operator. The operator copies input channels to output channels according to an order tensor.

Parameters:

handle[out] Where the image instance handle will be written to.

  • Must not be NULL.

Return values:
  • NVCV_ERROR_INVALID_ARGUMENT – Handle is null.

  • NVCV_ERROR_OUT_OF_MEMORY – Not enough memory to create the operator.

  • NVCV_SUCCESS – Operation executed successfully.

NVCVStatus cvcudaChannelReorderSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVTensorHandle in, NVCVTensorHandle out, const int32_t *order, int32_t orderLength)

Executes channel reorder on a tensor on the given CUDA stream. This operation does not wait for completion.

For every output channel c, the operator copies input channel order[c]. A negative order entry writes zero to the corresponding output channel. Repeated non-negative entries are allowed.

Reference: the non-negative gather mapping matches torchvision.transforms.v2.functional.permute_channels. Native ChannelReorder preserves its established negative-entry zero-fill behavior; callers that need Python negative indexing must normalize those indices before submission.

Limitations:

Input/Output: Data Layout: [kNHWC, kHWC, kNCHW, kCHW] Channels: 1, 2, 3, 4

Data Type

Allowed

8bit Unsigned

Yes

8bit Signed

No

16bit Unsigned

Yes

16bit Signed

Yes

32bit Unsigned

No

32bit Signed

Yes

16bit Float

No

32bit Float

Yes

64bit Float

No

Input and output must have identical shape, layout, data type, and channel count.

Parameters:
  • handle[in] Handle to the operator. Must not be NULL.

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

  • in[in] Input tensor.

  • out[out] Output tensor.

  • order[in] Host pointer to orderLength signed 32-bit channel indices. The values are copied synchronously during this call and may be released after it returns.

  • orderLength[in] Number of entries in order; must equal the tensor channel count.

Return values:
  • NVCV_ERROR_INVALID_ARGUMENT – Some parameter is outside the valid range.

  • NVCV_ERROR_INTERNAL – Internal error in the operator.

  • NVCV_SUCCESS – Operation submitted successfully.

NVCVStatus cvcudaChannelReorderVarShapeSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVImageBatchHandle in, NVCVImageBatchHandle out, NVCVTensorHandle orders_in)

Executes the reformat operation on the given cuda stream. This operation does not wait for completion.

Limitations:

Input: Data Layout: [kNHWC, kHWC, kNCHW, kCHW] Channels: 1, 2, 3, 4

Data Type

Allowed

8bit Unsigned

Yes

8bit Signed

No

16bit Unsigned

Yes

16bit Signed

Yes

32bit Unsigned

No

32bit Signed

Yes

16bit Float

No

32bit Float

Yes

64bit Float

No

Output: Data Layout: [kNHWC, kHWC, kNCHW, kCHW] Channels: 1, 2, 3, 4

Data Type

Allowed

8bit Unsigned

Yes

8bit Signed

No

16bit Unsigned

Yes

16bit Signed

Yes

32bit Unsigned

No

32bit Signed

Yes

16bit Float

No

32bit Float

Yes

64bit Float

No

Input/Output dependency

 Property      |  Input == Output
-------------- | -------------
 Data Layout   | Layout family
 Data Type     | Yes
 Number        | Yes
 Channels      | No

  • Input and output image formats must have the same layout family: interleaved formats have one plane, and planar formats have one plane per channel. Channels can be swizzled (i.e. RGBA8, BGRA8, RGBA8p, BGRA8p, etc).

  • The number of samples in the input and output ImageBatch must be the same

  • The orders_in tensor must have 2 dimensions. First dimension correspond to the number of images being, and the second the number of channels.

Example: let input be RGBA8 with a pixel = [108,63,18,214], output be YUV8, orders_in = [3,-1,1]

The corresponding pixel in the output will be [214,0,63].

  • Must not be NULL.

  • A non-negative order value must be less than the number of channels in the input image. Negative values write zero to the corresponding output channel.

  • Tensor dimensions must be NxC, where N is the number of images in the input varshape, and C is the number of channels in the output images.

Note

The output images’ format isn’t updated to reflect the new channel ordering.

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

    • Must not be NULL.

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

  • in[in] input varshape image batch.

  • out[out] output varshape image batch.

  • orders_in[in] 2D tensor with layout “NC” which specifies, for each output image sample in the batch, the index of the input channel to copy to the output channel. Negative indices will map to ‘0’ value written to the corresponding output channel.

Return values:
  • NVCV_ERROR_INVALID_ARGUMENT – Some parameter is outside valid range.

  • NVCV_ERROR_INTERNAL – Internal error in the operator, invalid types passed in.

  • NVCV_SUCCESS – Operation executed successfully.