X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/book_gpu.git/blobdiff_plain/4eb0d6980c190aa2e92700dd01c5f685405590bd..90d91fb64c1709967149c2753ee59db047eb5543:/BookGPU/Chapters/chapter2/ex3.cu?ds=sidebyside diff --git a/BookGPU/Chapters/chapter2/ex3.cu b/BookGPU/Chapters/chapter2/ex3.cu index fbdf3a2..cddcc30 100644 --- a/BookGPU/Chapters/chapter2/ex3.cu +++ b/BookGPU/Chapters/chapter2/ex3.cu @@ -6,16 +6,12 @@ #include "cutil_inline.h" #include - const int width=16; const int nbTh=width*width; const int size=1024; const int sizeMat=size*size; - - - __global__ void matmul(float *d_A, float *d_B, float *d_C) { int i= blockIdx.y*blockDim.y+ threadIdx.y; @@ -26,15 +22,10 @@ void matmul(float *d_A, float *d_B, float *d_C) { sum+=d_A[i*size+k]*d_B[k*size+j]; } d_C[i*size+j]=sum; - } - - - int main( int argc, char** argv) { - float *h_arrayA=(float*)malloc(sizeMat*sizeof(float)); float *h_arrayB=(float*)malloc(sizeMat*sizeof(float)); float *h_arrayC=(float*)malloc(sizeMat*sizeof(float)); @@ -46,9 +37,7 @@ int main( int argc, char** argv) cudaMalloc((void**)&d_arrayB,sizeMat*sizeof(float)); cudaMalloc((void**)&d_arrayC,sizeMat*sizeof(float)); - srand48(32); - for(int i=0;i>>(d_arrayA,d_arrayB,d_arrayC); cudaThreadSynchronize(); @@ -100,12 +81,10 @@ int main( int argc, char** argv) cudaMemcpy(h_arrayCgpu,d_arrayC, sizeMat * sizeof(float), cudaMemcpyDeviceToHost); - int good=1; for(int i=0;i1e-4) printf("%f %f\n",h_arrayC[i],h_arrayCgpu[i]); - cudaFree(d_arrayA); cudaFree(d_arrayB); cudaFree(d_arrayC); @@ -113,7 +92,5 @@ int main( int argc, char** argv) free(h_arrayB); free(h_arrayC); free(h_arrayCgpu); - return 0; - }