-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsupport.cu
More file actions
43 lines (34 loc) · 1.05 KB
/
support.cu
File metadata and controls
43 lines (34 loc) · 1.05 KB
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
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "support.h"
void verify(float *A, float *B, float *C, unsigned int m, unsigned int k,
unsigned int n) {
const float relativeTolerance = 1e-6;
for(int row = 0; row < m; ++row) {
for(int col = 0; col < n; ++col) {
float sum = 0;
for(unsigned int i = 0; i < k; ++i) {
sum += A[row*k + i]*B[i*n + col];
}
float relativeError = (sum - C[row*n + col])/sum;
if (relativeError > relativeTolerance
|| relativeError < -relativeTolerance) {
printf("(%d, %d) = %f, supposed to be %f\n", row, col, C[row*n + col], sum);
printf("TEST FAILED\n\n");
exit(0);
}
}
}
printf("TEST PASSED\n\n");
}
void startTime(Timer* timer) {
gettimeofday(&(timer->startTime), NULL);
}
void stopTime(Timer* timer) {
gettimeofday(&(timer->endTime), NULL);
}
float elapsedTime(Timer timer) {
return ((float) ((timer.endTime.tv_sec - timer.startTime.tv_sec) \
+ (timer.endTime.tv_usec - timer.startTime.tv_usec)/1.0e6));
}