pasky / pachi

A fairly strong Go/Baduk/Weiqi playing program
http://pachi.or.cz/
GNU General Public License v2.0
514 stars 117 forks source link

Memory Auto-Alloc #137

Closed lemonsqueeze closed 4 years ago

lemonsqueeze commented 4 years ago

Attempt to automatically grow tree memory once tree is full. kind of max_tree_size=auto

Right now you have to choose max_tree_size in advance which sucks if you don't know how much you're going to need: Pick too large and memory is wasted, too low and search stops when limit is reached... So idea is to seamlessly allocate a bigger tree, copy current one over and resume search when memory is full. Tricky because this needs to happen within search itself...

Very much of a hack right now, But seems to be doing ok so far, can analyze forever in Sabaki or genmove / ponder over very long thinking times without having to worry about max_tree_size.

lemonsqueeze commented 4 years ago

Something weird going on with tree garbage collection, Losing search results sometimes when analyze is resumed if it's allowed to happen, Investigate ...

lemonsqueeze commented 4 years ago

The pondering hack shouldn't even work ! There's no way the logger thread can stop search - of which it is part - without deadlocking itself. I have no idea what's going on =)

lemonsqueeze commented 4 years ago

Rewritten and cleaned up so it can be integrated properly, this is looking good now. Ended up adding flags support to the search api, trying to tweak it from the outside was getting really messy.

Turns out code was deadlocking but pthread_join() is smart enough to detect it and return right away. So just do it from a detached thread and check pthread_join() from now on.

I think I'll leave tree auto_alloc enabled by default, Can be turned off with auto_alloc=0 or fixed_mem uct parameters.

lemonsqueeze commented 4 years ago

One issue is now max_tree_size param is not the max amount of memory used for tree search anymore, just the initial amount. ie it can grow beyond max_tree_size which is confusing. I guess it'd be better to

Or rename it and add something to control max memory:

lemonsqueeze commented 4 years ago

Or simply

lemonsqueeze commented 4 years ago

Settling on: