#include<stdio.h>
#include<assert.h>
#include<cuda.h>

int main(void) {
float *a_h, *b_h; //host data
float *a_d, *b_d; // device data

int N=5, nBytes, i;

// declaration

nBytes = N*sizeof(float);
a_h = (float *)malloc(nBytes);
b_h = (float *)malloc(nBytes);
cudaMalloc((void **) &a_d, nBytes);
cudaMalloc((void **) &b_d, nBytes);


// set value of a_h

for (i=0;i<N;i++) a_h[i]=100.f * i;
// copy data from host to device
cudaMemcpy(a_d,a_h,nBytes,cudaMemcpyHostToDevice);
// copy data from device to device
cudaMemcpy(b_d,a_d,nBytes,cudaMemcpyDeviceToDevice);
// copy data from device to host
cudaMemcpy(b_h,b_d,nBytes,cudaMemcpyDeviceToHost);

for(i=0;i<N;i++) assert(a_h[i] == b_h[i]);
for (i=0;i<N;i++)
{
printf(" Isi dari variabel a_h adalah %f", a_h[i]);
printf("Isi dari variabel b_h adalah %f \n", b_h[i]);
}

free(a_h);free(b_h);cudaFree(a_d);cudaFree(b_d);

return 0;
}