Search code examples
c++cudamemset

Using memset in a CUDA kernel


This seems like an obvious issue, but Google turns up nothing interesting. Is it legal to use memset in a CUDA kernel such as:

__device__ void myKernel()
{
    int array[10];
    memset(array, 0, sizeof(array));
    // ...etc...
}

(I know int array[10] = {0}; is probably better, but this is just an example of a more complicated case.)


Solution

  • Yes, as described in Appendix B of the programming manual, memset, as well as memcpy, malloc, and free (the latter two only on Compute capability >= 2.0 devices) are supported in device code.