1976
by gtw
Added evaluation speed calibration commands. |
1 |
/*
|
2 |
* speed.c
|
|
3 |
*
|
|
4 |
* by Gary Wong <gtw@gnu.org>, 2003
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
3944
by ace
*** empty log message *** |
7 |
* it under the terms of version 3 or later of the GNU General Public License as
|
1976
by gtw
Added evaluation speed calibration commands. |
8 |
* published by the Free Software Foundation.
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 |
*
|
|
6220
by plm
Declare static function as such. |
19 |
* $Id: speed.c,v 1.34 2017/06/27 19:34:18 plm Exp $
|
1976
by gtw
Added evaluation speed calibration commands. |
20 |
*/
|
21 |
||
3940
by c_anthon
replace gtk_signal* with g_signal* |
22 |
#include "config.h" |
4038
by Superfly_Jon
Misc changes |
23 |
|
6046
by plm
Align neural net output to simd vector size. |
24 |
#if defined(USE_GTK)
|
4038
by Superfly_Jon
Misc changes |
25 |
#include "gtkgame.h" |
26 |
#else
|
|
1976
by gtw
Added evaluation speed calibration commands. |
27 |
#include "backgammon.h" |
28 |
#endif
|
|
6046
by plm
Align neural net output to simd vector size. |
29 |
#if defined(USE_MULTITHREAD)
|
3856
by Superfly_Jon
Make calibration test multi-threaded |
30 |
#include "multithread.h" |
4038
by Superfly_Jon
Misc changes |
31 |
#endif
|
32 |
#ifndef WIN32
|
|
3896
by c_anthon
hack to make edit new position work |
33 |
#include <stdlib.h> |
4038
by Superfly_Jon
Misc changes |
34 |
#endif
|
35 |
||
6220
by plm
Declare static function as such. |
36 |
#include "lib/isaac.h" |
6046
by plm
Align neural net output to simd vector size. |
37 |
#include "lib/simd.h" |
1976
by gtw
Added evaluation speed calibration commands. |
38 |
|
39 |
#define EVALS_PER_ITERATION 1024
|
|
40 |
||
5760
by plm
Declare file-scoped variables explicitely |
41 |
static randctx rc; |
42 |
static double timeTaken; |
|
3856
by Superfly_Jon
Make calibration test multi-threaded |
43 |
|
6220
by plm
Declare static function as such. |
44 |
static void |
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
45 |
RunEvals(void *UNUSED(notused)) |
3856
by Superfly_Jon
Make calibration test multi-threaded |
46 |
{
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
47 |
int aanBoard[EVALS_PER_ITERATION][2][25]; |
3856
by Superfly_Jon
Make calibration test multi-threaded |
48 |
int i, j, k; |
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
49 |
double t; |
6046
by plm
Align neural net output to simd vector size. |
50 |
SSE_ALIGN(float ar[NUM_OUTPUTS]); |
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
51 |
|
6046
by plm
Align neural net output to simd vector size. |
52 |
#if defined(USE_MULTITHREAD)
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
53 |
MT_Exclusive(); |
54 |
#endif
|
|
55 |
for (i = 0; i < EVALS_PER_ITERATION; i++) { |
|
56 |
/* Generate a random board. Don't allow chequers on the bar
|
|
57 |
* or borne off, so we can trivially guarantee the position
|
|
58 |
* is legal. */
|
|
59 |
for (j = 0; j < 25; j++) |
|
60 |
aanBoard[i][0][j] = aanBoard[i][1][j] = 0; |
|
61 |
||
62 |
for (j = 0; j < 15; j++) { |
|
63 |
do { |
|
64 |
k = irand(&rc) % 24; |
|
65 |
} while (aanBoard[i][1][23 - k]); |
|
66 |
aanBoard[i][0][k]++; |
|
67 |
||
68 |
do { |
|
69 |
k = irand(&rc) % 24; |
|
70 |
} while (aanBoard[i][0][23 - k]); |
|
71 |
aanBoard[i][1][k]++; |
|
72 |
}
|
|
73 |
}
|
|
74 |
||
6046
by plm
Align neural net output to simd vector size. |
75 |
#if defined(USE_MULTITHREAD)
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
76 |
MT_Release(); |
77 |
MT_SyncStart(); |
|
78 |
#else
|
|
79 |
t = get_time(); |
|
80 |
#endif
|
|
81 |
||
82 |
for (i = 0; i < EVALS_PER_ITERATION; i++) { |
|
83 |
(void) EvaluatePosition(NULL, (ConstTanBoard) aanBoard[i], ar, &ciCubeless, NULL); |
|
84 |
}
|
|
85 |
||
6046
by plm
Align neural net output to simd vector size. |
86 |
#if defined(USE_MULTITHREAD)
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
87 |
if ((t = MT_SyncEnd()) != 0) |
88 |
timeTaken += t; |
|
89 |
#else
|
|
90 |
timeTaken += (get_time() - t); |
|
3856
by Superfly_Jon
Make calibration test multi-threaded |
91 |
#endif
|
92 |
}
|
|
93 |
||
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
94 |
extern void |
95 |
CommandCalibrate(char *sz) |
|
3856
by Superfly_Jon
Make calibration test multi-threaded |
96 |
{
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
97 |
int n = -1; |
6046
by plm
Align neural net output to simd vector size. |
98 |
unsigned int i, iIter, iCacheSize; |
99 |
#if defined(USE_GTK)
|
|
2068
by thyssen
preparing for hypergammon |
100 |
void *pcc = NULL; |
1976
by gtw
Added evaluation speed calibration commands. |
101 |
#endif
|
3856
by Superfly_Jon
Make calibration test multi-threaded |
102 |
|
6046
by plm
Align neural net output to simd vector size. |
103 |
iCacheSize = GetEvalCacheEntries(); |
104 |
EvalCacheResize(0); |
|
105 |
||
106 |
#if defined(USE_MULTITHREAD)
|
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
107 |
MT_SyncInit(); |
3858
by Superfly_Jon
Fix for calibrating more than 2 threads |
108 |
#endif
|
109 |
||
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
110 |
if (sz && *sz) { |
111 |
n = ParseNumber(&sz); |
|
112 |
||
113 |
if (n < 1) { |
|
114 |
outputl(_("If you specify a parameter to `calibrate', " "it must be a number of iterations to run.")); |
|
115 |
return; |
|
116 |
}
|
|
117 |
}
|
|
118 |
||
119 |
if (clock() == (clock_t) - 1) { |
|
120 |
outputl(_("Calibration not available.")); |
|
121 |
return; |
|
122 |
}
|
|
123 |
||
124 |
rc.randrsl[0] = (ub4) time(NULL); |
|
125 |
for (i = 0; i < RANDSIZ; i++) |
|
126 |
rc.randrsl[i] = rc.randrsl[0]; |
|
127 |
irandinit(&rc, TRUE); |
|
1976
by gtw
Added evaluation speed calibration commands. |
128 |
|
6046
by plm
Align neural net output to simd vector size. |
129 |
#if defined(USE_GTK)
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
130 |
if (fX) |
131 |
pcc = GTKCalibrationStart(); |
|
1976
by gtw
Added evaluation speed calibration commands. |
132 |
#endif
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
133 |
|
5859
by plm
Fix compiler warning |
134 |
timeTaken = 0.0; |
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
135 |
for (iIter = 0; n < 0 || iIter < (unsigned int) n;) { |
136 |
double spd; |
|
137 |
if (fInterrupt) |
|
138 |
break; |
|
3856
by Superfly_Jon
Make calibration test multi-threaded |
139 |
|
6046
by plm
Align neural net output to simd vector size. |
140 |
#if defined(USE_MULTITHREAD)
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
141 |
mt_add_tasks(MT_GetNumThreads(), RunEvals, NULL, NULL); |
142 |
(void) MT_WaitForTasks(NULL, 0, FALSE); |
|
143 |
iIter += MT_GetNumThreads(); |
|
3856
by Superfly_Jon
Make calibration test multi-threaded |
144 |
#else
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
145 |
RunEvals(NULL); |
146 |
iIter++; |
|
147 |
#endif
|
|
148 |
||
5859
by plm
Fix compiler warning |
149 |
if (timeTaken <= 0.0) |
150 |
spd = 0.0; |
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
151 |
else
|
152 |
spd = iIter * (EVALS_PER_ITERATION * 1000 / timeTaken); |
|
6046
by plm
Align neural net output to simd vector size. |
153 |
#if defined(USE_GTK)
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
154 |
if (fX) |
155 |
GTKCalibrationUpdate(pcc, (float) spd); |
|
156 |
else
|
|
157 |
#endif
|
|
158 |
if (fShowProgress) { |
|
159 |
outputf(" \rCalibrating: %.0f static evaluations/second", spd); |
|
160 |
fflush(stdout); |
|
161 |
}
|
|
162 |
}
|
|
163 |
||
6046
by plm
Align neural net output to simd vector size. |
164 |
EvalCacheResize(iCacheSize); |
165 |
||
166 |
#if defined(USE_GTK)
|
|
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
167 |
if (fX) |
168 |
GTKCalibrationEnd(pcc); |
|
169 |
#endif
|
|
170 |
||
5859
by plm
Fix compiler warning |
171 |
if (timeTaken > 0.0) { |
5379
by mdpetch
Standardized the code formatting with indent -kr -l120 -fc1 -sc -nut -psl |
172 |
rEvalsPerSec = iIter * (float) (EVALS_PER_ITERATION * 1000 / timeTaken); |
173 |
outputf("\rCalibration result: %.0f static evaluations/second.\n", rEvalsPerSec); |
|
174 |
} else |
|
175 |
outputl(_("Calibration incomplete.")); |
|
1976
by gtw
Added evaluation speed calibration commands. |
176 |
}
|