Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 50683f58 authored by hhakim's avatar hhakim
Browse files

Manage new CMake option USE_OPENBLASO to build the pyfaust wrapper with...

Manage new CMake option USE_OPENBLASO to build the pyfaust wrapper with OpenBLAS-OpenMP Eigen backend and embed the openblaso library in the pyfaust package.
parent 9b669436
Branches
Tags
No related merge requests found
# the script supposes that PWD is the <build directory>/wrapper/python
file(GLOB LIBS _FaustCorePy*dylib _FaustCorePy*dll _FaustCorePy*pxd _FaustCorePy*so) # only one can exist
list(GET LIBS 0 PYLIB)
# add paths of (DY)LD_LIBRARY_PATH in considered directories because GET_RUNTIME_DEPENDENCIES doesn't take it into account
if(APPLE)
#message(STATUS DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH})
if(DEFINED ENV{DYLD_LIBRARY_PATH})
string(REPLACE ":" ";" LIB_PATHS "$ENV{DYLD_LIBRARY_PATH}")
endif()
elseif(UNIX)
#message(STATUS LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH})
if(DEFINED ENV{LD_LIBRARY_PATH})
string(REPLACE ":" ";" LIB_PATHS "$ENV{LD_LIBRARY_PATH}")
endif()
endif()
#message(STATUS "pyfaust lib: ${PYLIB} LIB_PATHS:${LIB_PATHS}")
file(GET_RUNTIME_DEPENDENCIES LIBRARIES ${PYLIB} RESOLVED_DEPENDENCIES_VAR LIBS UNRESOLVED_DEPENDENCIES_VAR ERR_LIBS DIRECTORIES ${LIB_PATHS})
#message(STATUS "libs=${LIBS} err_libs=${ERR_LIBS}")
foreach(LIB IN LISTS LIBS)
string(REGEX MATCH ".*libopenblaso.*" RES ${LIB})
string(LENGTH "${RES}" RES_LEN)
get_filename_component(LIB_FILE ${LIB} NAME)
if(${RES_LEN} GREATER 0)
message(STATUS "system libopenblaso: ${LIB}")
# copy the libopenblaso in pyfaust/lib
message("copying libopenblaso to wrapper/python/pyfaust/lib/${LIB_FILE}")
configure_file(${LIB} pyfaust/lib/${LIB_FILE} COPYONLY)
endif()
endforeach()
......@@ -240,6 +240,7 @@ option(PYTHON_ENCODING "The *.py charset for pyfaust/__init__.py (utf-8, windows
option(FAUST_TORCH "Faust torch backend for the Faust-Matrix/Vector product." OFF)
option(USE_GPU_MOD "Faust cuda backend for the Faust-Matrix/Vector product." OFF)
option(USE_OPENBLASO "Enable the use of OpenBLAS-OpenMP eigen backend in pyfaust (library embedded in the pip package)." OFF)
option(BUILD_COMPLEX_PYX "Building the python wrapper in order to support complex matrices or not." ON)
option(BUILD_FLOAT_PYX "Enabling the support of float matrices in the python wrapper." OFF)
option(BUILD_FLOAT_MEX "Enabling the support of float matrices in the matlab wrappers." OFF)
......
......@@ -175,6 +175,13 @@ if(APPLE AND BUILD_MULTITHREAD OR ${CMAKE_CXX_COMPILER} MATCHES .*clang.*)
file(READ ${FAUST_PYTHON_SRC_DIR}/libomp_loading.py OMP_LIB_LOADING)
endif()
if(USE_OPENBLASO AND UNIX)
file(READ ${FAUST_PYTHON_SRC_DIR}/blasomp_loading.py BLASOMP_LOADING)
set(FAUST_SETUP_PY_LFLAGS "${FAUST_SETUP_PY_LFLAGS}, '-lopenblaso'")
set(FAUST_SETUP_PY_CFLAGS "${FAUST_SETUP_PY_CFLAGS}, '-DEIGEN_USE_BLAS'")
set(PYFAUST_PKG_SUFFIX "-openblaso")
endif()
if(USE_GPU_MOD)
set(FAUST_PYTHON_INCLUDE_DIR "${FAUST_PYTHON_INCLUDE_DIR}, '${GPU_MOD_INCLUDE_DIR}', '${GPU_MOD_INCLUDE_DIR}/../build-cu9.2/', '${FAUST_SRC_LINEAR_OPERATOR_GPU2_DIR}'")
set(FAUST_SETUP_PY_CFLAGS "${FAUST_SETUP_PY_CFLAGS}, '-DUSE_GPU_MOD'")
......@@ -393,6 +400,10 @@ if(UNIX)
add_custom_target(EMBED_LIBOMP_IN_PYFAUST ALL
COMMAND cmake -P ${PROJECT_SOURCE_DIR}/CMake/embed_sys_libomp_into_pyfaust.txt DEPENDS ${FAUST_PYTHON_TARGET} COMMENT "Embedding the libomp library in pyfaust/lib directory")
endif()
if(USE_OPENBLASO)
add_custom_target(EMBED_OPENBLASO_IN_PYFAUST ALL
COMMAND cmake -P ${PROJECT_SOURCE_DIR}/CMake/embed_sys_openblaso_into_pyfaust.txt DEPENDS ${FAUST_PYTHON_TARGET} COMMENT "Embedding the libopenblaso library in pyfaust/lib directory")
endif()
endforeach()
elseif(WIN32)
if(${CMAKE_GENERATOR} MATCHES "Visual Studio")
......
from sys import platform as _pf
from glob import glob
blasomp_loading_verbose = True
internal_blasomp_loading = True
blasomp_name_noext = 'libopenblaso'
def load_lib_blaso():
"""
Loads openblaso if it is embedded in the pyfaust package.
"""
from os.path import join, exists
import sys
import ctypes
import ctypes.util
if _pf == 'darwin':
ext = 'dylib'
elif _pf == 'linux':
ext = 'so'
elif _pf == 'win32':
ext = 'dll'
for p in sys.path:
lib_path = join(p, 'pyfaust/lib/'+blasomp_name_noext+'.'+ext)
lib_path = glob(lib_path+"*")[0]
if exists(lib_path):
ctypes.CDLL(lib_path)
if blasomp_loading_verbose:
print(lib_path+" has been loaded successfully.")
break
else:
print("failed to load " + blasomp_name_noext +
" (didn't find any shared lib in"
" sys.path:", sys.path)
# load liblaso pyfaust embedded library if found in pyfaust location
if _pf in ['linux']:
load_lib_blaso()
# -*- coding: @PYTHON_ENCODING@ -*-
# @PYFAUST_LICENSE_HEADER@
# @BLASOMP_LOADING@
# @OMP_LIB_LOADING@
# @TORCH_LIBS_LOADING@
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment