diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 80a1a03f30..ce433e1074 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,13 +21,6 @@ jobs: python-version: 3.7 - name: Install deps run: pip install "conan>=1.31.2" - - name: Install openblas - run: | - set -e - sudo apt-get update - sudo apt-get install -y libopenblas-dev - shell: bash - if: runner.os == 'Linux' - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.0.2 if: runner.os == 'Windows' @@ -80,11 +73,11 @@ jobs: python-version: 3.7 - name: Install deps run: pip install "conan>=1.31.2" - - name: Install openblas and mpi + - name: Install mpi run: | set -e sudo apt-get update - sudo apt-get install -y libopenblas-dev openmpi-bin libopenmpi-dev + sudo apt-get install -y openmpi-bin libopenmpi-dev shell: bash - name: Compile Standalone run: | diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d3be004436..509a32f6c3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -58,7 +58,7 @@ jobs: run: | python -m cibuildwheel --output-dir wheelhouse env: - CIBW_BEFORE_ALL_LINUX: "yum install -y https://dl.fedoraproject.org/pub/epel/7/aarch64/Packages/e/epel-release-7-12.noarch.rpm && yum install -y openblas-devel" + CIBW_BEFORE_ALL_LINUX: "yum install -y https://dl.fedoraproject.org/pub/epel/7/aarch64/Packages/e/epel-release-7-12.noarch.rpm" CIBW_ARCHS_LINUX: aarch64 - uses: actions/upload-artifact@v2 with: @@ -134,7 +134,7 @@ jobs: python -m pip install cibuildwheel==2.2.2 - name: Build wheels env: - CIBW_BEFORE_ALL: "yum install -y yum-utils wget && wget -q https://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-rhel6-10-1-local-10.1.243-418.87.00-1.0-1.x86_64.rpm && rpm -i cuda-repo-rhel6-10-1-local-10.1.243-418.87.00-1.0-1.x86_64.rpm && yum clean all && yum -y install cuda-10-1 openblas-devel" + CIBW_BEFORE_ALL: "yum install -y yum-utils wget && wget -q https://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-rhel6-10-1-local-10.1.243-418.87.00-1.0-1.x86_64.rpm && rpm -i cuda-repo-rhel6-10-1-local-10.1.243-418.87.00-1.0-1.x86_64.rpm && yum clean all && yum -y install cuda-10-1" CIBW_SKIP: "*-manylinux_i686 cp310* pp* cp36* *musllinux*" CIBW_ENVIRONMENT: QISKIT_AER_PACKAGE_NAME=qiskit-aer-gpu AER_THRUST_BACKEND=CUDA CUDACXX=/usr/local/cuda/bin/nvcc run: | @@ -166,7 +166,7 @@ jobs: python -m pip install cibuildwheel==2.2.2 - name: Build wheels env: - CIBW_BEFORE_ALL: "yum install -y yum-utils wget && wget -q https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-rhel7-10-1-local-10.1.105-418.39-1.0-1.x86_64.rpm && rpm -i cuda-repo-rhel7-10-1-local-10.1.105-418.39-1.0-1.x86_64.rpm && yum clean all && yum -y install cuda-10-1 openblas-devel" + CIBW_BEFORE_ALL: "yum install -y yum-utils wget && wget -q https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-rhel7-10-1-local-10.1.105-418.39-1.0-1.x86_64.rpm && rpm -i cuda-repo-rhel7-10-1-local-10.1.105-418.39-1.0-1.x86_64.rpm && yum clean all && yum -y install cuda-10-1" CIBW_BUILD: "cp310-manylinux_x86_64" CIBW_ENVIRONMENT: QISKIT_AER_PACKAGE_NAME=qiskit-aer-gpu AER_THRUST_BACKEND=CUDA CUDACXX=/usr/local/cuda/bin/nvcc run: | diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e0fd9e38f2..f8efcd0032 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -65,12 +65,6 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}- - name: Install Deps run: python -m pip install -U setuptools wheel virtualenv - - name: Install openblas - run: | - set -e - sudo apt-get update - sudo apt-get install -y libopenblas-dev - shell: bash - name: Build Sdist run: python setup.py sdist - name: Install from sdist and test @@ -109,12 +103,6 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}- - name: Install Deps run: python -m pip install -U -c constraints.txt -r requirements-dev.txt wheel - - name: Install openblas - run: | - set -e - sudo apt-get update - sudo apt-get install -y libopenblas-dev - shell: bash - name: Install Aer run: python -m pip install -U . - name: Run Tests @@ -151,12 +139,6 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}- - name: Install Deps run: python -m pip install -U -c constraints.txt -r requirements-dev.txt wheel - - name: Install openblas - run: | - set -e - sudo apt-get update - sudo apt-get install -y libopenblas-dev - shell: bash - name: Install Aer run: | set -e diff --git a/CMakeLists.txt b/CMakeLists.txt index c3c670e6df..aafd02d8b7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,6 @@ endif() include(CTest) include(compiler_utils) include(Linter) -include(findBLASInSpecificPath) include(dependency_utils) # Get version information @@ -191,40 +190,6 @@ if(STATIC_LINKING) set(BLA_STATIC TRUE) endif() -if(AER_BLAS_LIB_PATH) - find_BLAS_in_specific_path(${AER_BLAS_LIB_PATH}) -else() - if(APPLE) - message(STATUS "Looking for Apple BLAS & Lapack 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...") - set(WIN_ARCH "win64" ) - if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4") # Checking if win32 build - set(WIN_ARCH "win32") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} -E tar "xvfj" "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${WIN_ARCH}/lib/openblas.7z" WORKING_DIRECTORY "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${WIN_ARCH}/lib/") - set(BACKEND_REDIST_DEPS ${BACKEND_REDIST_DEPS} "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${WIN_ARCH}/lib/libopenblas.dll") - set(BLAS_LIBRARIES "${AER_SIMULATOR_CPP_SRC_DIR}/third-party/${WIN_ARCH}/lib/libopenblas.dll.a") # Seems CMake is unable to find it on its own - set(BLAS_FOUND True) - else() - find_package(BLAS QUIET) - endif() - if(NOT BLAS_FOUND) - message(STATUS "OpenBLAS not found. Looking for any other BLAS & Lapack libraries...") - unset(BLA_VENDOR) - find_package(BLAS REQUIRED) - find_package(LAPACK REQUIRED) - set(BLAS_LIBRARIES "${BLAS_LIBRARIES};${LAPACK_LIBRARIES}") - endif() -endif() - -message(STATUS "BLAS library found: ${BLAS_LIBRARIES}") - if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64") if(APPLE OR UNIX) if (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") @@ -316,9 +281,10 @@ endif() # Set dependent libraries set(AER_LIBRARIES ${AER_LIBRARIES} - ${BLAS_LIBRARIES} AER_DEPENDENCY_PKG::nlohmann_json AER_DEPENDENCY_PKG::spdlog + AER_DEPENDENCY_PKG::openblas + ${CONAN_PKG_LIBS_OPENBLAS} Threads::Threads ${CMAKE_DL_LIBS} ${THRUST_DEPENDANT_LIBS} @@ -337,7 +303,7 @@ else() # Standalone build # machine running the code has SIMD support set(SIMD_SOURCE_FILE "${PROJECT_SOURCE_DIR}/src/simulators/statevector/qv_avx2.cpp") endif() - endif() + endif() set(AER_SIMULATOR_SOURCES "${PROJECT_SOURCE_DIR}/contrib/standalone/qasm_simulator.cpp") set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) diff --git a/cmake/FindBLAS.cmake.fix-static-linking b/cmake/FindBLAS.cmake.fix-static-linking deleted file mode 100644 index 61485c28b8..0000000000 --- a/cmake/FindBLAS.cmake.fix-static-linking +++ /dev/null @@ -1,706 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# FindBLAS -# -------- -# -# Find BLAS library -# -# This module finds an installed fortran library that implements the -# BLAS linear-algebra interface (see http://www.netlib.org/blas/). The -# list of libraries searched for is taken from the autoconf macro file, -# acx_blas.m4 (distributed at -# http://ac-archive.sourceforge.net/ac-archive/acx_blas.html). -# -# This module sets the following variables: -# -# :: -# -# BLAS_FOUND - set to true if a library implementing the BLAS interface -# is found -# BLAS_LINKER_FLAGS - uncached list of required linker flags (excluding -l -# and -L). -# BLAS_LIBRARIES - uncached list of libraries (using full path name) to -# link against to use BLAS -# BLAS95_LIBRARIES - uncached list of libraries (using full path name) -# to link against to use BLAS95 interface -# BLAS95_FOUND - set to true if a library implementing the BLAS f95 interface -# is found -# -# The following variables can be used to control this module: -# -# :: -# -# BLA_STATIC if set on this determines what kind of linkage we do (static) -# BLA_VENDOR if set checks only the specified vendor, if not set checks -# all the possibilities -# BLA_F95 if set on tries to find the f95 interfaces for BLAS/LAPACK -# BLA_PREFER_PKGCONFIG if set pkg-config will be used to search for a BLAS -# library first and if one is found that is preferred -# -# List of vendors (BLA_VENDOR) valid in this module: -# -# * Goto -# * OpenBLAS -# * FLAME -# * ATLAS PhiPACK -# * CXML -# * DXML -# * SunPerf -# * SCSL -# * SGIMATH -# * IBMESSL -# * Intel10_32 (intel mkl v10 32 bit) -# * Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model) -# * Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model) -# * Intel (older versions of mkl 32 and 64 bit) -# * ACML -# * ACML_MP -# * ACML_GPU -# * Apple -# * NAS -# * Generic -# -# .. note:: -# -# C/CXX should be enabled to use Intel mkl -# - -include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -cmake_push_check_state() -set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY}) - -set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - -# Check the language being used -if( NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED) ) - if(BLAS_FIND_REQUIRED) - message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.") - else() - message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)") - return() - endif() -endif() - -if(BLA_PREFER_PKGCONFIG) - find_package(PkgConfig) - pkg_check_modules(PKGC_BLAS blas) - if(PKGC_BLAS_FOUND) - set(BLAS_LIBRARIES "${PKGC_BLAS_LINK_LIBRARIES}") - return() - endif() -endif() - -macro(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list _thread) -# This macro checks for the existence of the combination of fortran libraries -# given by _list. If the combination is found, this macro checks (using the -# Check_Fortran_Function_Exists macro) whether can link against that library -# combination using the name of a routine given by _name using the linker -# flags given by _flags. If the combination of libraries is found and passes -# the link test, LIBRARIES is set to the list of complete library paths that -# have been found. Otherwise, LIBRARIES is set to FALSE. - -# N.B. _prefix is the prefix applied to the names of all cached variables that -# are generated internally and marked advanced by this macro. - -set(_libdir ${ARGN}) - -set(_libraries_work TRUE) -set(${LIBRARIES}) -set(_combined_name) -if (NOT _libdir) - if (WIN32) - set(_libdir ENV LIB) - elseif (APPLE) - set(_libdir ENV DYLD_LIBRARY_PATH) - else () - set(_libdir ENV LD_LIBRARY_PATH) - endif () -endif () - -foreach(_library ${_list}) - set(_combined_name ${_combined_name}_${_library}) - - if(_libraries_work) - if (BLA_STATIC) - if (WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif () - if (APPLE) - set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) - else () - set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - endif () - else () - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - # for ubuntu's libblas3gf and liblapack3gf packages - set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf) - endif () - endif () - find_library(${_prefix}_${_library}_LIBRARY - NAMES ${_library} - PATHS ${_libdir} - ) - mark_as_advanced(${_prefix}_${_library}_LIBRARY) - set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY}) - set(_libraries_work ${${_prefix}_${_library}_LIBRARY}) - endif() -endforeach() -if(_libraries_work) - # Test this combination of libraries. - set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_thread}) -# message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}") - if (CMAKE_Fortran_COMPILER_LOADED) - check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS) - else() - check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS) - endif() - set(CMAKE_REQUIRED_LIBRARIES) - mark_as_advanced(${_prefix}${_combined_name}_WORKS) - set(_libraries_work ${${_prefix}${_combined_name}_WORKS}) -endif() -if(NOT _libraries_work) - set(${LIBRARIES} FALSE) -endif() -#message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}") -endmacro() - -set(BLAS_LINKER_FLAGS) -set(BLAS_LIBRARIES) -set(BLAS95_LIBRARIES) -if (NOT $ENV{BLA_VENDOR} STREQUAL "") - set(BLA_VENDOR $ENV{BLA_VENDOR}) -else () - if(NOT BLA_VENDOR) - set(BLA_VENDOR "All") - endif() -endif () - -if (BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - # gotoblas (http://www.tacc.utexas.edu/tacc-projects/gotoblas2) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "goto2" - "" - ) - endif() -endif () - -if (BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - # OpenBLAS (http://www.openblas.net) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "openblas" - "pthread" - ) - endif() -endif () - -if (BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - # FLAME's blis library (https://github.com/flame/blis) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "blis" - "" - ) - endif() -endif () - -if (BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - dgemm - "" - "f77blas;atlas" - "" - ) - endif() -endif () - -# BLAS in PhiPACK libraries? (requires generic BLAS lib, too) -if (BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "sgemm;dgemm;blas" - "" - ) - endif() -endif () - -# BLAS in Alpha CXML library? -if (BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "cxml" - "" - ) - endif() -endif () - -# BLAS in Alpha DXML library? (now called CXML, see above) -if (BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "dxml" - "" - ) - endif() -endif () - -# BLAS in Sun Performance library? -if (BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "-xlic_lib=sunperf" - "sunperf;sunmath" - "" - ) - if(BLAS_LIBRARIES) - set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf") - endif() - endif() -endif () - -# BLAS in SCSL library? (SGI/Cray Scientific Library) -if (BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "scsl" - "" - ) - endif() -endif () - -# BLAS in SGIMATH library? -if (BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "complib.sgimath" - "" - ) - endif() -endif () - -# BLAS in IBM ESSL library? (requires generic BLAS lib, too) -if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "essl;blas" - "" - ) - endif() -endif () - -#BLAS in acml library? -if (BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All") - if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR - ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR - ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS)) - ) - # try to find acml in "standard" paths - if( WIN32 ) - file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" ) - else() - file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" ) - endif() - if( WIN32 ) - file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" ) - else() - file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" ) - endif() - list(GET _ACML_ROOT 0 _ACML_ROOT) - list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT) - if( _ACML_ROOT ) - get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH ) - if( SIZEOF_INTEGER EQUAL 8 ) - set( _ACML_PATH_SUFFIX "_int64" ) - else() - set( _ACML_PATH_SUFFIX "" ) - endif() - if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" ) - set( _ACML_COMPILER32 "ifort32" ) - set( _ACML_COMPILER64 "ifort64" ) - elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" ) - set( _ACML_COMPILER32 "sun32" ) - set( _ACML_COMPILER64 "sun64" ) - elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" ) - set( _ACML_COMPILER32 "pgi32" ) - if( WIN32 ) - set( _ACML_COMPILER64 "win64" ) - else() - set( _ACML_COMPILER64 "pgi64" ) - endif() - elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" ) - # 32 bit builds not supported on Open64 but for code simplicity - # We'll just use the same directory twice - set( _ACML_COMPILER32 "open64_64" ) - set( _ACML_COMPILER64 "open64_64" ) - elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" ) - set( _ACML_COMPILER32 "nag32" ) - set( _ACML_COMPILER64 "nag64" ) - else() - set( _ACML_COMPILER32 "gfortran32" ) - set( _ACML_COMPILER64 "gfortran64" ) - endif() - - if( BLA_VENDOR STREQUAL "ACML_MP" ) - set(_ACML_MP_LIB_DIRS - "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib" - "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" ) - else() - set(_ACML_LIB_DIRS - "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib" - "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" ) - endif() - endif() - elseif(BLAS_${BLA_VENDOR}_LIB_DIRS) - set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS}) - endif() - - if( BLA_VENDOR STREQUAL "ACML_MP" ) - foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS}) - check_fortran_libraries ( - BLAS_LIBRARIES - BLAS - sgemm - "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS} - ) - if( BLAS_LIBRARIES ) - break() - endif() - endforeach() - elseif( BLA_VENDOR STREQUAL "ACML_GPU" ) - foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS}) - check_fortran_libraries ( - BLAS_LIBRARIES - BLAS - sgemm - "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS} - ) - if( BLAS_LIBRARIES ) - break() - endif() - endforeach() - else() - foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} ) - check_fortran_libraries ( - BLAS_LIBRARIES - BLAS - sgemm - "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS} - ) - if( BLAS_LIBRARIES ) - break() - endif() - endforeach() - endif() - - # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "acml;acml_mv" - "" - ) - endif() - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "acml_mp;acml_mv" - "" - ) - endif() - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "acml;acml_mv;CALBLAS" - "" - ) - endif() -endif () # ACML - -# Apple BLAS library? -if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All") -if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - dgemm - "" - "Accelerate" - "" - ) - endif() -endif () - -if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All") - if ( NOT BLAS_LIBRARIES ) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - dgemm - "" - "vecLib" - "" - ) - endif () -endif () -# Generic BLAS library? -if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All") - if(NOT BLAS_LIBRARIES) - check_fortran_libraries( - BLAS_LIBRARIES - BLAS - sgemm - "" - "blas" - "" - ) - endif() -endif () - -#BLAS in intel mkl 10 library? (em64t 64bit) -if (BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All") - if (NOT WIN32) - set(LM "-lm") - endif () - if (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED) - if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED) - find_package(Threads) - else() - find_package(Threads REQUIRED) - endif() - - set(BLAS_SEARCH_LIBS "") - - if(BLA_F95) - set(BLAS_mkl_SEARCH_SYMBOL SGEMM) - set(_LIBRARIES BLAS95_LIBRARIES) - if (WIN32) - if (BLA_STATIC) - set(BLAS_mkl_DLL_SUFFIX "") - else() - set(BLAS_mkl_DLL_SUFFIX "_dll") - endif() - - # Find the main file (32-bit or 64-bit) - set(BLAS_SEARCH_LIBS_WIN_MAIN "") - if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN - "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}") - endif() - if (BLA_VENDOR MATCHES "^Intel10_64lp" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN - "mkl_blas95_lp64${BLAS_mkl_DLL_SUFFIX} mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}") - endif () - - # Add threading/sequential libs - set(BLAS_SEARCH_LIBS_WIN_THREAD "") - if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD - "mkl_sequential${BLAS_mkl_DLL_SUFFIX}") - endif() - if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All") - # old version - list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD - "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}") - # mkl >= 10.3 - list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD - "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}") - endif() - - # Cartesian product of the above - foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN}) - foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD}) - list(APPEND BLAS_SEARCH_LIBS - "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}") - endforeach() - endforeach() - else () - if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS - "mkl_blas95 mkl_intel mkl_intel_thread mkl_core guide") - endif () - if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All") - # old version - list(APPEND BLAS_SEARCH_LIBS - "mkl_blas95 mkl_intel_lp64 mkl_intel_thread mkl_core guide") - - # mkl >= 10.3 - if (CMAKE_C_COMPILER MATCHES ".+gcc") - list(APPEND BLAS_SEARCH_LIBS - "mkl_blas95_lp64 mkl_intel_lp64 mkl_gnu_thread mkl_core gomp") - else () - list(APPEND BLAS_SEARCH_LIBS - "mkl_blas95_lp64 mkl_intel_lp64 mkl_intel_thread mkl_core iomp5") - endif () - endif () - if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS - "mkl_intel_lp64 mkl_sequential mkl_core") - endif () - endif () - else () - set(BLAS_mkl_SEARCH_SYMBOL sgemm) - set(_LIBRARIES BLAS_LIBRARIES) - if (WIN32) - if (BLA_STATIC) - set(BLAS_mkl_DLL_SUFFIX "") - else() - set(BLAS_mkl_DLL_SUFFIX "_dll") - endif() - - # Find the main file (32-bit or 64-bit) - set(BLAS_SEARCH_LIBS_WIN_MAIN "") - if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN - "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}") - endif() - if (BLA_VENDOR MATCHES "^Intel10_64lp" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN - "mkl_intel_lp64${BLAS_mkl_DLL_SUFFIX}") - endif () - - # Add threading/sequential libs - set(BLAS_SEARCH_LIBS_WIN_THREAD "") - if (NOT BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All") - # old version - list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD - "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}") - # mkl >= 10.3 - list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD - "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}") - endif() - if (BLA_VENDOR MATCHES "_seq$" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD - "mkl_sequential${BLAS_mkl_DLL_SUFFIX}") - endif() - - # Cartesian product of the above - foreach (MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN}) - foreach (THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD}) - list(APPEND BLAS_SEARCH_LIBS - "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}") - endforeach() - endforeach() - else () - if (BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS - "mkl_intel mkl_intel_thread mkl_core guide") - endif () - if (BLA_VENDOR STREQUAL "Intel10_64lp" OR BLA_VENDOR STREQUAL "All") - - # old version - list(APPEND BLAS_SEARCH_LIBS - "mkl_intel_lp64 mkl_intel_thread mkl_core guide") - - # mkl >= 10.3 - if (CMAKE_C_COMPILER MATCHES ".+gcc") - list(APPEND BLAS_SEARCH_LIBS - "mkl_intel_lp64 mkl_gnu_thread mkl_core gomp") - else () - list(APPEND BLAS_SEARCH_LIBS - "mkl_intel_lp64 mkl_intel_thread mkl_core iomp5") - endif () - endif () - if (BLA_VENDOR STREQUAL "Intel10_64lp_seq" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS - "mkl_intel_lp64 mkl_sequential mkl_core") - endif () - - #older vesions of intel mkl libs - if (BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All") - list(APPEND BLAS_SEARCH_LIBS - "mkl") - list(APPEND BLAS_SEARCH_LIBS - "mkl_ia32") - list(APPEND BLAS_SEARCH_LIBS - "mkl_em64t") - endif () - endif () - endif () - - foreach (IT ${BLAS_SEARCH_LIBS}) - string(REPLACE " " ";" SEARCH_LIBS ${IT}) - if (NOT ${_LIBRARIES}) - check_fortran_libraries( - ${_LIBRARIES} - BLAS - ${BLAS_mkl_SEARCH_SYMBOL} - "" - "${SEARCH_LIBS}" - "${CMAKE_THREAD_LIBS_INIT};${LM}" - ) - endif () - endforeach () - - endif () -endif () - -if(BLA_F95) - find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS95_LIBRARIES) - set(BLAS95_FOUND ${BLAS_FOUND}) - if(BLAS_FOUND) - set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}") - endif() -else() - find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS_LIBRARIES) -endif() - -cmake_pop_check_state() -set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) diff --git a/cmake/conan_utils.cmake b/cmake/conan_utils.cmake index 66bd6f02bc..1bd7e5e509 100644 --- a/cmake/conan_utils.cmake +++ b/cmake/conan_utils.cmake @@ -10,8 +10,8 @@ macro(setup_conan) # Right now every dependency shall be static set(CONAN_OPTIONS ${CONAN_OPTIONS} "*:shared=False") - set(REQUIREMENTS nlohmann_json/3.1.1 spdlog/1.5.0) - list(APPEND AER_CONAN_LIBS nlohmann_json spdlog) + set(REQUIREMENTS nlohmann_json/3.1.1 spdlog/1.5.0 openblas/0.3.17) + list(APPEND AER_CONAN_LIBS nlohmann_json spdlog openblas) if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(REQUIREMENTS ${REQUIREMENTS} llvm-openmp/12.0.1) list(APPEND AER_CONAN_LIBS llvm-openmp) diff --git a/cmake/findBLASInSpecificPath.cmake b/cmake/findBLASInSpecificPath.cmake deleted file mode 100644 index 7577e0c09b..0000000000 --- a/cmake/findBLASInSpecificPath.cmake +++ /dev/null @@ -1,54 +0,0 @@ -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() diff --git a/pyproject.toml b/pyproject.toml index 0d5dc8e831..96743bea32 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,12 +24,5 @@ test-command = "python {project}/tools/verify_wheels.py" # restricting any dependencies that Numpy and Scipy might have. before-test = "pip install --only-binary=numpy,scipy numpy scipy" -[tool.cibuildwheel.linux] -before-all = "yum install -y openblas-devel" - [tool.cibuildwheel.windows] environment = { CMAKE_GENERATOR = "Visual Studio 16 2019"} - -[[tool.cibuildwheel.overrides]] -select = "cp3{7,8,9,10}-manylinux_i686" -before-all = "yum install -y openblas-devel wget && bash {project}/tools/install_rust.sh" diff --git a/src/framework/linalg/eigensystem.hpp b/src/framework/linalg/eigensystem.hpp index da0cc10d58..b78424decd 100644 --- a/src/framework/linalg/eigensystem.hpp +++ b/src/framework/linalg/eigensystem.hpp @@ -19,7 +19,6 @@ #include "framework/blas_protos.hpp" #include "framework/matrix.hpp" - /** * Returns the eigenvalues and eigenvectors * of a Hermitian matrix. diff --git a/src/framework/matrix.hpp b/src/framework/matrix.hpp index 54a8365950..50d6784c81 100755 --- a/src/framework/matrix.hpp +++ b/src/framework/matrix.hpp @@ -36,7 +36,6 @@ Multiplication is done with the C wrapper of the fortran blas library. #include #include -#include "framework/blas_protos.hpp" #include "framework/linalg/enable_if_numeric.hpp" /******************************************************************************* @@ -75,51 +74,16 @@ class matrix { friend matrix operator*(const S2 &beta, const matrix &A); // multiplication by a scalar beta*A + template friend matrix operator*(const matrix &A, const S2 &beta); // multiplication by a scalar A*beta - // Single-Precison Matrix Multiplication - friend matrix - operator*(const matrix &A, - const matrix &B); // real matrix multiplication A*B - friend matrix> operator*( - const matrix> &A, - const matrix> &B); // complex matrix multplication A*B - friend matrix> - operator*(const matrix &A, - const matrix> - &B); // real-complex matrix multplication A*B - friend matrix> - operator*(const matrix> &A, - const matrix &B); // real-complex matrix multplication A*B - // Double-Precision Matrix Multiplication - friend matrix - operator*(const matrix &A, - const matrix &B); // real matrix multiplication A*B - friend matrix> - operator*(const matrix> &A, - const matrix> - &B); // complex matrix multplication A*B - friend matrix> - operator*(const matrix &A, - const matrix> - &B); // real-complex matrix multplication A*B - friend matrix> - operator*(const matrix> &A, - const matrix &B); // real-complex matrix multplication A*B - // Single-Precision Matrix-Vector Multiplication - friend std::vector operator*(const matrix &A, - const std::vector &v); - friend std::vector> - operator*(const matrix> &A, - const std::vector> &v); - // Double-Precision Matrix-Vector Multiplication - friend std::vector operator*(const matrix &A, - const std::vector &v); - friend std::vector> - operator*(const matrix> &A, - const std::vector> &v); + + template + friend matrix + operator*(const matrix &A, + const matrix &B); // real matrix multiplication A*B public: //----------------------------------------------------------------------- @@ -670,164 +634,21 @@ matrix operator*(const S2 &beta, const matrix &A) { return temp; } -// Operator overloading with BLAS functions -inline matrix operator*(const matrix &A, - const matrix &B) { - // overloads A*B for real matricies and uses the blas dgemm routine - // cblas_dgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix C(A.rows_, B.cols_); - double alpha = 1.0, beta = 0.0; - dgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &A.rows_, &B.cols_, &A.cols_, &alpha, A.data_, - &A.LD_, B.data_, &B.LD_, &beta, C.data_, &C.LD_); - // cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, A.rows_, B.cols_, - // A.cols_, 1.0, A.data_, A.LD_, B.data_, B.LD_, 0.0, C.data_, C.LD_); - return C; -} -inline matrix operator*(const matrix &A, const matrix &B) { - // overloads A*B for real matricies and uses the blas sgemm routine - // cblas_sgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix C(A.rows_, B.cols_); - float alpha = 1.0, beta = 0.0; - sgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &A.rows_, &B.cols_, &A.cols_, &alpha, A.data_, - &A.LD_, B.data_, &B.LD_, &beta, C.data_, &C.LD_); - // cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, A.rows_, B.cols_, - // A.cols_, 1.0, A.data_, A.LD_, B.data_, B.LD_, 0.0, C.data_, C.LD_); - return C; -} -inline matrix> -operator*(const matrix> &A, - const matrix> &B) { - // overloads A*B for complex matricies and uses the blas zgemm routine - // cblas_zgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix> C(A.rows_, B.cols_); - std::complex alpha = 1.0, beta = 0.0; - cgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &A.rows_, &B.cols_, &A.cols_, &alpha, A.data_, - &A.LD_, B.data_, &B.LD_, &beta, C.data_, &C.LD_); - // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, A.rows_, B.cols_, - // A.cols_, &alpha, A.data_, A.LD_, B.data_, B.LD_, &beta, C.data_, C.LD_); - return C; -} -inline matrix> -operator*(const matrix> &A, - const matrix> &B) { - // overloads A*B for complex matricies and uses the blas zgemm routine - // cblas_zgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix> C(A.rows_, B.cols_); - std::complex alpha = 1.0, beta = 0.0; - zgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &A.rows_, &B.cols_, &A.cols_, &alpha, A.data_, - &A.LD_, B.data_, &B.LD_, &beta, C.data_, &C.LD_); - // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, A.rows_, B.cols_, - // A.cols_, &alpha, A.data_, A.LD_, B.data_, B.LD_, &beta, C.data_, C.LD_); - return C; -} -inline matrix> -operator*(const matrix &A, const matrix> &B) { - // overloads A*B for complex matricies and uses the blas zgemm routine - // cblas_zgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix> C(A.rows_, B.cols_), Ac(A.rows_, A.cols_); - Ac = A; - std::complex alpha = 1.0, beta = 0.0; - cgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &Ac.rows_, &B.cols_, &Ac.cols_, &alpha, Ac.data_, - &Ac.LD_, B.data_, &B.LD_, &beta, C.data_, &C.LD_); - // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, Ac.rows_, B.cols_, - // Ac.cols_, &alpha, Ac.data_, Ac.LD_, B.data_, B.LD_, &beta, C.data_, C.LD_); - return C; -} -inline matrix> -operator*(const matrix &A, const matrix> &B) { - // overloads A*B for complex matricies and uses the blas zgemm routine - // cblas_zgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix> C(A.rows_, B.cols_), Ac(A.rows_, A.cols_); - Ac = A; - std::complex alpha = 1.0, beta = 0.0; - zgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &Ac.rows_, &B.cols_, &Ac.cols_, &alpha, Ac.data_, - &Ac.LD_, B.data_, &B.LD_, &beta, C.data_, &C.LD_); - // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, Ac.rows_, B.cols_, - // Ac.cols_, &alpha, Ac.data_, Ac.LD_, B.data_, B.LD_, &beta, C.data_, C.LD_); - return C; -} -inline matrix> -operator*(const matrix> &A, const matrix &B) { - // overloads A*B for complex matricies and uses the blas zgemm routine - // cblas_zgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix> C(A.rows_, B.cols_), Bc(B.rows_, B.cols_); - Bc = B; - std::complex alpha = 1.0, beta = 0.0; - cgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &A.rows_, &Bc.cols_, &A.cols_, &alpha, A.data_, - &A.LD_, Bc.data_, &Bc.LD_, &beta, C.data_, &C.LD_); - // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, A.rows_, Bc.cols_, - // A.cols_, &alpha, A.data_, A.LD_, Bc.data_, Bc.LD_, &beta, C.data_, C.LD_); - return C; -} -inline matrix> -operator*(const matrix> &A, const matrix &B) { - // overloads A*B for complex matricies and uses the blas zgemm routine - // cblas_zgemm(CblasXMajor,op,op,N,M,K,alpha,A,LDA,B,LDB,beta,C,LDC) - // C-> alpha*op(A)*op(B) +beta C - matrix> C(A.rows_, B.cols_), Bc(B.rows_, B.cols_); - Bc = B; - std::complex alpha = 1.0, beta = 0.0; - zgemm_(&AerBlas::Trans[0], &AerBlas::Trans[0], &A.rows_, &Bc.cols_, &A.cols_, &alpha, A.data_, - &A.LD_, Bc.data_, &Bc.LD_, &beta, C.data_, &C.LD_); - // cblas_zgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, A.rows_, Bc.cols_, - // A.cols_, &alpha, A.data_, A.LD_, Bc.data_, Bc.LD_, &beta, C.data_, C.LD_); - return C; -} - -// Single-Precision Real -inline std::vector operator*(const matrix &A, - const std::vector &x) { - // overload A*v for complex matrixies and will used a blas function - std::vector y(A.rows_); - float alpha = 1.0, beta = 0.0; - const size_t incx = 1, incy = 1; - sgemv_(&AerBlas::Trans[0], &A.rows_, &A.cols_, &alpha, A.data_, &A.LD_, x.data(), &incx, - &beta, y.data(), &incy); - return y; -} -// Double-Precision Real -inline std::vector operator*(const matrix &A, - const std::vector &x) { - // overload A*v for complex matrixies and will used a blas function - std::vector y(A.rows_); - double alpha = 1.0, beta = 0.0; - const size_t incx = 1, incy = 1; - dgemv_(&AerBlas::Trans[0], &A.rows_, &A.cols_, &alpha, A.data_, &A.LD_, x.data(), &incx, - &beta, y.data(), &incy); - return y; -} -// Single-Precision Complex -inline std::vector> -operator*(const matrix> &A, - const std::vector> &x) { - // overload A*v for complex matrixies and will used a blas function - std::vector> y(A.rows_); - std::complex alpha = 1.0, beta = 0.0; - const size_t incx = 1, incy = 1; - cgemv_(&AerBlas::Trans[0], &A.rows_, &A.cols_, &alpha, A.data_, &A.LD_, x.data(), &incx, - &beta, y.data(), &incy); - return y; -} -// Double-Precision Complex -inline std::vector> -operator*(const matrix> &A, - const std::vector> &x) { - // overload A*v for complex matrixies and will used a blas function - std::vector> y(A.rows_); - std::complex alpha = 1.0, beta = 0.0; - const size_t incx = 1, incy = 1; - zgemv_(&AerBlas::Trans[0], &A.rows_, &A.cols_, &alpha, A.data_, &A.LD_, x.data(), &incx, - &beta, y.data(), &incy); - return y; +template +inline matrix operator*(const matrix &A, + const matrix &B) { + size_t rows1 = A.rows_, cols1 = A.cols_; + size_t cols2 = B.cols_; + matrix temp(rows1, cols2); + for (size_t i = 0; i < rows1; i++) { + for (size_t j = 0; j < cols2; j++) { + for (size_t k = 0; k < cols1; k++) { + temp(i, j) += A(i, k) * B(k, j); + } + } + } + return temp; } - //------------------------------------------------------------------------------ // end _matrix_h_ //------------------------------------------------------------------------------