gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] Default reading cache size


From: Gunnar Farnebäck
Subject: [gnugo-devel] Default reading cache size
Date: Fri, 13 Jan 2006 23:58:50 +0100
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/21.3 (sparc-sun-solaris2.9) MULE/5.0 (SAKAKI)

The patch gunnar_7_8.12 in ticket 36
(http://trac.gnugo.org/gnugo/ticket/36) may be somewhat controversial,
so I'd like to hear if anyone has objections.

The issue is this (copied from the ticket):

  The default size of the reading cache is set to 8 MB, which
  translates into 8 * 1024 * 1024 / sizeof(Hashentry) entries.
  Unfortunately the Hashentry size varies with platform, from 24 bytes
  on a typical 32-bit platform to 32 bytes on platforms where either
  ints are 64 bits (not so common) or structs are padded for 8 byte
  alignment (e.g. AMD64).
  
  The consequence is that the number of reading cache entries varies
  with platform, causing different cache behaviour and node counts.
  Potentially it can also cause differences in the move generation.

The solution in the patch is to set the default size to a fixed number
of cache entries instead of a particular memory usage. The -M option
still takes a memory size in MB (and will thus give a different number
of entries for different platforms) if positive while a negative value
gives the default number of cache entries. The --enable-cache-size
configure option behaves in the same way (default setting -1).

Patch appended below for convenience.

/Gunnar

Index: configure.in
===================================================================
RCS file: /cvsroot/gnugo/gnugo/configure.in,v
retrieving revision 1.128
diff -u -r1.128 configure.in
--- configure.in        23 Oct 2005 20:43:37 -0000      1.128
+++ configure.in        2 Nov 2005 00:00:47 -0000
@@ -54,13 +54,15 @@
   --enable-grid-opt=distrust  enable the grid optimsation in non-trusting mode
   --disable-grid-opt          disable the grid optimisation])
 
-default_cache_size=8
+default_cache_size=-1
 default_level=10
 default_semeai_node_limit=500
 default_owl_node_limit=1000
 
 AC_ARG_ENABLE(cache-size,
-  [  --enable-cache-size=n       reserve n MB RAM for caching (8 default)])
+  [  --enable-cache-size=n       reserve n MB RAM for caching (special value -1
+                               default, corresponding to 8-11 MB depending on
+                              platform)])
 
 AC_ARG_ENABLE(level,
   [  --enable-level=n            n = default level (10 standard)])
Index: doc/install.texi
===================================================================
RCS file: /cvsroot/gnugo/gnugo/doc/install.texi,v
retrieving revision 1.23
diff -u -r1.23 install.texi
--- doc/install.texi    23 Oct 2005 20:47:38 -0000      1.23
+++ doc/install.texi    2 Nov 2005 00:00:48 -0000
@@ -85,9 +85,11 @@
 @node Ram Cache
 @subsection Ram Cache
 
-By default, GNU Go makes a cache of 8 Megabytes in RAM for its
+By default, GNU Go makes a cache of about 8 Megabytes in RAM for its
 internal use. The cache is used to store intermediate results during
-its analysis of the position.
+its analysis of the position. More precisely the default cache size is
+350000 entries, which translates to 8.01 MB on typical 32 bit
+platforms and 10.68 MB on typical 64 bit platforms.
 
 Increasing the cache size will often give a modest speed improvement.
 If your system has lots of RAM, consider increasing the cache
@@ -114,7 +116,8 @@
 
 @noindent
 creates a cache of size 32 megabytes. If you omit this, your default
-cache size will be 8 MB. You must recompile and reinstall
+cache size will be 8-11 MB as discussed above. Setting cache size
+negative also gives the default size. You must recompile and reinstall
 GNU Go after reconfiguring it by running @command{make} and
 @command{make install}.
 
Index: engine/cache.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.c,v
retrieving revision 1.48
diff -u -r1.48 cache.c
--- engine/cache.c      18 Oct 2005 17:22:28 -0000      1.48
+++ engine/cache.c      2 Nov 2005 00:00:48 -0000
@@ -83,7 +83,9 @@
 
 
 
