Subversion Repositories Games.Chess Giants

Rev

Rev 33 | Rev 154 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 pmbaty 1
#include "chess.h"
2
#include "data.h"
3
/* last modified 02/26/14 */
4
/*
5
 *******************************************************************************
6
 *                                                                             *
7
 *   Bench() runs a simple six-position benchmark to gauge Crafty's            *
8
 *   performance.  The test positons are hard-coded, and the benchmark is      *
9
 *   calculated much like it would with an external "test" file.  The test     *
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
 *   measure only; the actual solutions to the positions are ignored.          *
14
 *                                                                             *
15
 *******************************************************************************
16
 */
108 pmbaty 17
int Bench(int increase, int autotune) {
33 pmbaty 18
  uint64_t nodes = 0;
108 pmbaty 19
  int old_do, old_st, old_sd, total_time_used, pos, begin, end;
33 pmbaty 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
  };
108 pmbaty 30
  int fen_depth[6] = { 24, 20, 25, 21, 18, 19 };
33 pmbaty 31
 
32
/*
33
 ************************************************************
34
 *                                                          *
35
 *  Initialize.                                             *
36
 *                                                          *
37
 ************************************************************
38
 */
108 pmbaty 39
  begin = ReadClock();
33 pmbaty 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;
108 pmbaty 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
  }
33 pmbaty 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];
108 pmbaty 76
    InitializeHashTables(0);
77
    Iterate(game_wtm, think, 0);
33 pmbaty 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
 */
108 pmbaty 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
  }
33 pmbaty 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 pmbaty 108
  end = ReadClock();
109
  return end - begin;
33 pmbaty 110
}
108 pmbaty 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, begin, end, old_mt;
126
  FILE *old_books, *old_book;
127
  TREE *const tree = block[0];
