Why am I getting a warning about cudaMemcpyToArray(...) being deprecated?

Viewed 377

What is this warning and how can I fix it?

warning: ‘cudaError_t cudaMemcpyToArray(cudaArray_t, size_t, size_t, const void*, size_t, cudaMemcpyKind)’ is deprecated [-Wdeprecated-declarations]
1 Answers

Deprecated means it is not recommended for use, and the support for it may be dropped in the very next CUDA release.

A description of what to do about it is given here.

For a typical usage where you are copying an entire allocation from host to device, and the source (host) allocation is a flat (unpitched) allocation of width w elements by height h rows, perhaps something like this:

cudaMemcpyToArray(dst, 0, 0, src, h*w*sizeof(src[0]), cudaMemcpyHostToDevice)

You would replace it with:

cudaMemcpy2DToArray(dst, 0, 0, src, w*sizeof(src[0]) , w*sizeof(src[0]), h, cudaMemcpyHostToDevice);

The replacement API (cudaMemcpy2DToArray) is documented here.

Note that in the example that I have given, if you have no sense of a "2D" allocation consisting of rows and columns, but instead have a single flat allocation of (let's say) w elements, you can simply set h=1 in the formulation above.

Related