Documente Academic
Documente Profesional
Documente Cultură
h>
#include<conio.h>
#include<cuda.h>
__global__ void mulmatrix(float *first , float *second , float *result ,int widt
h1 ,int width2)
{
int idx = threadIdx.x;
int idy = threadIdx.y;
int k ;
float a ,b ,sum;
sum = 0;
for(k=0;k<width1;k++)
{
a = first[idy*width1+k];
b = second[k*(width2)+idx];
sum = sum + (a*b);
}
result[idy*(width2)+idx] = sum;
}
void main()
{
float *a_h, *b_h , *c_h ,*a_d,*b_d,*c_d;
int width1, width2 , row1,col1,row2,col2;
printf("Enter the size of the first matrix>>");
scanf("%d %d",&row1,&col1);
printf("Enter the size of the second matrix>>");
scanf("%d %d",&row2,&col2);
//memory allocation on the host
a_h =(float*)malloc(sizeof(float)*row1*col1);
b_h =(float*)malloc(sizeof(float)*row2*col2);
c_h =(float*)malloc(sizeof(float)*row1*col2);