-/* Initialize the transposition table. */
+/* Initialize the transposition table. Non-positive memsize means use
+ * the default size of DEFAULT_NUMBER_OF_CACHE_ENTRIES entries.
+ */
 
 static void
 tt_init(Transposition_table *table, int memsize)
@@ -94,7 +96,10 @@
   hash_init();
   keyhash_init();
 
-  num_entries = memsize / sizeof(table->entries[0]);
+  if (memsize > 0)
+    num_entries = memsize / sizeof(table->entries[0]);
+  else
+    num_entries = DEFAULT_NUMBER_OF_CACHE_ENTRIES;
 
   table->num_entries = num_entries;
   table->entries     = malloc(num_entries * sizeof(table->entries[0]));
@@ -289,6 +294,12 @@
 reading_cache_clear()
 {
   tt_clear(&ttable);
+}
+
+float
+reading_cache_default_size()
+{
+  return DEFAULT_NUMBER_OF_CACHE_ENTRIES * sizeof(Hashentry) / 1024.0 / 1024.0;
 }
 
 
Index: engine/cache.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.h,v
retrieving revision 1.52
diff -u -r1.52 cache.h
--- engine/cache.h      12 Jun 2005 09:34:13 -0000      1.52
+++ engine/cache.h      2 Nov 2005 00:00:48 -0000
@@ -96,6 +96,11 @@
 
 extern Transposition_table ttable;
 
+/* Number of cache entries to use by default if no cache memory usage
+ * has been set explicitly.
+ */
+#define DEFAULT_NUMBER_OF_CACHE_ENTRIES 350000
+
 void tt_free(Transposition_table *table);
 int  tt_get(Transposition_table *table, enum routine_id routine,
            int target1, int target2, int remaining_depth,
Index: engine/liberty.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/liberty.h,v
retrieving revision 1.248
diff -u -r1.248 liberty.h
--- engine/liberty.h    19 Oct 2005 09:55:04 -0000      1.248
+++ engine/liberty.h    2 Nov 2005 00:00:49 -0000
@@ -196,6 +196,7 @@
 
 void reading_cache_init(int bytes);
 void reading_cache_clear(void);
+float reading_cache_default_size(void);
 
 /* reading.c */
 int attack(int str, int *move);
Index: interface/main.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/main.c,v
retrieving revision 1.124
diff -u -r1.124 main.c
--- interface/main.c    22 Oct 2005 15:05:03 -0000      1.124
+++ interface/main.c    2 Nov 2005 00:00:52 -0000
@@ -469,8 +469,11 @@
                "Owl node limit: %d\n", OWL_NODE_LIMIT);
        fprintf(stdout,
                "Semeai node limit: %d\n", SEMEAI_NODE_LIMIT);
-       fprintf(stdout,
-               "Cache size: %d MB\n", DEFAULT_MEMORY);
+       if (DEFAULT_MEMORY == -1)
+         fprintf(stdout, "Cache size: %d MB (special default value)\n",
+                 DEFAULT_MEMORY);
+       else
+         fprintf(stdout, "Cache size: %d MB\n", DEFAULT_MEMORY);
 
        return EXIT_SUCCESS;
        break;
@@ -1443,7 +1446,7 @@
    --score aftermath --capture-all-dead --chinese-rules   Tromp-Taylor score\n\
 \n\
 Cache size (higher=more memory usage, faster unless swapping occurs):\n\
-   -M, --cache-size <megabytes>  RAM cache for hashing (default %4.1f Mb)\n\
+   -M, --cache-size <megabytes>  RAM cache for caching (default %4.1f Mb)\n\
 \n\
 "
 
@@ -1543,7 +1546,8 @@
 show_help(void)
 {
   printf(USAGE, DEFAULT_LEVEL);
-  printf(USAGE1, (float) DEFAULT_MEMORY);
+  printf(USAGE1, DEFAULT_MEMORY <= 0 ? reading_cache_default_size() :
+        (float) DEFAULT_MEMORY);
   printf(USAGE2, MIN_BOARD, MAX_BOARD, MAX_HANDICAP);
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]