Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cpp/command/gtp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static const vector<string> knownCommands = {

//Get or change a few limited params dynamically
"kata-get-models",
"kata-get-nn-rows",
"kata-get-param",
"kata-set-param",
"kata-list-params",
Expand Down Expand Up @@ -382,6 +383,11 @@ struct GTPEngine {
double genmoveTimeSum;
std::atomic<int> genmoveExpectedId;

//Rows each NN evaluator ran before its counter was reset or the evaluator rebuilt (foldNNRows),
//so that kata-get-nn-rows counts from the engine's start.
uint64_t nnRowsFolded;
uint64_t humanRowsFolded;

//Positions during this game when genmove was called
std::vector<Sgf::PositionSample> genmoveSamples;

Expand Down Expand Up @@ -429,6 +435,8 @@ struct GTPEngine {
genmoveTimer(),
genmoveTimeSum(0.0),
genmoveExpectedId(0),
nnRowsFolded(0),
humanRowsFolded(0),
genmoveSamples()
{
}
Expand All @@ -454,6 +462,15 @@ struct GTPEngine {
void clearStatsForNewGame() {
}

//numRowsProcessed() is reset by genmove and starts afresh in a rebuilt evaluator: fold it in
//before either, so kata-get-nn-rows only ever grows and its difference around any command holds.
void foldNNRows() {
if(nnEval != NULL)
nnRowsFolded += nnEval->numRowsProcessed();
if(humanEval != NULL)
humanRowsFolded += humanEval->numRowsProcessed();
}

//Specify -1 for the sizes for a default
void setOrResetBoardSize(ConfigParser& cfg, Logger& logger, Rand& seedRand, int boardXSize, int boardYSize, bool loggingToStderr) {
bool wasDefault = false;
Expand All @@ -479,6 +496,7 @@ struct GTPEngine {
if(nnEval != NULL) {
assert(bot != NULL);
bot->stopAndWait();
foldNNRows();
delete bot;
delete nnEval;
delete humanEval;
Expand Down Expand Up @@ -1110,6 +1128,7 @@ struct GTPEngine {
) {
genmoveTimer.reset();

foldNNRows();
nnEval->clearStats();
if(humanEval != NULL)
humanEval->clearStats();
Expand Down Expand Up @@ -2687,6 +2706,14 @@ int MainCmds::gtp(const vector<string>& args) {
}
}
}
else if(command == "kata-get-nn-rows") {
//Rows each NN evaluator has run since the engine started. A cache hit runs none, so the
//difference around a command is the evaluations it cost the device.
nlohmann::json rows;
rows["main"] = engine->nnRowsFolded + (engine->nnEval == NULL ? 0 : engine->nnEval->numRowsProcessed());
rows["human"] = engine->humanRowsFolded + (engine->humanEval == NULL ? 0 : engine->humanEval->numRowsProcessed());
response = rows.dump();
}
else if(command == "kata-get-models") {
nlohmann::json modelsList = nlohmann::json::array();
if(engine->nnEval != NULL) {
Expand Down
5 changes: 5 additions & 0 deletions docs/GTP_Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ In addition to a basic set of [GTP commands](https://www.lysator.liu.se/~gunnar/
* Each item in the array is a json object with at least the following keys: `"name", "internalName", "maxBatchSize", "usesHumanSLProfile", "version", "usingFP16"`.
* This command can be used by controllers to tell if a human SL model is loaded (e.g. one for which `"usesHumanSLProfile"` is true).

* `kata-get-nn-rows`
* Returns a JSON dictionary `{"main": N, "human": M}`: the number of positions (rows) the main model and the human SL model have evaluated since the engine started, `0` for a model that is not loaded.
* A position served from the NN cache is not a row, so the difference between two calls is the neural net work done in between, e.g. around a `genmove` or a `kata-analyze`. Since any command stops a running analysis first, the call that ends one counts all of its rows.
* The counts only grow: `genmove` resetting its per-move statistics and a `boardsize` that rebuilds the evaluators do not reset them.

* `cputime`, `gomill-cpu_time`
* Returns the approximate total wall-clock-time spent during the handling of `genmove` or the various flavors of `genmove_analyze` commands described above so far during the entire current instance of the engine, as a floating point number of seconds. Does NOT currently count time spent during pondering or during the various `lz-analyze`, `kata-analyze`, etc.
* Note: Gomill specifies that its variant of the command should return the total time summed across CPUs. For KataGo, this time is both unuseful and hard to measure because much of the time is spent waiting on the GPU, not on the CPU, and with different threads sometimes blocking each other through the multitheading and often exceeding the number of cores on a user's system, time spent on CPUs is hard to make sense of. So instead we report wall-clock-time, which is far more useful to record and should correspond more closely to what users may want to know for actual practical benchmarking and performance.
Expand Down
Loading