-
Notifications
You must be signed in to change notification settings - Fork 80
CudaDeviceVariable
Michael Kunz edited this page Aug 1, 2015
·
3 revisions
A CudaDeviceVariable (and its variations) object represents allocated memory on the device. The class knows about the exact memory layout (as array length, array dimension, memory pitch, etc.). As the class is a generic, it also knows about its type and type size. All this simplifies dramatically any data copying as no size parameters are needed. Only the source or destination array must be defined (either a default C# host array or another device variable). Device memory is freed as soon as the CudaDeviceVariable object is disposed.
Example code:
CudaDeviceVariable<float> data_d = new CudaDeviceVariable<float>(256);
float[] data_h = new float[256];
for (int i = 0; i < 256; i++)
{
data_h[i] = i;
}
data_d.CopyToDevice(data_h);
//using direct assignments:
float[] data2_h = new float[256];
for (int i = 0; i < 256; i++)
{
data2_h[i] = i;
}
CudaDeviceVariable<float> data2_d = data2_h;
//access elements directly:
float value = data_d[5];
data_d[5] = value - 1.0f;