Replies: 5 comments 6 replies
-
Don’t know how helpful it is, but issue #2755 also talks about hash usage. |
Beta Was this translation helpful? Give feedback.
-
A common rule of thumb ( from ancient chess computer days) is that a user should be using about 70% of the available hash. So that depends on time and how fast your computer and the number of threads. On some modern hardware with a large number of cores and threads, a large hash may get filled very fast, in just a few minutes. If you are only doing very short search with just a single thread, a large hash is not needed. This is the reason why hash utilization is being reported on the command line, it is useful information. If you are using Windows Large Pages with default settings, best practice is to set hash in 2048 MB increments, -> 2048, 4096, 6144 etc. |
Beta Was this translation helpful? Give feedback.
-
improving docs would be useful I guess. The rule of thumb is, never more than the computer can support, i.e. avoid more than say 70% of total RAM (unless you have a lot) seems a good idea (assuming you have a single chess engine running, not matches between multiple engines). Usually, you need to have a look at how much hash is used in search, this depends on TC. Probably ideal is to have the hash only say, 50-70% filled. The default hash is almost always too small on modern computers, but the UCI protocol suggests using a small number. Most memory related problems seem to come from table base use. The rule if thumb IMO seems to be, if you use N man TB, leave enough memory free for N-1 man TB to be in RAM. |
Beta Was this translation helpful? Give feedback.
-
There is no right hash size, everything depend on your workloads. Just monitor the UCI output, i.e., by parsing debug log, and see the "hashfull" value. If it reaches 1000, try to increase the hash size. If the hash is almost full but never gets full, you get optimal results in terms of higer number of nodes evaluated, or higher NPS values. It is always faster to get results from cache for a duplicate position, then to re-evaluate a position again. The StockFish chess engine tries to allocate an approximate time to reach a given depth. You never know for sure (in milliseconds) how long will it take to evaluate a position given a particular depth. However, it should be taken into consideration that StockFish does not evaluate all possible moves to that depth. Therefore, a larger cache typically evaluates more moves even at a higher time cost, but leading to better results. A larger cache is especially useful if your CPU has many threads and cores; above a certain number of threads, a larger cache can provide faster results. A larger cache size allows the engine to avoid recalculating the same position caused by different moves. So it might take slower but give higher quality results, which means different but better results. Instead of counting all possible moves up to a certain number of plies, the engine tries to evaluate only the best reasonable moves. With larger cache sizes, more moves are evaluated to the specified search depth. Therefore, with a larger cache, we can achieve higher seldepth (selective search depth in layers) and more evaluated nodes, if not higher nodes per second (NPS). Some say that a larger chess engine hash actually slows down the result because it doesn't fit in the CPU cache, e.g. 18MB on an Intel i5-12500 CPU. The argument goes that larger chess engine hashes produce more CPU cache misses and are thus slower than smaller hashes. However, a CPU cache miss is not as expensive as a chess engine re-evaluating a position. You can get the facts by issuing the following command to a UCI engine with a 1MB cache (assuming your CPU has 12 threads):
On my computer, it gave the following results: Depth: 30, Threads: 12, Cache: 1 MB
If I run the same commands, but the cache size is 32768 MB rather than 1 MB ( Depth: 30, Threads: 12, Cache: 32768 MB (32 GB)
As you can see, the engine with the larger cache evaluates to a higher number of nodes and a higher NPS and higher "seldepth". The moves recommended by the engine are also different, starting from the second ply (d7d5 vs. g8f6). For example, at 12 threads and 30 depth, a sufficiently large cache results in a 15% increase in NPS, a 27% increase in the number of evaluation nodes, but a 14% increase in total time. The value after "hashfull" means the fullness of the cache space in tens of percentage points, i.e., "hashfull 1000" mean 100.0%; "hashfull 22" mean 2.2%. The difference is more pronounced with more threads (96) and greater depth (45). Although it only increased the number of evaluated nodes by 6%, it achieved a 22% increase in NPS and a 20% decrease in time. Here are the results: Depth: 45, Threads: 96, Cache: 1 MB
Depth: 45, Threads: 96, Cache: 327680 MB (320 GB)
Therefore, I recommend setting the cache memory size to the maximum size available RAM allows (but don't swap out memory). P.S. If I set the limit by time instead of number of moves (e.g. "go movetime 3600000" makes the evaluation take an hour), on a CPU with 12 threads and 32GB cache it takes about 10 minutes to completely fill the cache space. However, even for an hour-long calculation, larger cache sizes give better results. |
Beta Was this translation helpful? Give feedback.
-
For posterity, a test is available in the wiki showing the elo cost of a small hash
https://github.com/official-stockfish/Stockfish/wiki/Useful-data#elo-cost-of-small-hash |
Beta Was this translation helpful? Give feedback.
-
Hey,
I noticed that almost all of Stockfish's settings are well documented, except for the hash size. The readme only says to set it after the threads. But what is the right hash size?
I have often read that bigger <> better. This issue discusses the correct hash size for the TCEC. There it is described that there are a variety of factors for the correct hash size and no general statement can be made. But how do I test which hash size is the right one for my system? Which benchmarks should I test and what should I look out for?
I once saw a Stockfish fork where a formula was given. But I can't find it right now. I think this is a question that many Stockfish users ask themselves over time. Since there is probably no simple short answer, perhaps a wiki article for this would be useful.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions