Building Crafty 22.0 on a Macintosh

Discussion of chess software programming and technical issues.

Moderator: Ras

bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Building Crafty 22.0 on a Macintosh

Post by bob »

sje wrote:
Zach Wegner wrote:
sje wrote:Are any of those custom inline lock routines really that much better than using a plain and portable pthread mutex?
Pthread mutexes don't work with processes, or with Windows.
That's okay, because I don't work with Windows either.

More to the point, the pthreads utilities including mutexes does work (to some extent) under Windows using the Cygwin Unix-on-Windows package.
Here is the question to determine if you can use MUTEXes without incurring a big performance penalty: How often do you acquire them? And when you do acquire them, how long do you hold them?

If you call them frequently, then mutexes are too expensive. If you hold them for just a short period of time, they are even more expensive. How often you acquire them depends on how/when/where you do parallel split operations and how you use locks to protect critical sections such as "NextMove()" and the like...

The more you use locks, the less attractive MUTEXes look. They are for very coarse-grained stuff, not for very fine-grained things like the typical chess program will use them for.
lexx6281

Re: Running Crafty 22.0 on a Macintosh - Summary: POWERPC G4

Post by lexx6281 »

I have been following this thread and wanted to give a summary of how I managed to get Crafty 22.0 to compile cleanly on my POWERPC G4. There's nothing new here that hasn't been covered by different folks on the thread so far, but hopefully will prove useful to someone new to the forum, looking for a quick one-stop summary.

Compiling crafty 22.0
For PowerPC-based OSX 10.4.11

Makefile:
=========
Add


darwin:
$(MAKE) make target=FreeBSD \
CC=gcc CXX=g++ \
CFLAGS=' -Wall -pipe -O3' \
CXFLAGS= \
LDFLAGS= \
LIBS='-lstdc++' \
opt=' -DCPUS=2 -DPOWERPC' \ <-- Add POWERPC option




chess.h
=======
change

# DEFINE CPUS 1
(was CPUS=1)

remove
# define lock_t volatile int



utility.c
=========
change

# if !defined(NEXT) && !defined(__APPLE__)
( was # if !defined(NEXT) )


egtb.cpp
========

Remove
#define lock_t volatile int



(lock_t now only defined once in lock.h)
Failure to remove lock_t entry in egtb.cpp causes a 'lock_t redefined' error, along with a compile failure due to incompatibility between *volatile int and #defined POWERPC OSSpinLock from lock.h


$ gcc --version
powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5370)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


$ make darwin
make target=FreeBSD \
CC=gcc CXX=g++ \
CFLAGS=' -Wall -pipe -O3' \
CXFLAGS= \
LDFLAGS= \
LIBS='-lstdc++' \
opt=' -DCPUS=2 -DPOWERPC' \
crafty-make
gcc -Wall -pipe -O3 -DCPUS=2 -DPOWERPC -DFreeBSD -c crafty.c
g++ -c -DCPUS=2 -DPOWERPC -DFreeBSD egtb.cpp
egtb.cpp:4483: warning: 'TB_CRC_CHECK' initialized and declared 'extern'
gcc -o crafty crafty.o egtb.o -lm -lstdc++
$


$ sudo vi /etc/sysctl.conf

add:

# increase maximum shared memory size
kern.sysv.shmmax=536870912
kern.sysv.shmmin=1
kern.sysv.shmmni=128
kern.sysv.shmseg=32
kern.sysv.shmall=131072

reboot


$ ./crafty
unable to open book file [./book.bin].
book is disabled
unable to open book file [./books.bin].
EGTB access enabled
using tbpath=./TB
0 piece tablebase files found
hash table memory = 96M bytes.
pawn hash table memory = 40M bytes.
EGTB cache memory = 32M bytes.
pondering enabled.
book learning enabled
result learning enabled
book file enabled.
show book statistics

tellicsnoalias set 1 Crafty v22.0 (1 cpus)
tellicsnoalias kibitz Hello from Crafty v22.0! (1 cpus)




If you are upgrading from a version of crafty <20.17, it will give the following error:

"book.bin not made by version 20.17 or later"

(if you start xboard, and then try and use the Analyze feature, the program will quit with a 'broken pipe' error for the same reason).


Recreate the book.bin with v22.0 and you will be good to go.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Four way fat executable available

