normalize constants to align with resource classes
Changes the lowercased constants to uppercase and replaces the : with a _ character. This aligns with the naming convention for resource classes in the placement API. Change-Id: Ic8e87ff8db5b1893d2060af01bf48adda712a27c
This commit is contained in:
parent
6f4b514145
commit
9452af54b1
76
README.rst
76
README.rst
|
@ -22,12 +22,12 @@ by simply importing the os_traits module and referencing one of the module's
|
|||
traits constants::
|
||||
|
||||
$ python
|
||||
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
|
||||
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
|
||||
[GCC 5.3.1 20160413] on linux2
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import os_traits as ot
|
||||
>>> print ot.HW_CPU_X86_SSE42
|
||||
hw:cpu:x86:sse42
|
||||
HW_CPU_X86_SSE42
|
||||
|
||||
Don't know what the symbol names are for the `os_traits` module? There's a
|
||||
helper method for that::
|
||||
|
@ -60,39 +60,39 @@ helper method for that::
|
|||
|
||||
Want to see the trait strings for a subset of traits? There's a method for that too::
|
||||
|
||||
>>> pprint.pprint(ot.get_traits(ot.NAMESPACES['x86']))
|
||||
['hw:cpu:x86:aes-ni',
|
||||
'hw:cpu:x86:avx512er',
|
||||
'hw:cpu:x86:avx512cd',
|
||||
'hw:cpu:x86:tbm',
|
||||
'hw:cpu:x86:tsx',
|
||||
'hw:cpu:x86:fma3',
|
||||
'hw:cpu:x86:svm',
|
||||
'hw:cpu:x86:fma4',
|
||||
'hw:cpu:x86:mpx',
|
||||
'hw:cpu:x86:sse2',
|
||||
'hw:cpu:x86:sse3',
|
||||
'hw:cpu:x86:mmx',
|
||||
'hw:cpu:x86:ssse3',
|
||||
'hw:cpu:x86:sse4a',
|
||||
'hw:cpu:x86:avx2',
|
||||
'hw:cpu:x86:sgx',
|
||||
'hw:cpu:x86:avx',
|
||||
'hw:cpu:x86:avx512bw',
|
||||
'hw:cpu:x86:avx512dq',
|
||||
'hw:cpu:x86:sse',
|
||||
'hw:cpu:x86:sha',
|
||||
'hw:cpu:x86:avx512f',
|
||||
'hw:cpu:x86:f16c',
|
||||
'hw:cpu:x86:sse41',
|
||||
'hw:cpu:x86:sse42',
|
||||
'hw:cpu:x86:vmx',
|
||||
'hw:cpu:x86:asf',
|
||||
'hw:cpu:x86:bmi2',
|
||||
'hw:cpu:x86:clmul',
|
||||
'hw:cpu:x86:avx512vl',
|
||||
'hw:cpu:x86:avx512pf',
|
||||
'hw:cpu:x86:xop',
|
||||
'hw:cpu:x86:bmi',
|
||||
'hw:cpu:x86:abm',
|
||||
'hw:cpu:x86:3dnow']
|
||||
>>> pprint.pprint(ot.get_traits(ot.NAMESPACES['X86']))
|
||||
['HW_CPU_X86_AES-NI',
|
||||
'HW_CPU_X86_AVX512ER',
|
||||
'HW_CPU_X86_AVX512CD',
|
||||
'HW_CPU_X86_TBM',
|
||||
'HW_CPU_X86_TSX',
|
||||
'HW_CPU_X86_FMA3',
|
||||
'HW_CPU_X86_SVM',
|
||||
'HW_CPU_X86_FMA4',
|
||||
'HW_CPU_X86_MPX',
|
||||
'HW_CPU_X86_SSE2',
|
||||
'HW_CPU_X86_SSE3',
|
||||
'HW_CPU_X86_MMX',
|
||||
'HW_CPU_X86_SSSE3',
|
||||
'HW_CPU_X86_SSE4A',
|
||||
'HW_CPU_X86_AVX2',
|
||||
'HW_CPU_X86_SGX',
|
||||
'HW_CPU_X86_AVX',
|
||||
'HW_CPU_X86_AVX512BW',
|
||||
'HW_CPU_X86_AVX512DQ',
|
||||
'HW_CPU_X86_SSE',
|
||||
'HW_CPU_X86_SHA',
|
||||
'HW_CPU_X86_AVX512F',
|
||||
'HW_CPU_X86_F16C',
|
||||
'HW_CPU_X86_SSE41',
|
||||
'HW_CPU_X86_SSE42',
|
||||
'HW_CPU_X86_VMX',
|
||||
'HW_CPU_X86_ASF',
|
||||
'HW_CPU_X86_BMI2',
|
||||
'HW_CPU_X86_CLMUL',
|
||||
'HW_CPU_X86_AVX512VL',
|
||||
'HW_CPU_X86_AVX512PF',
|
||||
'HW_CPU_X86_XOP',
|
||||
'HW_CPU_X86_BMI',
|
||||
'HW_CPU_X86_ABM',
|
||||
'HW_CPU_X86_3DNOW']
|
||||
|
|
|
@ -28,7 +28,7 @@ def get_symbol_names(prefix=None):
|
|||
"""Returns the names of symbols of trait strings in the os_traits module,
|
||||
optionally filtered by a supplied prefix.
|
||||
|
||||
:param prefix: Optional string prefix to filter by. e.g. 'hw:'
|
||||
:param prefix: Optional string prefix to filter by. e.g. 'HW_'
|
||||
"""
|
||||
excluded_keys = ('NAMESPACES',)
|
||||
excluded_values = NAMESPACES.values()
|
||||
|
@ -47,7 +47,7 @@ def get_traits(prefix=None):
|
|||
"""Returns the trait strings in the os_traits module, optionally filtered
|
||||
by a supplied prefix.
|
||||
|
||||
:param prefix: Optional string prefix to filter by. e.g. 'hw:'
|
||||
:param prefix: Optional string prefix to filter by. e.g. 'HW_'
|
||||
"""
|
||||
excluded_keys = ('NAMESPACES',)
|
||||
excluded_values = NAMESPACES.values()
|
||||
|
|
|
@ -13,63 +13,63 @@
|
|||
# under the License.
|
||||
|
||||
# All hardware-specific features are prefixed with this namespace
|
||||
_HW_NS = 'hw:'
|
||||
_HW_NS = 'HW_'
|
||||
|
||||
# All CPU-specific features are prefixed with this namespace
|
||||
_CPU_NS = _HW_NS + 'cpu:'
|
||||
_CPU_NS = _HW_NS + 'CPU_'
|
||||
|
||||
_CPU_X86_NS = _CPU_NS + 'x86:'
|
||||
_CPU_X86_NS = _CPU_NS + 'X86_'
|
||||
|
||||
# ref: https://en.wikipedia.org/wiki/Streaming_SIMD_Extensions
|
||||
HW_CPU_X86_AVX = _CPU_X86_NS + 'avx'
|
||||
HW_CPU_X86_AVX2 = _CPU_X86_NS + 'avx2'
|
||||
HW_CPU_X86_CLMUL = _CPU_X86_NS + 'clmul'
|
||||
HW_CPU_X86_FMA3 = _CPU_X86_NS + 'fma3'
|
||||
HW_CPU_X86_FMA4 = _CPU_X86_NS + 'fma4'
|
||||
HW_CPU_X86_F16C = _CPU_X86_NS + 'f16c'
|
||||
HW_CPU_X86_MMX = _CPU_X86_NS + 'mmx'
|
||||
HW_CPU_X86_SSE = _CPU_X86_NS + 'sse'
|
||||
HW_CPU_X86_SSE2 = _CPU_X86_NS + 'sse2'
|
||||
HW_CPU_X86_SSE3 = _CPU_X86_NS + 'sse3'
|
||||
HW_CPU_X86_SSSE3 = _CPU_X86_NS + 'ssse3'
|
||||
HW_CPU_X86_SSE41 = _CPU_X86_NS + 'sse41'
|
||||
HW_CPU_X86_SSE42 = _CPU_X86_NS + 'sse42'
|
||||
HW_CPU_X86_SSE4A = _CPU_X86_NS + 'sse4a'
|
||||
HW_CPU_X86_XOP = _CPU_X86_NS + 'xop'
|
||||
HW_CPU_X86_3DNOW = _CPU_X86_NS + '3dnow'
|
||||
HW_CPU_X86_AVX = _CPU_X86_NS + 'AVX'
|
||||
HW_CPU_X86_AVX2 = _CPU_X86_NS + 'AVX2'
|
||||
HW_CPU_X86_CLMUL = _CPU_X86_NS + 'CLMUL'
|
||||
HW_CPU_X86_FMA3 = _CPU_X86_NS + 'FMA3'
|
||||
HW_CPU_X86_FMA4 = _CPU_X86_NS + 'FMA4'
|
||||
HW_CPU_X86_F16C = _CPU_X86_NS + 'F16C'
|
||||
HW_CPU_X86_MMX = _CPU_X86_NS + 'MMX'
|
||||
HW_CPU_X86_SSE = _CPU_X86_NS + 'SSE'
|
||||
HW_CPU_X86_SSE2 = _CPU_X86_NS + 'SSE2'
|
||||
HW_CPU_X86_SSE3 = _CPU_X86_NS + 'SSE3'
|
||||
HW_CPU_X86_SSSE3 = _CPU_X86_NS + 'SSSE3'
|
||||
HW_CPU_X86_SSE41 = _CPU_X86_NS + 'SSE41'
|
||||
HW_CPU_X86_SSE42 = _CPU_X86_NS + 'SSE42'
|
||||
HW_CPU_X86_SSE4A = _CPU_X86_NS + 'SSE4A'
|
||||
HW_CPU_X86_XOP = _CPU_X86_NS + 'XOP'
|
||||
HW_CPU_X86_3DNOW = _CPU_X86_NS + '3DNOW'
|
||||
# ref: https://en.wikipedia.org/wiki/AVX-512
|
||||
HW_CPU_X86_AVX512F = _CPU_X86_NS + 'avx512f' # foundation
|
||||
HW_CPU_X86_AVX512CD = _CPU_X86_NS + 'avx512cd' # conflict detection
|
||||
HW_CPU_X86_AVX512PF = _CPU_X86_NS + 'avx512pf' # prefetch
|
||||
HW_CPU_X86_AVX512ER = _CPU_X86_NS + 'avx512er' # exponential + reciprocal
|
||||
HW_CPU_X86_AVX512VL = _CPU_X86_NS + 'avx512vl' # vector length extensions
|
||||
HW_CPU_X86_AVX512BW = _CPU_X86_NS + 'avx512bw' # byte + word
|
||||
HW_CPU_X86_AVX512DQ = _CPU_X86_NS + 'avx512dq' # double word + quad word
|
||||
HW_CPU_X86_AVX512F = _CPU_X86_NS + 'AVX512F' # foundation
|
||||
HW_CPU_X86_AVX512CD = _CPU_X86_NS + 'AVX512CD' # conflict detection
|
||||
HW_CPU_X86_AVX512PF = _CPU_X86_NS + 'AVX512PF' # prefetch
|
||||
HW_CPU_X86_AVX512ER = _CPU_X86_NS + 'AVX512ER' # exponential + reciprocal
|
||||
HW_CPU_X86_AVX512VL = _CPU_X86_NS + 'AVX512VL' # vector length extensions
|
||||
HW_CPU_X86_AVX512BW = _CPU_X86_NS + 'AVX512BW' # byte + word
|
||||
HW_CPU_X86_AVX512DQ = _CPU_X86_NS + 'AVX512DQ' # double word + quad word
|
||||
# ref: https://en.wikipedia.org/wiki/Bit_Manipulation_Instruction_Sets
|
||||
HW_CPU_X86_ABM = _CPU_X86_NS + 'abm'
|
||||
HW_CPU_X86_BMI = _CPU_X86_NS + 'bmi'
|
||||
HW_CPU_X86_BMI2 = _CPU_X86_NS + 'bmi2'
|
||||
HW_CPU_X86_TBM = _CPU_X86_NS + 'tbm'
|
||||
HW_CPU_X86_ABM = _CPU_X86_NS + 'ABM'
|
||||
HW_CPU_X86_BMI = _CPU_X86_NS + 'BMI'
|
||||
HW_CPU_X86_BMI2 = _CPU_X86_NS + 'BMI2'
|
||||
HW_CPU_X86_TBM = _CPU_X86_NS + 'TBM'
|
||||
# ref: https://en.wikipedia.org/wiki/AES_instruction_set
|
||||
HW_CPU_X86_AESNI = _CPU_X86_NS + 'aes-ni'
|
||||
HW_CPU_X86_AESNI = _CPU_X86_NS + 'AES-NI'
|
||||
# ref: https://en.wikipedia.org/wiki/Intel_SHA_extensions
|
||||
HW_CPU_X86_SHA = _CPU_X86_NS + 'sha'
|
||||
HW_CPU_X86_SHA = _CPU_X86_NS + 'SHA'
|
||||
# ref: https://en.wikipedia.org/wiki/Intel_MPX
|
||||
HW_CPU_X86_MPX = _CPU_X86_NS + 'mpx'
|
||||
HW_CPU_X86_MPX = _CPU_X86_NS + 'MPX'
|
||||
# ref: https://en.wikipedia.org/wiki/Software_Guard_Extensions
|
||||
HW_CPU_X86_SGX = _CPU_X86_NS + 'sgx'
|
||||
HW_CPU_X86_SGX = _CPU_X86_NS + 'SGX'
|
||||
# ref: https://en.wikipedia.org/wiki/Transactional_Synchronization_Extensions
|
||||
HW_CPU_X86_TSX = _CPU_X86_NS + 'tsx'
|
||||
HW_CPU_X86_TSX = _CPU_X86_NS + 'TSX'
|
||||
# ref: https://en.wikipedia.org/wiki/Advanced_Synchronization_Facility
|
||||
HW_CPU_X86_ASF = _CPU_X86_NS + 'asf'
|
||||
HW_CPU_X86_ASF = _CPU_X86_NS + 'ASF'
|
||||
# ref: https://en.wikipedia.org/wiki/VT-x
|
||||
HW_CPU_X86_VMX = _CPU_X86_NS + 'vmx'
|
||||
HW_CPU_X86_VMX = _CPU_X86_NS + 'VMX'
|
||||
# ref: https://en.wikipedia.org/wiki/AMD-V
|
||||
HW_CPU_X86_SVM = _CPU_X86_NS + 'svm'
|
||||
HW_CPU_X86_SVM = _CPU_X86_NS + 'SVM'
|
||||
|
||||
NAMESPACES = {
|
||||
'hardware': _HW_NS,
|
||||
'hw': _HW_NS,
|
||||
'cpu': _CPU_NS,
|
||||
'x86': _CPU_X86_NS,
|
||||
'HARDWARE': _HW_NS,
|
||||
'HW': _HW_NS,
|
||||
'CPU': _CPU_NS,
|
||||
'X86': _CPU_X86_NS,
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class TestOs_traits(base.TestCase):
|
|||
|
||||
def test_trait(self):
|
||||
trait = ot.HW_CPU_X86_SSE42
|
||||
self.assertEqual("hw:cpu:x86:sse42", trait)
|
||||
self.assertEqual("HW_CPU_X86_SSE42", trait)
|
||||
|
||||
def test_get_symbol_names(self):
|
||||
names = ot.get_symbol_names()
|
||||
|
@ -36,16 +36,16 @@ class TestOs_traits(base.TestCase):
|
|||
|
||||
def test_namespaces(self):
|
||||
namespaces = ot.NAMESPACES
|
||||
self.assertIn(("hardware", "hw:"), namespaces.items())
|
||||
self.assertIn(("HARDWARE", "HW_"), namespaces.items())
|
||||
self.assertEqual(4, len(namespaces))
|
||||
|
||||
def test_get_traits(self):
|
||||
traits = ot.get_traits(ot.NAMESPACES['x86'])
|
||||
self.assertIn("hw:cpu:x86:sse42", traits)
|
||||
traits = ot.get_traits(ot.NAMESPACES['X86'])
|
||||
self.assertIn("HW_CPU_X86_SSE42", traits)
|
||||
self.assertEqual(35, len(traits))
|
||||
|
||||
def test_check_traits(self):
|
||||
traits = set(["hw:cpu:x86:sse42", "hw:cpu:x86:xop"])
|
||||
traits = set(["HW_CPU_X86_SSE42", "HW_CPU_X86_XOP"])
|
||||
not_traits = set(["not_trait1", "not_trait2"])
|
||||
|
||||
check_traits = []
|
||||
|
|
Loading…
Reference in New Issue