copy data which is allocated in device from device to host

I have a pointer which is dynamically allocated in device,then how can I copy it from device to host.
#include <stdio.h>

#define cudaSafeCall(call){
cudaError err = call;
if(cudaSuccess != err){
fprintf(stderr, “%s(%i) : %s.\n”, FILE, LINE, cudaGetErrorString(err));
exit(EXIT_FAILURE);
}}
#define cudaCheckErr(errorMessage) {
cudaError_t err = cudaGetLastError();
if(cudaSuccess != err){
fprintf(stderr, “%s(%i) : %s : (code %d) %s.\n”, FILE, LINE, errorMessage, err, cudaGetErrorString(err));
exit(EXIT_FAILURE);
}}

struct num{
int *a;
int b;
};

device struct num gun;
int main()
{
int i;
char c[100];
struct num dun,cun;
cudaSafeCall(cudaSetDevice(1));
cun=(struct num
)malloc(10
sizeof(struct num));
cudaSafeCall(cudaMalloc(&dun,10
sizeof(struct num)));
cudaSafeCall(cudaMemcpyToSymbol(gun,&dun,sizeof(struct num*)));
global void kernel();
kernel<<<1,10>>>();
cudaSafeCall(cudaDeviceSynchronize());
cudaCheckErr©;
cudaSafeCall(cudaMemcpyFromSymbol(&dun,gun,sizeof(struct num*)));
cudaSafeCall(cudaMemcpy(cun,dun,10sizeof(struct num),cudaMemcpyDeviceToHost));
for(i=0;i<10;i++) cudaSafeCall(cudaMalloc(&csu[i].a,10
sizeof(int)));
cudaSafeCall(cudaGetSymbolAddress((void**)csu[0].a,(void**)gun[0].a));
for(i=0;i<10;i++) cun[i].a=(int*)malloc(10sizeof(int));
for(i=0;i<10;i++) cudaSafeCall(cudaMemcpy(cun[i].a,dun[i].a,10
sizeof(int),cudaMemcpyDeviceToHost));
printf("%d “,cun[8].b);
printf(”%d ",cun[8].a[8]);
cudaSafeCall(cudaFree(dun));
free(cun);
}

global void kernel()
{
int i;
int tid=threadIdx.x;
gun[tid].b=tid;
gun[tid].a=(int*)malloc(10*sizeof(int));//this is dynamically allocated in device.
for(i=0;i<10;i++)
gun[tid].a[i]=tid+i;
}

In this program, it’s always come to a “segmentation fault” in cudaSafeCall(cudaMemcpy(cun[i].a,dun[i].a,10*sizeof(int),cudaMemcpyDeviceToHost)).Why?And what can I do to copy this data from device to host?

I the size of int the same as the size of struct num?

I have solved this problem with someone’s help.I have already copied the pointer,just need to copy the result from device to host.The follow is the web:

http://stackoverflow.com/questions/8322547/copy-data-which-is-allocated-in-device-from-device-to-host/8325871#8325871