-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgemm_comm.cu
More file actions
45 lines (42 loc) · 1011 Bytes
/
Copy pathgemm_comm.cu
File metadata and controls
45 lines (42 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <sys/time.h>
double get_walltime()
{
struct timeval tp;
gettimeofday(&tp, NULL);
return (double)(tp.tv_sec + tp.tv_usec * 1e-6);
}
void matrixSerial(float *hostA, float *hostB, float *hostC, int M, int K, int N)
{
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
float tmp = 0;
for (int s = 0; s < K; s++)
{
tmp += hostA[i * K + s] * hostB[s * N + j];
}
hostC[i * N + j] = tmp;
}
}
}
void compare(float *hostC, float *serialC, int M, int N)
{
float error = 0;
bool tmp = true;
for (int i = 0; i < M * N; i++)
{
error = fmax(error, fabs(hostC[i] - serialC[i]));
if (error > 1e-2)
{
tmp = false;
printf("error:hostC[%d] = %.3f, serialC[%d] = %.3f\n", i, hostC[i], i, serialC[i]);
break;
}
}
if (tmp)
{
printf("GPU output all right\n");
}
}