Post by sje »

I've built a four way (ppc/ppc64/i386/x86-64) fat executable binary version of Crafty for all current Macintosh platforms. It works, at least on the ones I've been able to test. The program is compiled for single core boxes (-DCPU=1), but should of course work on multicore machines. It's just under 5 MB in size, and I'll email a copy to anyone who requests one.

You'll still have to make the /etc/sysctl.conf modification (and then reboot) to pump up the shared memory capability.
lexx6281

Re: Running Crafty 22.1 on a Macintosh - Summary: POWERPC G4

Post by lexx6281 »

Hi all,
First: Thank you all for making the updates to the various scripts to make the POWERPC Mac compile so much cleaner for 22.1 !

Second: On my G4, we now only have the one final issue, which I guess, from reading the thread, is probably outside the scope of what can be altered, due to egtb.cpp being owned by a different author:

If we modify (per previously) the Makefile to allow it to work on G4 (ie - add the -DPOWERPC option), then we still get the errors due to the redefinition of 'lock_t', with the following 'invalid conversion' errors.

As mentioned, manual alteration of the egtb.cpp file to remove the definition of lock_t then allows the compile to complete successfully.


Probably no way to fix this issue, but just posting this as an FYI for any of us still running the old G4 chipsets.... :-)



Example of compile issue - original 22.1 egtb.cpp file.
--------------------------------------------------------------

$ make darwin
make target=FreeBSD \
CC=gcc CXX=g++ \
CFLAGS=' -Wall -pipe -O3' \
CXFLAGS= \
LDFLAGS= \
LIBS='-lstdc++' \
opt=' -DCPUS=2 -DPOWERPC' \
crafty-make
gcc -Wall -pipe -O3 -DCPUS=2 -DPOWERPC -DFreeBSD -c crafty.c
g++ -c -DCPUS=2 -DPOWERPC -DFreeBSD egtb.cpp
egtb.cpp:83:1: warning: "lock_t" redefined
In file included from egtb.cpp:54:
lock.h:78:1: warning: this is the location of the previous definition
egtb.cpp:4484: warning: 'TB_CRC_CHECK' initialized and declared 'extern'
egtb.cpp: In function 'void VTbCloseFile(int, color)':
egtb.cpp:5392: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5392: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5398: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5398: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp: In function 'int TbtProbeTable(int, color, unsigned int, unsigned int)':
egtb.cpp:5741: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5741: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5750: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5750: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5765: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5765: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5782: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5782: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5794: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5794: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5796: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5796: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5802: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5802: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5823: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5823: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5824: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5824: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5825: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5825: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5836: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5836: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5851: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5851: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5860: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5860: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5875: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5875: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5897: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5897: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:5899: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5899: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:5994: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:5994: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:6007: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6007: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:6013: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6013: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:6023: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6023: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:6031: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6031: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:6033: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6033: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:6049: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6049: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:6050: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6050: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:6073: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6073: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:6074: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6074: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:6080: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6080: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
egtb.cpp:6082: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6082: error: initializing argument 1 of 'void OSSpinLockLock(OSSpinLock*)'
egtb.cpp:6086: error: invalid conversion from 'volatile int*' to 'OSSpinLock*'
egtb.cpp:6086: error: initializing argument 1 of 'void OSSpinLockUnlock(OSSpinLock*)'
make[2]: *** [egtb.o] Error 1
make[1]: *** [crafty-make] Error 2
make: *** [darwin] Error 2

$ make clean
rm -f *.o crafty


[success] - After modification to egtb.cpp, to remove definition of lock_t:
------------------------------------------------------------------------------------

$ make darwin
make target=FreeBSD \
CC=gcc CXX=g++ \
CFLAGS=' -Wall -pipe -O3' \
CXFLAGS= \
LDFLAGS= \
LIBS='-lstdc++' \
opt=' -DCPUS=2 -DPOWERPC' \
crafty-make
gcc -Wall -pipe -O3 -DCPUS=2 -DPOWERPC -DFreeBSD -c crafty.c
g++ -c -DCPUS=2 -DPOWERPC -DFreeBSD egtb.cpp
egtb.cpp:4483: warning: 'TB_CRC_CHECK' initialized and declared 'extern'
gcc -o crafty crafty.o egtb.o -lm -lstdc++
$