-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck.cuh
More file actions
69 lines (65 loc) · 1.86 KB
/
check.cuh
File metadata and controls
69 lines (65 loc) · 1.86 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <cstdio>
#include <cmath>
#include <type_traits>
#include <cuda_fp16.h>
#include <cuda_bf16.h>
#define EPSILON 1e-2
template <typename T>
void checkResult(T* hostRef, T* gpuRef,const int N){
bool match = 1;
int error_count = 4;
int count = 0;
for(int i = 0; i < N; i++){
if constexpr (std::is_same<T, float>::value){
if(abs(hostRef[i] - gpuRef[i]) > EPSILON){
match = 0;
//printf("Arrays do not match!\n");
if (count < error_count){
printf("hostRef[%d] = %5.6f, gpuRef[%d] = %5.6f\n", i, hostRef[i], i, gpuRef[i]);
}
count++;
// break;
}
}
else if constexpr(std::is_same<T, __half>::value){
if(abs(__half2float(hostRef[i]) - __half2float(gpuRef[i])) > EPSILON){
match = 0;
//printf("Arrays do not match!\n");
if (count < error_count){
printf("hostRef[%d] = %5.6f, gpuRef[%d] = %5.6f\n", i, __half2float(hostRef[i]), i, __half2float(gpuRef[i]));
}
count++;
// break;
}
}
else if constexpr(std::is_same<T, __nv_bfloat16>::value){
if(abs(__bfloat162float(hostRef[i]) - __bfloat162float(gpuRef[i])) > EPSILON){
match = 0;
//printf("Arrays do not match!\n");
if (count < error_count){
printf("hostRef[%d] = %5.6f, gpuRef[%d] = %5.6f\n", i, __bfloat162float(hostRef[i]), i, __bfloat162float(gpuRef[i]));
}
count++;
// break;
}
}
else{
if(hostRef[i] != gpuRef[i]){
match = 0;
//printf("Arrays do not match!\n");
if (count < error_count){
printf("hostRef[%d] = %d, gpuRef[%d] = %d\n", i, hostRef[i], i, gpuRef[i]);
}
count++;
// break;
}
}
}
if(match){
printf("Arrays match!\n");
}
else{
printf("Arrays do not match!\n");
printf("Error count: %d\n", count);
}
}