-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfpPTXtest.cu
205 lines (165 loc) · 4.95 KB
/
fpPTXtest.cu
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// bls12_381: Arithmetic for BLS12-381
// Copyright 2022-2023 Dag Arne Osvik
// Copyright 2022-2023 Luan Cardoso dos Santos
// Tests if the inline PTX and pure PTX functions generate matching results.
#include "fp.cuh"
#include "fptest.cuh"
#include "fp_ptx.cuh"
/**
* @brief Test the equivalence between the inline PTX functions with the pure PTX
* macros
*
* @return __global__
*/
__global__ void FpTestEqPTXInline(testval_t *testval) {
printf("=== RUN %s\n", __func__);
bool pass = true;
size_t count = 0;
fp_t x, y, r, rp;
//add
for(int i=0; pass && i<TESTVALS; i++){
for(int j=0; pass && j<TESTVALS; j++){
fp_cpy(x, testval[i]);
fp_cpy(y, testval[j]);
fp_add(r, x, y);
fp_add_ptx(rp, x, y);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED add\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
}
//sub
for(int i=0; pass && i<TESTVALS; i++){
for(int j=0; pass && j<TESTVALS; j++){
fp_cpy(x, testval[i]);
fp_cpy(y, testval[j]);
fp_sub(r, x, y);
fp_sub_ptx(rp, x, y);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED sub\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
}
//mul
for(int i=0; pass && i<TESTVALS; i++){
for(int j=0; pass && j<TESTVALS; j++){
fp_cpy(x, testval[i]);
fp_cpy(y, testval[j]);
fp_mul(r, x, y);
fp_mul_ptx(rp, x, y);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED mul\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
}
//sqr
for(int i=0; pass && i<TESTVALS; i++){
fp_cpy(x, testval[i]);
fp_sqr(r, x);
fp_sqr_ptx(rp, x);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED sqr\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
//x2
for(int i=0; pass && i<TESTVALS; i++){
fp_cpy(x, testval[i]);
fp_x2(r, x);
fp_x2_ptx(rp, x);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED x2\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
//x3
for(int i=0; pass && i<TESTVALS; i++){
fp_cpy(x, testval[i]);
fp_x3(r, x);
fp_x3_ptx(rp, x);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED x2\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
//x4
for(int i=0; pass && i<TESTVALS; i++){
fp_cpy(x, testval[i]);
fp_x4(r, x);
fp_x4_ptx(rp, x);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED x2\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
//x8
for(int i=0; pass && i<TESTVALS; i++){
fp_cpy(x, testval[i]);
fp_x8(r, x);
fp_x8_ptx(rp, x);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED x2\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
//x12
for(int i=0; pass && i<TESTVALS; i++){
fp_cpy(x, testval[i]);
fp_x12(r, x);
fp_x12_ptx(rp, x);
if(fp_neq(r, rp)){
pass = false;
printf("%d: FAILED x2\n", i);
fp_print("x : ", x);
fp_print("y : ", y);
fp_print("r : ", r);
fp_print("rp : ", rp);
}
++count;
}
printf("%ld tests\n", count);
PRINTPASS(pass);
}