128
  char fen[64][80] = {
129
    {"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b"},
130
    {"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b"},
131
    {"3rr1k1/pp3pp1/1qn2np1/8/3p4/PP1R1P2/2P1NQPP/R1B3K1 b"},
132
    {"4r1k1/r1q2ppp/ppp2n2/4P3/5Rb1/1N1BQ3/PPP3PP/R5K1 w"},
133
    {"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w"},
134
    {"3r1rk1/p5pp/bpp1pp2/8/q1PP1P2/b3P3/P2NQRPP/1R2B1K1 b"},
135
    {"8/R7/2q5/8/6k1/8/1P5p/K6R w"},
136
    {"2r3k1/1p2q1pp/2b1pr2/p1pp4/6Q1/1P1PP1R1/P1PN2PP/5RK1 w"},
137
    {"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b"},
138
    {"1k1r4/pp1b1R2/3q2pp/4p3/2B5/4Q3/PPP2B2/2K5 b"},
139
    {"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w"},
140
    {"r1bqkb1r/4npp1/p1p4p/1p1pP1B1/8/1B6/PPPN1PPP/R2Q1RK1 w"},
141
    {"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 w"},
142
    {"2r1nrk1/p2q1ppp/bp1p4/n1pPp3/P1P1P3/2PBB1N1/4QPPP/R4RK1 w"},
143
    {"8/3k4/8/8/8/4B3/4KB2/2B5 w"},
144
    {"6k1/6p1/P6p/r1N5/5p2/7P/1b3PP1/4R1K1 w"},
145
    {"8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w"},
146
    {"r2q1rk1/1ppnbppp/p2p1nb1/3Pp3/2P1P1P1/2N2N1P/PPB1QP2/R1B2RK1 b"},
147
    {"2kr1bnr/pbpq4/2n1pp2/3p3p/3P1P1B/2N2N1Q/PPP3PP/2KR1B1R w"},
148
    {"8/2p5/8/2kPKp1p/2p4P/2P5/3P4/8 w"},
149
    {"3rn2k/ppb2rpp/2ppqp2/5N2/2P1P3/1P5Q/PB3PPP/3RR1K1 w"},
150
    {"rnbqkb1r/p3pppp/1p6/2ppP3/3N4/2P5/PPP1QPPP/R1B1KB1R w"},
151
    {"2r3k1/pppR1pp1/4p3/4P1P1/5P2/1P4K1/P1P5/8 w"},
152
    {"/k/rnn////5RBB/K/ w"},
153
    {"r1bq1rk1/ppp1nppp/4n3/3p3Q/3P4/1BP1B3/PP1N2PP/R4RK1 w"},
154
    {"8/8/3P3k/8/1p6/8/1P6/1K3n2 b"},
155
    {"8/2p4P/8/kr6/6R1/8/8/1K6 w"},
156
    {"r2qnrnk/p2b2b1/1p1p2pp/2pPpp2/1PP1P3/PRNBB3/3QNPPP/5RK1 w"},
157
    {"5k2/7R/4P2p/5K2/p1r2P1p/8/8/8 b"},
158
    {"rq3rk1/ppp2ppp/1bnpb3/3N2B1/3NP3/7P/PPPQ1PP1/2KR3R w"},
159
    {"2q1rr1k/3bbnnp/p2p1pp1/2pPp3/PpP1P1P1/1P2BNNP/2BQ1PRK/7R b"},
160
    {"2rqkb1r/ppp2p2/2npb1p1/1N1Nn2p/2P1PP2/8/PP2B1PP/R1BQK2R b"},
161
    {"r2q1rk1/4bppp/p2p4/2pP4/3pP3/3Q4/PP1B1PPP/R3R1K1 w"},
162
    {"6k1/6p1/6Pp/ppp5/3pn2P/1P3K2/1PP2P2/3N4 b"},
163
    {"8/3p3B/5p2/5P2/p7/PP5b/k7/6K1 w"},
164
    {"r1bbk1nr/pp3p1p/2n5/1N4p1/2Np1B2/8/PPP2PPP/2KR1B1R w"},
165
    {"8/1p3pp1/7p/5P1P/2k3P1/8/2K2P2/8 w"},
166
    {"8/8/8/5N2/8/p7/8/2NK3k w"},
167
    {"r1bq1r1k/b1p1npp1/p2p3p/1p6/3PP3/1B2NN2/PP3PPP/R2Q1RK1 w"},
168
    {"8/8/1P6/5pr1/8/4R3/7k/2K5 w"},
169
    {"4k2r/1pb2ppp/1p2p3/1R1p4/3P4/2r1PN2/P4PPP/1R4K1 b"},
170
    {"r1bq1r1k/1pp1n1pp/1p1p4/4p2Q/4Pp2/1BNP4/PPP2PPP/3R1RK1 w"},
171
    {"3r1k2/4npp1/1ppr3p/p6P/P2PPPP1/1NR5/5K2/2R5 w"},
172
    {"r3r1k1/2p2ppp/p1p1bn2/8/1q2P3/2NPQN2/PPP3PP/R4RK1 b"},
173
    {"6k1/4pp1p/3p2p1/P1pPb3/R7/1r2P1PP/3B1P2/6K1 w"},
174
    {"r1bqk2r/pp2bppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 b"},
175
    {"r1q2rk1/2p1bppp/2Pp4/p6b/Q1PNp3/4B3/PP1R1PPP/2K4R w"},
176
    {"8/pp2r1k1/2p1p3/3pP2p/1P1P1P1P/P5KR/8/8 w"},
177
    {"3b4/5kp1/1p1p1p1p/pP1PpP1P/P1P1P3/3KN3/8/8 w"},
178
    {"r1bq1rk1/pp2ppbp/2np2p1/2n5/P3PP2/N1P2N2/1PB3PP/R1B1QRK1 b"},
179
    {"r3r1k1/ppqb1ppp/8/4p1NQ/8/2P5/PP3PPP/R3R1K1 b"},
180
    {"rnbqkb1r/p3pppp/1p6/2ppP3/3N4/2P5/PPP1QPPP/R1B1KB1R w"},
181
    {"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w"},
182
    {"/k/3p/p2P1p/P2P1P///K/ w"},
183
    {"rnb2r1k/pp2p2p/2pp2p1/q2P1p2/8/1Pb2NP1/PB2PPBP/R2Q1RK1 w"},
184
    {"8/6pk/1p6/8/PP3p1p/5P2/4KP1q/3Q4 w"},
185
    {"8/3p4/p1bk3p/Pp6/1Kp1PpPp/2P2P1P/2P5/5B2 b"},
186
    {"1nk1r1r1/pp2n1pp/4p3/q2pPp1N/b1pP1P2/B1P2R2/2P1B1PP/R2Q2K1 w"},
187
    {"2K5/p7/7P/5pR1/8/5k2/r7/8 w"},
188
    {"3rr3/2pq2pk/p2p1pnp/8/2QBPP2/1P6/P5PP/4RRK1 b"},
189
    {"r1b2rk1/2q1b1pp/p2ppn2/1p6/3QP3/1BN1B3/PPP3PP/R4RK1 w"},
190
    {"8/8/8/8/5kp1/P7/8/1K1N4 w"},
191
    {"r4k2/pb2bp1r/1p1qp2p/3pNp2/3P1P2/2N3P1/PPP1Q2P/2KRR3 w"},
192
    {"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w"}
193
  };
