#include <iostream>
#include <cuda.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
using namespace std;

__global__ void kernel_gpu(int *A0,int N){
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < N){
A0[i] = A0[i];
}
}

void kernel_cpu(int *A0,int N){
for(int i=0;i<N;i++){
A0[i] = A0[i];
}
}

int main(int argc,char **argv) {
fprintf(stderr, "769 ");
int size=658857;
int intBytes = size*sizeof(int);
int floatBytes = size*sizeof(float);
int *A0;
A0 = (int *)malloc(intBytes);
for(int i=0;i<658857;i++){
A0[i] = 47+i+1;
}
int *d_A0;
cudaMalloc((void **)&d_A0,658857*sizeof(int));
cudaMemcpy(d_A0,A0,658857*sizeof(int),cudaMemcpyHostToDevice);
int n = 2574*256;
int block_size = 256;
int block_no = n/block_size;
struct timeval time0,time1;
gettimeofday(&time0,NULL);
kernel_gpu<<<block_no,block_size>>>(d_A0,658857);
cudaThreadSynchronize();
gettimeofday(&time1,NULL);
double totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
fprintf(stderr, "GPU time: %lf msecs ",  (totaltime10)/1000.0F);
gettimeofday(&time0,NULL);
kernel_cpu(A0,658857);
gettimeofday(&time1,NULL);
totaltime10 = (time1.tv_sec*1000000.0 + time1.tv_usec) - (time0.tv_sec*1000000.0 + time0.tv_usec);
fprintf(stderr, "CPU time: %lf msecs ",  (totaltime10)/1000.0F);
int *testA0;
testA0 = (int *)malloc(intBytes);
cudaMemcpy(testA0,d_A0,658857*sizeof(int),cudaMemcpyDeviceToHost);
for(int i=0;i<658857;i++){
if (A0[i] != testA0[i]) {
printf("Invalid kernel ");
break;}
}
free(A0);
free(testA0);
cudaFree(d_A0);
printf("\n");return 0; }