Rev 108 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 108 | Rev 154 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "chess.h" |
1 | #include "chess.h" |
2 | #include "data.h" |
2 | #include "data.h" |
3 | /* last modified |
3 | /* last modified 09/29/16 */ |
4 | /* |
4 | /* |
5 | ******************************************************************************* |
5 | ******************************************************************************* |
6 | * * |
6 | * * |
7 | * Bench() runs a |
7 | * Bench() runs a 64 position benchmark during the build process. The test * |
8 | * |
8 | * positons are hard-coded. This is designed as a stand-alone benchmark to * |
9 | * |
9 | * comper different machines, or as a profile-guided-optimization test that * |
10 | * is a mix of opening, middlegame, and endgame positions, with both * |
- | |
11 | * tactical and positional aspects. (For those interested, the positions * |
- | |
12 | * chosen are Bratko-Kopec 2, 4, 8, 12, 22 and 23.) This test is a speed * |
- | |
13 | * |
10 | * produces good profile data. * |
14 | * * |
11 | * * |
15 | ******************************************************************************* |
12 | ******************************************************************************* |
16 | */ |
13 | */ |
17 | int Bench(int increase, int autotune) { |
14 | int Bench(int increase, int autotune) { |
18 | uint64_t nodes = 0; |
15 | uint64_t nodes = 0; |
19 | int old_do, old_st, old_sd, total_time_used, pos, begin, end; |
- | |
20 | FILE *old_books, *old_book; |
- | |
21 | TREE *const tree = block[0]; |
- | |
22 | char fen[6][80] = { |
- | |
23 | {"3r1k2/4npp1/1ppr3p/p6P/P2PPPP1/1NR5/5K2/2R5 w - - 0 1"}, |
- | |
24 | {"rnbqkb1r/p3pppp/1p6/2ppP3/3N4/2P5/PPP1QPPP/R1B1KB1R w KQkq - 0 1"}, |
- | |
25 | {"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w - - 0 1"}, |
- | |
26 | {"r3r1k1/ppqb1ppp/8/4p1NQ/8/2P5/PP3PPP/R3R1K1 b - - 0 1"}, |
- | |
27 | {"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b - - 0 1"}, |
- | |
28 | {"r1bqk2r/pp2bppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 b kq - 0 1"} |
- | |
29 | }; |
- | |
30 | int fen_depth[6] = { 24, 20, 25, 21, 18, 19 }; |
- | |
31 | - | ||
32 | /* |
- | |
33 | ************************************************************ |
- | |
34 | * * |
- | |
35 | * Initialize. * |
- | |
36 | * * |
- | |
37 | ************************************************************ |
- | |
38 | */ |
- | |
39 | begin = ReadClock(); |
- | |
40 | total_time_used = 0; |
- | |
41 | old_st = search_time_limit; |
- | |
42 | old_sd = search_depth; |
- | |
43 | old_do = display_options; |
- | |
44 | search_time_limit = 90000; |
- | |
45 | display_options = 1; |
- | |
46 | old_book = book_file; |
- | |
47 | book_file = 0; |
- | |
48 | old_books = books_file; |
- | |
49 | books_file = 0; |
- | |
50 | if (!autotune) { |
- | |
51 | if (increase) |
- | |
52 | Print(4095, "Running benchmark (modifying depth by %d plies). . .\n", |
- | |
53 | increase); |
- | |
54 | else |
- | |
55 | Print(4095, "Running benchmark. . .\n"); |
- | |
56 | fflush(stdout); |
- | |
57 | } |
- | |
58 | /* |
- | |
59 | ************************************************************ |
- | |
60 | * * |
- | |
61 | * Now we loop through the six positions. We use the * |
- | |
62 | * ReadParse() procedure to break the FEN into tokens and * |
- | |
63 | * then call SetBoard() to set up the positions. Then a * |
- | |
64 | * call to Iterate() and we are done. * |
- | |
65 | * * |
- | |
66 | ************************************************************ |
- | |
67 | */ |
- | |
68 | for (pos = 0; pos < 6; pos++) { |
- | |
69 | strcpy(buffer, fen[pos]); |
- | |
70 | nargs = ReadParse(buffer, args, " \t;="); |
- | |
71 | SetBoard(tree, nargs, args, 0); |
- | |
72 | search_depth = fen_depth[pos] + increase; |
- | |
73 | last_pv.pathd = 0; |
- | |
74 | thinking = 1; |
- | |
75 | tree->status[1] = tree->status[0]; |
- | |
76 | InitializeHashTables(0); |
- | |
77 | Iterate(game_wtm, think, 0); |
- | |
78 | thinking = 0; |
- | |
79 | nodes += tree->nodes_searched; |
- | |
80 | total_time_used += (program_end_time - program_start_time); |
- | |
81 | printf("."); |
- | |
82 | fflush(stdout); |
- | |
83 | } |
- | |
84 | /* |
- | |
85 | ************************************************************ |
- | |
86 | * * |
- | |
87 | * Benchmark done. Now dump the results. * |
- | |
88 | * * |
- | |
89 | ************************************************************ |
- | |
90 | */ |
- | |
91 | if (!autotune) |
- | |
92 | printf("\n"); |
- | |
93 | if (!autotune) { |
- | |
94 | Print(4095, "Total nodes: %" PRIu64 "\n", nodes); |
- | |
95 | Print(4095, "Raw nodes per second: %d\n", |
- | |
96 | (int) ((double) nodes / ((double) total_time_used / (double) 100.0))); |
- | |
97 | Print(4095, "Total elapsed time: %.2f\n", |
- | |
98 | ((double) total_time_used / (double) 100.0)); |
- | |
99 | } |
- | |
100 | input_stream = stdin; |
- | |
101 | early_exit = 99; |
- | |
102 | display_options = old_do; |
- | |
103 | search_time_limit = old_st; |
- | |
104 | search_depth = old_sd; |
- | |
105 | books_file = old_books; |
- | |
106 | book_file = old_book; |
- | |
107 | NewGame(0); |
- | |
108 | end = ReadClock(); |
- | |
109 | return end - begin; |
- | |
110 | } |
- | |
111 | - | ||
112 | /* last modified 02/26/14 */ |
- | |
113 | /* |
- | |
114 | ******************************************************************************* |
- | |
115 | * * |
- | |
116 | * Bench_PGO() runs a 64 position benchmark during the build process. The * |
- | |
117 | * test positons are hard-coded, and the benchmark is similiar to the normal * |
- | |
118 | * bench command. It designed specifically to run with the makefile for * |
- | |
119 | * profile guided optimizations. * |
- | |
120 | * * |
- | |
121 | ******************************************************************************* |
- | |
122 | */ |
- | |
123 | int Bench_PGO(int increase, int autotune) { |
- | |
124 | uint64_t nodes = 0; |
- | |
125 | int old_do, old_st, old_sd, total_time_used, pos, |
16 | int old_do, old_st, old_sd, total_time_used, pos, old_mt = smp_max_threads; |
126 | FILE *old_books, *old_book; |
17 | FILE *old_books, *old_book; |
127 | TREE *const tree = block[0]; |
18 | TREE *const tree = block[0]; |
128 | char fen[64][80] = { |
19 | char fen[64][80] = { |
129 | {"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b"}, |
20 | {"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b"}, |
130 | {"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b"}, |
21 | {"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b"}, |
Line 133... | Line 24... | ||
133 | {"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w"}, |
24 | {"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w"}, |
134 | {"3r1rk1/p5pp/bpp1pp2/8/q1PP1P2/b3P3/P2NQRPP/1R2B1K1 b"}, |
25 | {"3r1rk1/p5pp/bpp1pp2/8/q1PP1P2/b3P3/P2NQRPP/1R2B1K1 b"}, |
135 | {"8/R7/2q5/8/6k1/8/1P5p/K6R w"}, |
26 | {"8/R7/2q5/8/6k1/8/1P5p/K6R w"}, |
136 | {"2r3k1/1p2q1pp/2b1pr2/p1pp4/6Q1/1P1PP1R1/P1PN2PP/5RK1 w"}, |
27 | {"2r3k1/1p2q1pp/2b1pr2/p1pp4/6Q1/1P1PP1R1/P1PN2PP/5RK1 w"}, |
137 | {"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b"}, |
28 | {"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b"}, |
138 | {" |
29 | {"5r1k/6p/1n2Q2p/4p//7P/PP4PK/R1B1q/ w"}, |
139 | {"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w"}, |
30 | {"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w"}, |
140 | {"r1bqkb1r/4npp1/p1p4p/1p1pP1B1/8/1B6/PPPN1PPP/R2Q1RK1 w"}, |
31 | {"r1bqkb1r/4npp1/p1p4p/1p1pP1B1/8/1B6/PPPN1PPP/R2Q1RK1 w"}, |
141 | {"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 w"}, |
32 | {"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 w"}, |
142 | {"2r1nrk1/p2q1ppp/bp1p4/n1pPp3/P1P1P3/2PBB1N1/4QPPP/R4RK1 w"}, |
33 | {"2r1nrk1/p2q1ppp/bp1p4/n1pPp3/P1P1P3/2PBB1N1/4QPPP/R4RK1 w"}, |
143 | {"8/3k4/8/8/8/4B3/4KB2/2B5 w"}, |
34 | {"8/3k4/8/8/8/4B3/4KB2/2B5 w"}, |
Line 198... | Line 89... | ||
198 | * * |
89 | * * |
199 | * Initialize. * |
90 | * Initialize. * |
200 | * * |
91 | * * |
201 | ************************************************************ |
92 | ************************************************************ |
202 | */ |
93 | */ |
203 | begin = ReadClock(); |
- | |
204 | total_time_used = 0; |
94 | total_time_used = 0; |
205 | old_st = search_time_limit; |
95 | old_st = search_time_limit; |
206 | old_sd = search_depth; |
96 | old_sd = search_depth; |
207 | old_do = display_options; |
97 | old_do = display_options; |
208 | search_time_limit = 90000; |
98 | search_time_limit = 90000; |
Line 211... | Line 101... | ||
211 | book_file = 0; |
101 | book_file = 0; |
212 | old_books = books_file; |
102 | old_books = books_file; |
213 | books_file = 0; |
103 | books_file = 0; |
214 | if (!autotune) { |
104 | if (!autotune) { |
215 | if (increase) |
105 | if (increase) |
- | 106 | Print(4095, |
|
216 |
|
107 | "Running serial benchmark (modifying depth by %d plies). . .\n", |
217 | increase); |
108 | increase); |
218 | else |
109 | else |
219 | Print(4095, "Running benchmark. . .\n"); |
110 | Print(4095, "Running serial benchmark. . .\n"); |
220 | fflush(stdout); |
111 | fflush(stdout); |
221 | } |
112 | } |
222 | /* |
113 | /* |
223 | ************************************************************ |
114 | ************************************************************ |
224 | * * |
115 | * * |
Line 240... | Line 131... | ||
240 | InitializeHashTables(0); |
131 | InitializeHashTables(0); |
241 | Iterate(game_wtm, think, 0); |
132 | Iterate(game_wtm, think, 0); |
242 | thinking = 0; |
133 | thinking = 0; |
243 | nodes += tree->nodes_searched; |
134 | nodes += tree->nodes_searched; |
244 | total_time_used += (program_end_time - program_start_time); |
135 | total_time_used += (program_end_time - program_start_time); |
245 | nodes_per_second = |
136 | nodes_per_second = |
246 |
|
137 | (uint64_t) tree->nodes_searched * 100 / |
247 | Max((uint64_t) program_end_time - program_start_time, 1 |
138 | Max((uint64_t) program_end_time - program_start_time, 1); |
248 | if (pos % 7 == 0) |
139 | if (pos % 7 == 0) |
249 | Print(4095, "pos: "); |
140 | Print(4095, "pos: "); |
250 | Print(4095, "%d", pos + 1); |
- | |
251 | Print(4095, "(%s) ", DisplayKMB(nodes_per_second, 0)); |
141 | Print(4095, "%2d(%s) ", pos + 1, DisplayKMB(nodes_per_second, 0)); |
252 | if (pos % 7 == 6) |
142 | if (pos % 7 == 6) |
253 | Print(4095, "\n"); |
143 | Print(4095, "\n"); |
254 | fflush(stdout); |
144 | fflush(stdout); |
255 | } |
145 | } |
256 | Print(4095, "\n"); |
- | |
257 | /* |
146 | /* |
258 | ************************************************************ |
147 | ************************************************************ |
259 | * * |
148 | * * |
260 | * |
149 | * Serial benchmark done. Now dump the results. * |
261 | * * |
150 | * * |
262 | ************************************************************ |
151 | ************************************************************ |
263 | */ |
152 | */ |
264 | if (!autotune) |
153 | if (!autotune) |
265 | printf("\n"); |
154 | printf("\n"); |
266 | if (!autotune) { |
155 | if (!autotune) { |
267 | Print(4095, "Total nodes: %" PRIu64 "\n", nodes); |
156 | Print(4095, "\nTotal nodes: %" PRIu64 "\n", nodes); |
268 | Print(4095, "Raw nodes per second: %d\n", |
157 | Print(4095, "Raw nodes per second: %d\n", |
269 | (int) ((double) nodes / ((double) total_time_used / (double) 100.0))); |
158 | (int) ((double) nodes / ((double) total_time_used / (double) 100.0))); |
270 | Print(4095, "Total elapsed time: %.2f\n\n", |
159 | Print(4095, "Total elapsed time: %.2f\n\n", |
271 | ((double) total_time_used / (double) 100.0)); |
160 | ((double) total_time_used / (double) 100.0)); |
272 | } |
161 | } |
- | 162 | /* |
|
- | 163 | ************************************************************ |
|
- | 164 | * * |
|
273 |
|
165 | * Now we repeat for two threads to provide PGO data for * |
- | 166 | * the compiler. * |
|
- | 167 | * * |
|
- | 168 | ************************************************************ |
|
- | 169 | */ |
|
274 |
|
170 | if (smp_max_threads == 0) { |
275 | smp_max_threads = 2; |
171 | smp_max_threads = 2; |
- | 172 | Print(4095, "Running SMP benchmark (%d threads)...\n", smp_max_threads); |
|
276 | fflush(stdout); |
173 | fflush(stdout); |
- | 174 | Print(4095, "pos: "); |
|
277 | for (pos = |
175 | for (pos = 0; pos < 2 && old_mt == 0; pos++) { |
278 | strcpy(buffer, fen[pos]); |
176 | strcpy(buffer, fen[pos]); |
279 | nargs = ReadParse(buffer, args, " \t;="); |
177 | nargs = ReadParse(buffer, args, " \t;="); |
280 | SetBoard(tree, nargs, args, 0); |
178 | SetBoard(tree, nargs, args, 0); |
281 | search_depth = fen_depth + increase; |
179 | search_depth = fen_depth + increase; |
282 | last_pv.pathd = 0; |
180 | last_pv.pathd = 0; |
283 | thinking = 1; |
181 | thinking = 1; |
284 | tree->status[1] = tree->status[0]; |
182 | tree->status[1] = tree->status[0]; |
285 | InitializeHashTables(0); |
183 | InitializeHashTables(0); |
286 | Iterate(game_wtm, think, 0); |
184 | Iterate(game_wtm, think, 0); |
287 | thinking = 0; |
185 | thinking = 0; |
288 | nodes += tree->nodes_searched; |
186 | nodes += tree->nodes_searched; |
289 | total_time_used += (program_end_time - program_start_time); |
187 | total_time_used += (program_end_time - program_start_time); |
290 |
|
188 | nodes_per_second = |
291 |
|
189 | (uint64_t) tree->nodes_searched * 100 / |
292 | Max((uint64_t) program_end_time - program_start_time, 1 |
190 | Max((uint64_t) program_end_time - program_start_time, 1); |
- | 191 | Print(4095, "%2d(%s) ", pos + 1, DisplayKMB(nodes_per_second, 0)); |
|
- | 192 | } |
|
- | 193 | } |
|
- | 194 | /* |
|
- | 195 | ************************************************************ |
|
- | 196 | * * |
|
- | 197 | * Benchmark done. Now dump the results. * |
|
- | 198 | * * |
|
- | 199 | ************************************************************ |
|
- | 200 | */ |
|
- | 201 | if (!autotune) |
|
- | 202 | printf("\n"); |
|
- | 203 | if (!autotune && old_mt == 0) { |
|
- | 204 | Print(4095, "\nTotal nodes: %" PRIu64 "\n", nodes); |
|
293 | Print(4095, " |
205 | Print(4095, "Raw nodes per second: %d\n", |
- | 206 | (int) ((double) nodes / ((double) total_time_used / (double) 100.0))); |
|
294 | Print(4095, " |
207 | Print(4095, "Total elapsed time: %.2f\n\n", |
- | 208 | ((double) total_time_used / (double) 100.0)); |
|
295 | } |
209 | } |
296 | input_stream = stdin; |
210 | input_stream = stdin; |
297 | early_exit = 99; |
211 | early_exit = 99; |
298 | display_options = old_do; |
212 | display_options = old_do; |
299 | search_time_limit = old_st; |
213 | search_time_limit = old_st; |
300 | search_depth = old_sd; |
214 | search_depth = old_sd; |
301 | smp_max_threads = Max( |
215 | smp_max_threads = Max(0, old_mt); |
302 | books_file = old_books; |
216 | books_file = old_books; |
303 | book_file = old_book; |
217 | book_file = old_book; |
304 | NewGame(0); |
- | |
305 |
|
218 | InitializeChessBoard(tree); |
306 | return |
219 | return total_time_used; |
307 | } |
220 | } |