Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
addmatrix.cu

addmatrix.cu

Ratings: (0)|Views: 36|Likes:
Published by Farhan Ahmad
CUDA C program for adding two matrices.
CUDA C program for adding two matrices.

More info:

Categories:Types, School Work
Published by: Farhan Ahmad on Oct 04, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

01/10/2011

pdf

text

original

 
#include<stdio.h>#include<cuda.h>#include<conio.h> __global__voidaddmatrix(float*a,float*b,float*c){intidx=threadIdx.x;c[idx]=a[idx]+b[idx];}intmain(){float**a_h,**b_h,**c_h;float*a_d,*b_d,*c_d;introw,col,i,j;printf("Enterthesize(rowsspacecol)ofthematrix>>");scanf("%d%d",&row,&col);size_tsize=row*sizeof(float);//sizecalculationforthedevice//memoryallocationforthehostdevicea_h=(float**)malloc(sizeof(float*)*row);for(i=0;i<col;i++){a_h[i]=(float*)malloc(sizeof(float)*col);}b_h=(float**)malloc(sizeof(float*)*row);for(i=0;i<col;i++){b_h[i]=(float*)malloc(sizeof(float)*col);}c_h=(float**)malloc(sizeof(float*)*row);for(i=0;i<col;i++){c_h[i]=(float*)malloc(sizeof(float)*col);}//memoryallocationonDRAMofdevicecudaMalloc((void**)&a_d,size);cudaMalloc((void**)&b_d,size);cudaMalloc((void**)&c_d,size);//datainputforthearraysprintf("Enterthefirstmatrix\n");for(i=0;i<row;i++){for(j=0;j<col;j++){printf("Enterthea_h[%d][%d]>>",i,j);scanf("%f",&a_h[i][j]);}}printf("Enterthesecondmatrix\n");for(i=0;i<row;i++){for(j=0;j<col;j++){

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->