Merge pull request #1070 from Flamefire/fix-cpuid2

Fix use of CPUID overwriting registers in use
This commit is contained in:
David Addison 2023-11-18 11:05:42 -08:00 committed by GitHub
commit 16b5be19f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,9 @@
#include "core.h" #include "core.h"
#include "nvmlwrap.h" #include "nvmlwrap.h"
#include "xml.h" #include "xml.h"
#if defined(__x86_64__)
#include <cpuid.h>
#endif
/*******************/ /*******************/
/* XML File Parser */ /* XML File Parser */
@ -412,7 +415,8 @@ ncclResult_t ncclTopoGetXmlFromCpu(struct ncclXmlNode* cpuNode, struct ncclXml*
char vendor[12]; char vendor[12];
} cpuid0; } cpuid0;
asm volatile("cpuid" : "=b" (cpuid0.ebx), "=c" (cpuid0.ecx), "=d" (cpuid0.edx) : "a" (0) : "memory"); unsigned unused;
__cpuid(0, unused, cpuid0.ebx, cpuid0.ecx, cpuid0.edx);
char vendor[13]; char vendor[13];
strncpy(vendor, cpuid0.vendor, 12); strncpy(vendor, cpuid0.vendor, 12);
vendor[12] = '\0'; vendor[12] = '\0';
@ -434,7 +438,8 @@ ncclResult_t ncclTopoGetXmlFromCpu(struct ncclXmlNode* cpuNode, struct ncclXml*
}; };
uint32_t val; uint32_t val;
} cpuid1; } cpuid1;
asm volatile("cpuid" : "=a" (cpuid1.val) : "a" (1) : "memory"); unsigned unused;
__cpuid(1, cpuid1.val, unused, unused, unused);
int familyId = cpuid1.familyId + (cpuid1.extFamilyId << 4); int familyId = cpuid1.familyId + (cpuid1.extFamilyId << 4);
int modelId = cpuid1.modelId + (cpuid1.extModelId << 4); int modelId = cpuid1.modelId + (cpuid1.extModelId << 4);
NCCLCHECK(xmlSetAttrInt(cpuNode, "familyid", familyId)); NCCLCHECK(xmlSetAttrInt(cpuNode, "familyid", familyId));