cudaMemcpy image data with conversion from HWC to CHW

Viewed 496

Imagine that we have some OpenCV usual image Mat:

cv::Mat usual_image = cv::imread(...)

This image stored as HWC/NHWC array in memory.

If that possible to copy this image as CHW/NCHW (separated channel arrays, in sense) into cuda memory without super high cost cv::split?

Just for visualization HWC and CHW: Just for visualization

1 Answers

The fastest way to do this will be to copy the image as-is to the GPU, then write a GPU kernel to split the data into 3 buffers.

A slower alternative would be to use 3 calls to cudaMemcpy2D to copy the data from host to device, one call per plane.

Related