1

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 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.