-
Notifications
You must be signed in to change notification settings - Fork 2
/
bench.c
307 lines (304 loc) · 12.4 KB
/
bench.c
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include "chess.h"
#include "data.h"
/* last modified 02/26/14 */
/*
*******************************************************************************
* *
* Bench() runs a simple six-position benchmark to gauge Crafty's *
* performance. The test positons are hard-coded, and the benchmark is *
* calculated much like it would with an external "test" file. The test *
* is a mix of opening, middlegame, and endgame positions, with both *
* tactical and positional aspects. (For those interested, the positions *
* chosen are Bratko-Kopec 2, 4, 8, 12, 22 and 23.) This test is a speed *
* measure only; the actual solutions to the positions are ignored. *
* *
*******************************************************************************
*/
int Bench(int increase, int autotune) {
uint64_t nodes = 0;
int old_do, old_st, old_sd, total_time_used, pos, begin, end;
FILE *old_books, *old_book;
TREE *const tree = block[0];
char fen[6][80] = {
{"3r1k2/4npp1/1ppr3p/p6P/P2PPPP1/1NR5/5K2/2R5 w - - 0 1"},
{"rnbqkb1r/p3pppp/1p6/2ppP3/3N4/2P5/PPP1QPPP/R1B1KB1R w KQkq - 0 1"},
{"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w - - 0 1"},
{"r3r1k1/ppqb1ppp/8/4p1NQ/8/2P5/PP3PPP/R3R1K1 b - - 0 1"},
{"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b - - 0 1"},
{"r1bqk2r/pp2bppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 b kq - 0 1"}
};
int fen_depth[6] = { 24, 20, 25, 21, 18, 19 };
/*
************************************************************
* *
* Initialize. *
* *
************************************************************
*/
begin = ReadClock();
total_time_used = 0;
old_st = search_time_limit;
old_sd = search_depth;
old_do = display_options;
search_time_limit = 90000;
display_options = 1;
old_book = book_file;
book_file = 0;
old_books = books_file;
books_file = 0;
if (!autotune) {
if (increase)
Print(4095, "Running benchmark (modifying depth by %d plies). . .\n",
increase);
else
Print(4095, "Running benchmark. . .\n");
fflush(stdout);
}
/*
************************************************************
* *
* Now we loop through the six positions. We use the *
* ReadParse() procedure to break the FEN into tokens and *
* then call SetBoard() to set up the positions. Then a *
* call to Iterate() and we are done. *
* *
************************************************************
*/
for (pos = 0; pos < 6; pos++) {
strcpy(buffer, fen[pos]);
nargs = ReadParse(buffer, args, " \t;=");
SetBoard(tree, nargs, args, 0);
search_depth = fen_depth[pos] + increase;
last_pv.pathd = 0;
thinking = 1;
tree->status[1] = tree->status[0];
InitializeHashTables(0);
Iterate(game_wtm, think, 0);
thinking = 0;
nodes += tree->nodes_searched;
total_time_used += (program_end_time - program_start_time);
printf(".");
fflush(stdout);
}
/*
************************************************************
* *
* Benchmark done. Now dump the results. *
* *
************************************************************
*/
if (!autotune)
printf("\n");
if (!autotune) {
Print(4095, "Total nodes: %" PRIu64 "\n", nodes);
Print(4095, "Raw nodes per second: %d\n",
(int) ((double) nodes / ((double) total_time_used / (double) 100.0)));
Print(4095, "Total elapsed time: %.2f\n",
((double) total_time_used / (double) 100.0));
}
input_stream = stdin;
early_exit = 99;
display_options = old_do;
search_time_limit = old_st;
search_depth = old_sd;
books_file = old_books;
book_file = old_book;
NewGame(0);
end = ReadClock();
return end - begin;
}
/* last modified 02/26/14 */
/*
*******************************************************************************
* *
* Bench_PGO() runs a 64 position benchmark during the build process. The *
* test positons are hard-coded, and the benchmark is similiar to the normal *
* bench command. It designed specifically to run with the makefile for *
* profile guided optimizations. *
* *
*******************************************************************************
*/
int Bench_PGO(int increase, int autotune) {
uint64_t nodes = 0;
int old_do, old_st, old_sd, total_time_used, pos, begin, end, old_mt;
FILE *old_books, *old_book;
TREE *const tree = block[0];
char fen[64][80] = {
{"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b"},
{"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b"},
{"3rr1k1/pp3pp1/1qn2np1/8/3p4/PP1R1P2/2P1NQPP/R1B3K1 b"},
{"4r1k1/r1q2ppp/ppp2n2/4P3/5Rb1/1N1BQ3/PPP3PP/R5K1 w"},
{"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w"},
{"3r1rk1/p5pp/bpp1pp2/8/q1PP1P2/b3P3/P2NQRPP/1R2B1K1 b"},
{"8/R7/2q5/8/6k1/8/1P5p/K6R w"},
{"2r3k1/1p2q1pp/2b1pr2/p1pp4/6Q1/1P1PP1R1/P1PN2PP/5RK1 w"},
{"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b"},
{"1k1r4/pp1b1R2/3q2pp/4p3/2B5/4Q3/PPP2B2/2K5 b"},
{"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w"},
{"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PPPP/RNBQKBNR w"},
{"/k/3p/p2P1p/P2P1P///K/ w"},
{"rnb2r1k/pp2p2p/2pp2p1/q2P1p2/8/1Pb2NP1/PB2PPBP/R2Q1RK1 w"},
{"8/6pk/1p6/8/PP3p1p/5P2/4KP1q/3Q4 w"},
{"8/3p4/p1bk3p/Pp6/1Kp1PpPp/2P2P1P/2P5/5B2 b"},
{"1nk1r1r1/pp2n1pp/4p3/q2pPp1N/b1pP1P2/B1P2R2/2P1B1PP/R2Q2K1 w"},
{"2K5/p7/7P/5pR1/8/5k2/r7/8 w"},
{"3rr3/2pq2pk/p2p1pnp/8/2QBPP2/1P6/P5PP/4RRK1 b"},
{"r1b2rk1/2q1b1pp/p2ppn2/1p6/3QP3/1BN1B3/PPP3PP/R4RK1 w"},
{"8/8/8/8/5kp1/P7/8/1K1N4 w"},
{"r4k2/pb2bp1r/1p1qp2p/3pNp2/3P1P2/2N3P1/PPP1Q2P/2KRR3 w"},
{"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w"}
};
int fen_depth = 16;
/*
************************************************************
* *
* Initialize. *
* *
************************************************************
*/
begin = ReadClock();
total_time_used = 0;
old_st = search_time_limit;
old_sd = search_depth;
old_do = display_options;
search_time_limit = 90000;
display_options = 1;
old_book = book_file;
book_file = 0;
old_books = books_file;
books_file = 0;
if (!autotune) {
if (increase)
Print(4095, "Running benchmark (modifying depth by %d plies). . .\n",
increase);
else
Print(4095, "Running benchmark. . .\n");
fflush(stdout);
}
/*
************************************************************
* *
* Now we loop through the 64 positions. We use the *
* ReadParse() procedure to break the FEN into tokens and *
* then call SetBoard() to set up the positions. Then a *
* call to Iterate() and we are done. *
* *
************************************************************
*/
for (pos = 0; pos < 64; pos++) {
strcpy(buffer, fen[pos]);
nargs = ReadParse(buffer, args, " \t;=");
SetBoard(tree, nargs, args, 0);
search_depth = fen_depth + increase;
last_pv.pathd = 0;
thinking = 1;
tree->status[1] = tree->status[0];
InitializeHashTables(0);
Iterate(game_wtm, think, 0);
thinking = 0;
nodes += tree->nodes_searched;
total_time_used += (program_end_time - program_start_time);
nodes_per_second =
(uint64_t) tree->nodes_searched * 100 /
Max((uint64_t) program_end_time - program_start_time, 1);
if (pos % 7 == 0)
Print(4095, "pos: ");
Print(4095, "%d", pos + 1);
Print(4095, "(%s) ", DisplayKMB(nodes_per_second, 0));
if (pos % 7 == 6)
Print(4095, "\n");
fflush(stdout);
}
Print(4095, "\n");
/*
************************************************************
* *
* Benchmark done. Now dump the results. *
* *
************************************************************
*/
if (!autotune)
printf("\n");
if (!autotune) {
Print(4095, "Total nodes: %" PRIu64 "\n", nodes);
Print(4095, "Raw nodes per second: %d\n",
(int) ((double) nodes / ((double) total_time_used / (double) 100.0)));
Print(4095, "Total elapsed time: %.2f\n\n",
((double) total_time_used / (double) 100.0));
}
Print(4095, "Performing SMP PGO...\n");
old_mt = smp_max_threads;
smp_max_threads = 2;
fflush(stdout);
for (pos = 63; pos < 64; pos++) {
strcpy(buffer, fen[pos]);
nargs = ReadParse(buffer, args, " \t;=");
SetBoard(tree, nargs, args, 0);
search_depth = fen_depth + increase;
last_pv.pathd = 0;
thinking = 1;
tree->status[1] = tree->status[0];
InitializeHashTables(0);
Iterate(game_wtm, think, 0);
thinking = 0;
nodes += tree->nodes_searched;
total_time_used += (program_end_time - program_start_time);
nodes_per_second =
(uint64_t) tree->nodes_searched * 100 /
Max((uint64_t) program_end_time - program_start_time, 1);
Print(4095, " Running two threads...\n");
Print(4095, "pos: %d(%s)\n", pos + 1, DisplayKMB(nodes_per_second, 0));
}
input_stream = stdin;
early_exit = 99;
display_options = old_do;
search_time_limit = old_st;
search_depth = old_sd;
smp_max_threads = Max(1, old_mt);
books_file = old_books;
book_file = old_book;
NewGame(0);
end = ReadClock();
return end - begin;
}