Casting float* to char* while looping over a 2-D array in linear memory on device

后端 未结 3 1798
慢半拍i
慢半拍i 2021-01-14 03:46

On Page 21 of the CUDA 4.0 programming guide there is an example (given below) to illustrate looping over the elements of a 2D array of floats in device memory. The dimensi

3条回答
  •  执笔经年
    2021-01-14 04:35

    The cast is just to make the pointer arithmetic work right;

    (float*)((char*)devPtr + r * pitch);
    

    moves r*pitch bytes forward while

    (float*)(devPtr + r * pitch);
    

    would move r*pitch floats forward (ie 4 times as many bytes)

提交回复
热议问题