mirror of https://github.com/Qiskit/qiskit-aer.git
Choose BLAS library path (#543)
* Search blas library under specified dir (-DBLAS_LIB_PATH) * BLAS_LIB_PATH flag explanation
This commit is contained in:
parent
f2ecd87f8f
commit
a2a16a49c6
|
@ -21,6 +21,8 @@ Changelog](http://keepachangelog.com/en/1.0.0/).
|
|||
Added
|
||||
-----
|
||||
- Added high level pulse simulator tests (\#379)
|
||||
- CMake BLAS_LIB_PATH flag to set path to look for BLAS lib (\#543)
|
||||
|
||||
Changed
|
||||
-------
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ option(BUILD_TESTS "Specify whether we want to build tests or not" FALSE)
|
|||
include(CTest)
|
||||
include(compiler_utils)
|
||||
include(Linter)
|
||||
include(findBLASInSpecificPath)
|
||||
|
||||
# Get version information
|
||||
get_version(${VERSION_NUM})
|
||||
|
@ -156,25 +157,26 @@ if(STATIC_LINKING)
|
|||
set(BLA_STATIC TRUE)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
message(STATUS "Looking for Apple BLAS library...")
|
||||
set(BLA_VENDOR "Apple")
|
||||
if(BLAS_LIB_PATH)
|
||||
find_BLAS_in_specific_path(${BLAS_LIB_PATH})
|
||||
else()
|
||||
message(STATUS "Looking for OpenBLAS library...")
|
||||
set(BLA_VENDOR "OpenBLAS")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
message(STATUS "Uncompressing OpenBLAS static library...")
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar "xvfj" "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/win64/lib/openblas.7z"
|
||||
WORKING_DIRECTORY "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/win64/lib/")
|
||||
endif()
|
||||
|
||||
find_package(BLAS QUIET)
|
||||
if(NOT BLAS_FOUND)
|
||||
message(STATUS "OpenBLAS not found. Looking for any other BLAS library...")
|
||||
unset(BLA_VENDOR)
|
||||
find_package(BLAS REQUIRED)
|
||||
if(APPLE)
|
||||
message(STATUS "Looking for Apple BLAS library...")
|
||||
set(BLA_VENDOR "Apple")
|
||||
else()
|
||||
message(STATUS "Looking for OpenBLAS library...")
|
||||
set(BLA_VENDOR "OpenBLAS")
|
||||
endif()
|
||||
if(WIN32)
|
||||
message(STATUS "Uncompressing OpenBLAS static library...")
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E tar "xvfj" "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/win64/lib/openblas.7z" WORKING_DIRECTORY "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/win64/lib/")
|
||||
endif()
|
||||
find_package(BLAS QUIET)
|
||||
if(NOT BLAS_FOUND)
|
||||
message(STATUS "OpenBLAS not found. Looking for any other BLAS library...")
|
||||
unset(BLA_VENDOR)
|
||||
find_package(BLAS REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "BLAS library found: ${BLAS_LIBRARIES}")
|
||||
|
|
|
@ -257,6 +257,14 @@ USER_LIB_PATH
|
|||
Default: No value.
|
||||
Example: ``cmake -DUSER_LIB_PATH=C:\path\to\openblas\libopenblas.so ..``
|
||||
|
||||
BLAS_LIB_PATH
|
||||
Tells CMake the directory to look for the BLAS library instead of the usual paths.
|
||||
If no BLAS library is found under that directory, CMake will raise an error and stop.
|
||||
|
||||
Values: An absolute path with file included.
|
||||
Default: No value.
|
||||
Example: ``cmake -DBLAS_LIB_PATH=/path/to/look/for/blas/ ..``
|
||||
|
||||
STATIC_LINKING
|
||||
Tells the build system whether to create static versions of the programs being built or not.
|
||||
NOTE: On MacOS static linking is not fully working for all versions of GNU G++/Clang
|
||||
|
@ -300,6 +308,18 @@ qiskit-aer$ python ./setup.py install
|
|||
qiskit-aer$ python -m unittest discover -s test -v
|
||||
```
|
||||
|
||||
Alternatively you can run the integration tests in parallel using `stestr`.
|
||||
```
|
||||
qiskit-aer$ stestr run --slowest
|
||||
```
|
||||
|
||||
The `slowest` option will print the slowest tests at the end.
|
||||
Manual for `stestr` can be found [here](https://stestr.readthedocs.io/en/latest/MANUAL.html#).
|
||||
You may need to install it:
|
||||
```
|
||||
qiskit-aer$ pip install stestr
|
||||
```
|
||||
|
||||
The integration tests for Terra addon are included in: `test/terra`.
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
function(find_blas_in_specific_path BLAS_LIB_PATH)
|
||||
|
||||
function(check_blas_lib_found BLAS_LIB_PATH BLAS_LIBS BLAS_FOUND)
|
||||
# This function is intented to be called only from find_blas_in_specific_path
|
||||
# Check if the lib has been found and if it was in a sub of the provided path.
|
||||
# FindBLAS.cmake always search some standard paths so, if no lib is found
|
||||
# below provided BLAS_LIB_PATH, it could have found the BLAS lib at some other place
|
||||
# and not where the user specified
|
||||
if(NOT BLAS_FOUND)
|
||||
return()
|
||||
endif()
|
||||
list(GET BLAS_LIBS 0 FIRST_BLAS_PATH)
|
||||
# Need to add final separator in order to check if BLAS_LIB_PATH is a
|
||||
# parent directory for BLAS_LIBS
|
||||
string(APPEND BLAS_LIB_PATH "/") # already in CMake format
|
||||
file(TO_CMAKE_PATH ${FIRST_BLAS_PATH} FIRST_BLAS_PATH)
|
||||
string(APPEND FIRST_BLAS_PATH "/") # already in CMake format
|
||||
string(FIND ${FIRST_BLAS_PATH} ${BLAS_LIB_PATH} BLAS_DIR_MATCH)
|
||||
if(NOT BLAS_FOUND OR NOT BLAS_DIR_MATCH STREQUAL "0")
|
||||
set(BLAS_FOUND FALSE PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
get_filename_component(BLAS_LIB_PATH ${BLAS_LIB_PATH} ABSOLUTE)
|
||||
message(STATUS "Looking for BLAS library in user defined dir: ${BLAS_LIB_PATH}")
|
||||
file(TO_CMAKE_PATH ${BLAS_LIB_PATH} BLAS_LIB_PATH)
|
||||
if(NOT IS_DIRECTORY ${BLAS_LIB_PATH})
|
||||
message(FATAL_ERROR "${BLAS_LIB_PATH} is not a valid directory")
|
||||
endif()
|
||||
|
||||
# Modify CMAKE_PREFIX_PATH locally to only search in provided dir
|
||||
# (though FindBLAS ALWAYS search certain system dirs)
|
||||
set(CMAKE_PREFIX_PATH ${BLAS_LIB_PATH})
|
||||
|
||||
find_package(BLAS QUIET)
|
||||
# Check if BLAS libs are under provided DIR
|
||||
check_blas_lib_found(${BLAS_LIB_PATH} ${BLAS_LIBRARIES} ${BLAS_FOUND})
|
||||
|
||||
if(NOT BLAS_FOUND AND APPLE)
|
||||
# We may need to search for specific APPLE framework
|
||||
# Try again setting the BLA_VENDOR to APPLE
|
||||
set(BLA_VENDOR "Apple")
|
||||
find_package(BLAS QUIET)
|
||||
check_blas_lib_found(${BLAS_LIB_PATH} ${BLAS_LIBRARIES} ${BLAS_FOUND})
|
||||
endif()
|
||||
|
||||
if(NOT BLAS_FOUND)
|
||||
message(FATAL_ERROR "BLAS library not found in dir: ${BLAS_LIB_PATH}")
|
||||
endif()
|
||||
|
||||
set(BLAS_LIBRARIES ${BLAS_LIBRARIES} PARENT_SCOPE)
|
||||
set(BLAS_FOUND ${BLAS_FOUND} PARENT_SCOPE)
|
||||
set(BLAS_LINKER_FLAGS ${BLAS_LINKER_FLAGS} PARENT_SCOPE)
|
||||
endfunction()
|
Loading…
Reference in New Issue