Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Utility script to know which core was detected by openblas runtime compiled with DYNAMIC_ARCH=1
# See: https://github.com/xianyi/OpenBLAS/wiki/faq#usage-1
# Set the OPENBLAS_CORETYPE environment variable to override the detection.
# List of supported cores:
# https://github.com/xianyi/OpenBLAS/blob/develop/driver/others/dynamic.c#L337
import os.path as op
import numpy as np
from ctypes import WinDLL, c_char_p
def openblas_get_corename(dll_name='libopenblaspy.dll'):
dll_path = op.join(np.core.__path__[0], dll_name)
openblas = WinDLL(dll_path)
openblas.openblas_get_corename.restype = c_char_p
return openblas.openblas_get_corename().decode('ascii')
print(openblas_get_corename())
# See: https://github.com/xianyi/OpenBLAS/wiki/faq#usage-1
# Set the OPENBLAS_CORETYPE environment variable to override the detection.
# List of supported cores:
# https://github.com/xianyi/OpenBLAS/blob/develop/driver/others/dynamic.c#L337
import os
import sys
import numpy as np
from ctypes import cdll, c_char_p
if sys.platform == 'darwin':
ext = '.dylib'
else:
ext = '.so'
DEFAULT_PATH = '/opt/OpenBLAS/lib/libopenblas' + ext
def openblas_get_corename(dll_path=DEFAULT_PATH):
openblas = cdll.LoadLibrary(dll_path)
openblas.openblas_get_corename.restype = c_char_p
return openblas.openblas_get_corename().decode('ascii')
if len(sys.argv) > 1:
dll_path = sys.argv[1]
else:
dll_path = DEFAULT_PATH
libs_folder = os.path.join(np.__path__[0], '.libs')
if os.path.exists(libs_folder):
matching = sorted(fn for fn in os.listdir(libs_folder)
if fn.startswith('libopenblas') and ext in fn)
if len(matching) > 0:
dll_path = os.path.join(libs_folder, matching[0])
if not os.path.exists(dll_path):
raise ValueError('Could not find openblas at: %s' % dll_path)
print("OpenBLAS found at: %s" % dll_path)
print(openblas_get_corename(dll_path=dll_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment