Discussion of anything and everything relating to chess playing software and machines.
Moderators: hgm, Dann Corbit, Harvey Williamson
Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
-
zullil
- Posts: 6442
- Joined: Mon Jan 08, 2007 11:31 pm
- Location: PA USA
- Full name: Louis Zulli
Post
by zullil » Fri Apr 09, 2010 12:35 pm
Having now found a way to toggle hyper-threading off and on, I can confirm that the code below does
not work on my dual quad-core Intel 5520 Mac Pro.
The printf statement produces 16 8 8 in both cases.
Code: Select all
/// HT_enabled() returns true if hyper-threading is enabled on current machine
static bool HT_enabled() {
char CPUString[0x20];
int CPUInfo[4] = {-1};
int nIds, nLogicalCPU, nCores;
// Detect CPU producer
__cpuid(CPUInfo, 0);
nIds = CPUInfo[0];
memset(CPUString, 0, sizeof(CPUString));
memcpy(&CPUString[0], &CPUInfo[1], sizeof(int));
memcpy(&CPUString[4], &CPUInfo[3], sizeof(int));
memcpy(&CPUString[8], &CPUInfo[2], sizeof(int));
// Not an Intel CPU or CPUID.4 not supported
if (strcmp(CPUString, "GenuineIntel") || nIds < 4)
return false;
// Detect if HT Technology is supported
__cpuid(CPUInfo, 1);
if (!((CPUInfo[3] >> 28) & 1))
return false;
nLogicalCPU = (CPUInfo[1] >> 16) & 0xFF;
// Detect number of cores
__cpuid(CPUInfo, 4);
nCores = 1 + ((CPUInfo[0] >> 26) & 0x3F);
printf("%d %d %d\n", nLogicalCPU, nCores, builtin_cpu_count());
return nLogicalCPU > nCores;
}
-
mcostalba
- Posts: 2684
- Joined: Sat Jun 14, 2008 7:17 pm
Post
by mcostalba » Fri Apr 09, 2010 5:16 pm
zullil wrote:Having now found a way to toggle hyper-threading off and on, I can confirm that the code below does not work on my dual quad-core Intel 5520 Mac Pro.
The printf statement produces 16 8 8 in both cases.
Hi Louis,
thanks for testing this.
We will probably revert HT detection entirely and fall back on 1.6.3 behaviour that is not perfect but at least gives no surprises and people seems already used to it.
Making HT detection to work in all cases seems very complex: you need to add a lot of obscure code very different from what you are supposed to find in a chess engine, more similar to OS kernel code
I also take the chance to highlight that HT detection has _nothing_ to do with playing strength, crashes or other strange behavior. The only net effect is that your engine will run using less cores of what actually could run, but you can easily workaround this simply setting "threads" UCI parameters to the number of actual cores your machine has. You can do this with any GUI or even from command line.
-
BrandonSi
Post
by BrandonSi » Fri Apr 09, 2010 7:53 pm
I haven't looked at this myself, but you should be able to get a physical core count vs logical core count by deconstructing the APIC ID for each logical cpu (or x2APIC for x64).. LOGICAL_ID vs CORE_ID. Was that the route taken in Stockfish?
I agree though, not much benefit in figuring this out, just let the user do the work.
-
Ralph Stoesser
- Posts: 408
- Joined: Sat Mar 06, 2010 8:28 am
Post
by Ralph Stoesser » Sat Apr 10, 2010 12:47 am
mcostalba wrote:BrandonSi wrote:I haven't looked at this myself
Please, if interested take a look at:
http://software.intel.com/en-us/article ... umeration/
If you (or someone else) is able to come up with a working patch for SF out of that document then you are my new code idol

At the Intel site is also source code available.
The desired function:
Code: Select all
/*
* GetSysProcessorCoreCount
*
* Returns count of processor cores in the system that were enumerated by this app
*
* Arguments: None
*
* Return: Number of physical processors or 0 if number can not be calculated
*/
unsigned GetSysProcessorCoreCount()
{
if (!glbl_ptr->EnumeratedCoreCount)
InitCpuTopology();
if (glbl_ptr->error) return 0;
return glbl_ptr->EnumeratedCoreCount;
}
Only a few thousend lines of utility code behind the scene (InitCpuTopology()) to include ...
