From fe9d5123ab5a841fd686b9c36179e676dcc42cdc Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Fri, 18 May 2018 09:34:59 +0200 Subject: [PATCH] Automatic detection of available SIMD instruction sets --- backends/simd_instruction_sets.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backends/simd_instruction_sets.py b/backends/simd_instruction_sets.py index 28e1cc8b2..cc47af67c 100644 --- a/backends/simd_instruction_sets.py +++ b/backends/simd_instruction_sets.py @@ -93,3 +93,24 @@ def get_vector_instruction_set(data_type='double', instruction_set='avx'): result['headers'] = headers[instruction_set] return result + + +def get_supported_instruction_sets(): + """List of supported instruction sets on current hardware, or None if query failed.""" + try: + from cpuinfo import get_cpu_info + except ImportError: + return None + + result = [] + required_sse_flags = {'sse', 'sse2', 'ssse3', 'sse4_1', 'sse4_2'} + required_avx_flags = {'avx'} + required_avx512_flags = {'avx512f'} + flags = set(get_cpu_info()['flags']) + if flags.issuperset(required_sse_flags): + result.append("sse") + if flags.issuperset(required_avx_flags): + result.append("avx") + if flags.issuperset(required_avx512_flags): + result.append("avx512") + return result -- GitLab