Last active
February 25, 2016 21:57
-
-
Save matthew-brett/a53778f99b7062cc332d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" Replicates BLIS template selection logic in: | |
https://github.com/flame/blis/blob/0.1.8/build/auto-detect/cpuid_x86.c#L95 | |
""" | |
# pip install x86cpu | |
from x86cpu import info | |
def get_vendor(): | |
if info.vendor == "GenuineIntel": | |
return 'intel' | |
if info.vendor == "AuthenticAMD": | |
return 'amd' | |
# This line why? From: | |
# https://github.com/flame/blis/blob/0.1.8/build/auto-detect/cpuid_x86.c#L95 | |
if info.reg0.eax == 0 or (info.reg0.eax & 0x500) != 0: | |
return 'intel' | |
return 'unknown' | |
# Intel: family, model, extended model | |
FAM_MOD_EXTMOD = { | |
(6, 7, 1): 'penryn', | |
(6, 13, 1): 'dunnington', | |
(6, 10, 2): 'sandybridge', | |
(6, 13, 2): 'sandybridge', | |
(6, 10, 3): 'ivybridge', | |
(6, 14, 3): 'ivybridge', | |
(6, 12, 3): 'haswell', | |
(6, 15, 3): 'haswell', | |
(6, 13, 3): 'broadwell', | |
(6, 5, 4): 'haswell', | |
(6, 6, 4): 'haswell', | |
(6, 7, 4): 'broadwell', | |
(6, 15, 4): 'broadwell', | |
(6, 6, 5): 'broadwell', | |
} | |
# AMD: family, model, extended family | |
FAM_MOD_EXTFAM = { | |
(15, 1, 6): 'bulldozer', | |
(15, 2, 6): 'piledriver', | |
(15, 0, 6): 'steamroller', | |
} | |
# configs are diffferent from chip name for some chips | |
CHIP2CONFIG = dict( | |
ivybridge='sandybridge', | |
broadwell='haswell', | |
penryn='dunnington', | |
steamroller='piledriver') | |
# These configs reset to reference if AVX support is missing | |
NEEDS_AVX = ('sandybridge', 'haswell', 'bulldozer', 'piledriver') | |
def choose_config(): | |
vendor = get_vendor() | |
if get_vendor() not in ('intel', 'amd'): | |
return 'reference' | |
if vendor == 'intel': | |
chip = FAM_MOD_EXTMOD.get( | |
(info.family, info.model, info.extended_model), | |
'reference') | |
else: # AMD | |
chip = FAM_MOD_EXTFAM.get( | |
(info.family, info.model, info.extended_family), | |
'reference') | |
config = CHIP2CONFIG.get(chip, chip) | |
return ('reference' if (config in NEEDS_AVX and not info.supports_avx) | |
else config) | |
print(choose_config()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment