Professional Documents
Culture Documents
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 device
a_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);
}