swapping pointers

Hey guys, I’m having some issues successfully swapping pointers within a kernel.

I allocated two char arrays (for input and output) on the device using cudaMemAlloc() and passing the two arrays to a kernel. I plan on doing a time-stepping calculation, so using the input array to set values in the output. After the iteration, I want to swap the in and out array [so the output of the first call becomes the input of the second]. I have something, but it’s not working [of course]:

// main:

check_error(cudaMalloc((void **) & g_in, size*size*sizeof(char)));

check_error(cudaMalloc((void **) & g_out, size*size*sizeof(char)));

kernel <<< gridDims, threadDims >>> (g_in,g_out,size);

__device__ void swap(char **x, char **y) {

	char *t = *x;

	*x = *y;

	*y = t;

}

__global__ kernel(char *in, char *out,int size)

{

	int i = (blockDim.x * blockIdx.x) + threadIdx.x, j = (blockDim.y * blockIdx.y) + threadIdx.y;

	if (i < 0 || i >= size || j < 0 || j >= size) return; 

	int index = i*size+j, g;

	for (g = 0; g < 10; g++)

	{

		out[index] = g;

		swap(&in,&out);

	}

}

Any ideas? Thanks in advance.