How to allocate cudaArrays? I'm particularly interested in allocating 1D array. After allocation how to access simple elements of it? I read CUDA programming guide but I'm not getting it fully. Can anybody please explain with sample code. Is using cuda1Darray recommended?
1 Answer
cudaArrays are special structures, optimized for texture fetching. You can allocate 1D cudaArray as follows:
cudaArray* arr;
//Create Channel Descriptor. float is just for example. Change it to required data type.
cudaChannelFormatDesc channel = cudaCreateChannelDesc<float>();
//Allocate Memory
cudaMallocArray(&arr,&channel,Number_Of_Elements, 1,cudaArrayDefault);
The width and height is the number of elements in the x and y directions.
In the kernel, the elements of this array can be accessed by using tex1D or tex2D functions. cudaArrays can only be read inside device code using these functions.