Allocating memory to __device__ variables

Hi, searching around the forum gave parts of answers to this but I wanted to be clear in my own mind. Say I have arrays on the host that I wish to copy to device variables declared and use them in device code e.g.

float _array1[100];

float _array2[100];

__device__ float array1[100];

__device__ float array2[100];

__device__ void update() {

    array1[0]++;

}

How do I allocate memory on the device for the named arrays?

I gather I need to allocate memory to a host pointer using cudaMalloc. What I’m not sure about is then using this pointer and copying the host arrays to the device array symbols.

Edit: I’m doing this to avoid having to pass pointers to the device arrays around the various functions)

You already have. By declaring a static compile-time size for the arrays, they are automatically allocated just like in C.

To copy to/from these arrays on the host, you need to use cudaMemcpyToSymbol. You can also get a pointer with cudaGetSymbolAddress. Search the forums for these functions, this topic has been discussed recently (several times).