194
  int fen_depth = 16;
195
 
196
 /*
197
  ************************************************************
198
  *                                                          *
199
  *  Initialize.                                             *
200
  *                                                          *
201
  ************************************************************
202
  */
203
  begin = ReadClock();
204
  total_time_used = 0;
205
  old_st = search_time_limit;
206
  old_sd = search_depth;
207
  old_do = display_options;
208
  search_time_limit = 90000;
209
  display_options = 1;
210
  old_book = book_file;
211
  book_file = 0;
212
  old_books = books_file;
213
  books_file = 0;
214
  if (!autotune) {
215
    if (increase)
216
      Print(4095, "Running benchmark (modifying depth by %d plies). . .\n",
217
          increase);
218
    else
219
      Print(4095, "Running benchmark. . .\n");
220
    fflush(stdout);
221
  }
222
 /*
223
  ************************************************************
224
  *                                                          *
225
  *  Now we loop through the 64 positions.  We use the      *
226
  *  ReadParse() procedure to break the FEN into tokens and  *
227
  *  then call SetBoard() to set up the positions.  Then a   *
228
  *  call to Iterate() and we are done.                      *
229
  *                                                          *
230
  ************************************************************
231
  */
232
  for (pos = 0; pos < 64; pos++) {
233
    strcpy(buffer, fen[pos]);
234
    nargs = ReadParse(buffer, args, " \t;=");
235
    SetBoard(tree, nargs, args, 0);
236
    search_depth = fen_depth + increase;
237
    last_pv.pathd = 0;
238
    thinking = 1;
239
    tree->status[1] = tree->status[0];
240
    InitializeHashTables(0);
241
    Iterate(game_wtm, think, 0);
242
    thinking = 0;
243
    nodes += tree->nodes_searched;
244
    total_time_used += (program_end_time - program_start_time);
245
    nodes_per_second = (unsigned int) // Pierre-Marie Baty -- added type cast
246
        ((uint64_t) tree->nodes_searched * 100 /
247
        Max((uint64_t) program_end_time - program_start_time, 1));
248
    if (pos % 7 == 0)
249
      Print(4095, "pos: ");
250
    Print(4095, "%d", pos + 1);
251
    Print(4095, "(%s) ", DisplayKMB(nodes_per_second, 0));
252
    if (pos % 7 == 6)
253
      Print(4095, "\n");
254
    fflush(stdout);
255
  }
256
  Print(4095, "\n");
257
 /*
258
  ************************************************************
259
  *                                                          *
260
  *  Benchmark done.  Now dump the results.                  *
261
  *                                                          *
262
  ************************************************************
263
  */
264
  if (!autotune)
265
    printf("\n");
266
  if (!autotune) {
267
    Print(4095, "Total nodes: %" PRIu64 "\n", nodes);
268
    Print(4095, "Raw nodes per second: %d\n",
269
        (int) ((double) nodes / ((double) total_time_used / (double) 100.0)));
270
    Print(4095, "Total elapsed time: %.2f\n\n",
271
        ((double) total_time_used / (double) 100.0));
272
  }
273
  Print(4095, "Performing SMP PGO...\n");
274
  old_mt = smp_max_threads;
275
  smp_max_threads = 2;
276
  fflush(stdout);
277
  for (pos = 63; pos < 64; pos++) {
278
    strcpy(buffer, fen[pos]);
279
    nargs = ReadParse(buffer, args, " \t;=");
280
    SetBoard(tree, nargs, args, 0);
281
    search_depth = fen_depth + increase;
282
    last_pv.pathd = 0;
283
    thinking = 1;
284
    tree->status[1] = tree->status[0];
285
    InitializeHashTables(0);
286
    Iterate(game_wtm, think, 0);
287
    thinking = 0;
288
    nodes += tree->nodes_searched;
289
    total_time_used += (program_end_time - program_start_time);
290
    nodes_per_second = (unsigned int) // Pierre-Marie Baty -- added type cast
291
        ((uint64_t) tree->nodes_searched * 100 /
292
        Max((uint64_t) program_end_time - program_start_time, 1));
293
    Print(4095, " Running two threads...\n");
294
    Print(4095, "pos: %d(%s)\n", pos + 1, DisplayKMB(nodes_per_second, 0));
295
  }
296
  input_stream = stdin;
297
  early_exit = 99;
298
  display_options = old_do;
299
  search_time_limit = old_st;
300
  search_depth = old_sd;
301
  smp_max_threads = Max(1, old_mt);
302
  books_file = old_books;
303
  book_file = old_book;
304
  NewGame(0);
305
  end = ReadClock();
306
  return end - begin;
307
}