CudaPitchedDeviceVariable<byte> throw exception

May 5, 2014 at 4:11 PM
Hi,
i get an exception when i'm executing this code :
using (CudaPitchedDeviceVariable<byte> pitch_data = new CudaPitchedDeviceVariable<byte>(1024, 2048))
{
    pitch_data.CopyToDevice(new byte[1024 * 2048]);
}
The exception is : "ErrorInvalidValue: this indicates that on or more of the parameters passed to the API call is not within an acceptable range of values.

I don't understand why... i just want to create a pichted variable that will contains a byte[] array which have 1024 columns and 2048 rows.
Pitch is supposed to be equal to 1024.

Does someone understand why ?
Coordinator
May 5, 2014 at 4:59 PM
Hi,

the problem is that cuMemAllocPitch requires the alignment size to be either 4, 8 or 16 bytes, whereas taking one single byte gives an alignment size of 1. To circumvent this, CudaPitchedDevicevariable has a second constructor with a "pack"-argument that groups "pack"-count elements to one alignment value. This means if you have a constructor like
CudaPitchedDeviceVariable<byte> pitch_data = new CudaPitchedDeviceVariable<byte>(1024, 2048, 4)
everything is fine as four bytes give now the alignment criterion.
For further details on this, have a look at the description of cuMemAllocPitch and the code in the constructors of CudaPitchedDeviceVaraibale.

Cheers,
Michael