diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7686d24cf0..f5c4ee91bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,10 @@ jobs: run: python -m pip install -U cibuildwheel==2.22.0 - name: Build Wheels env: + MACOSX_DEPLOYMENT_TARGET: "10.13" + CIBW_ARCHS_WINDOWS: AMD64 AER_CMAKE_OPENMP_BUILD: 1 + CONAN_SETTINGS_ARCH: x86_64 run: cibuildwheel --output-dir wheelhouse - uses: actions/upload-artifact@v4 with: @@ -48,11 +51,8 @@ jobs: run: python -m pip install -U cibuildwheel==2.22.0 - name: Build Wheels env: + PYTHONUNBUFFERED: "1" CIBW_ARCHS_MACOS: arm64 - CIBW_BEFORE_BUILD: | # conan<2.0.0 on arm64 (turns to be 1.66.0) complains about not supporting Clang 17 - python -m pip install "conan<2.0.0" - conan config init --force - sed -i '' 's/"16.0"/"16.0", "17.0"/' ~/.conan/settings.yml run: cibuildwheel --output-dir wheelhouse - uses: actions/upload-artifact@v4 with: @@ -114,7 +114,7 @@ jobs: - name: Build wheels env: CIBW_BEFORE_ALL: "sed -i -e 's/^mirrorlist/#mirrorlist/' -e 's/^#baseurl/baseurl/' -e 's/mirror.centos.org/vault.centos.org/' /etc/yum.repos.d/*.repo && yum install -y yum-utils wget && wget -q https://developer.download.nvidia.com/compute/cuda/12.5.1/local_installers/cuda-repo-rhel8-12-5-local-12.5.1_555.42.06-1.x86_64.rpm && rpm -i cuda-repo-rhel8-12-5-local-12.5.1_555.42.06-1.x86_64.rpm && yum clean all && yum -y install cuda-toolkit-12-5 && yum -y install openblas-devel && yum clean all" - CIBW_BEFORE_BUILD : "pip cache purge && pip install nvidia-cuda-runtime-cu12 nvidia-nvjitlink-cu12 nvidia-cublas-cu12 nvidia-cusolver-cu12 nvidia-cusparse-cu12 'cuquantum-cu12<24.11.0'" + CIBW_BEFORE_BUILD : "pip cache purge && pip install nvidia-cuda-runtime-cu12 nvidia-nvjitlink-cu12 nvidia-cublas-cu12 nvidia-cusolver-cu12 nvidia-cusparse-cu12 'cuquantum-cu12>=24.8.0' 'custatevec-cu12>=1.9.0' 'cutensor-cu12>=2.3.1' 'cutensornet-cu12>=2.5.0' " CIBW_SKIP: "*-manylinux_i686 pp* cp36* cp37* cp38* cp39* cp310* cp311* *musllinux*" CIBW_ENVIRONMENT: QISKIT_AER_PACKAGE_NAME=qiskit-aer-gpu QISKIT_AER_CUDA_MAJOR=12 CMAKE_VERBOSE_MAKEFILE=true AER_THRUST_BACKEND=CUDA CUDACXX=/usr/local/cuda/bin/nvcc AER_CUDA_ARCH="7.0 7.2 7.5 8.0 8.6 8.7 8.9 9.0" AER_PYTHON_CUDA_ROOT=/opt/_internal AER_CIBUILD=true CIBW_REPAIR_WHEEL_COMMAND: 'auditwheel repair --exclude libcudart.so.12 --exclude libcustatevec.so.1 --exclude libcutensornet.so.2 --exclude libcutensor.so.1 --exclude libcutensorMg.so.1 --exclude libcusolver.so.11 --exclude libcusolverMg.so.11 --exclude libcusolver.so.12 --exclude libcusolverMg.so.12 --exclude libcusparse.so.12 --exclude libcublas.so.12 --exclude libcublasLt.so.12 --exclude libnvJitLink.so.12 -w {dest_dir} {wheel}' diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 802163a0d0..e0cc2c91bb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -84,10 +84,6 @@ jobs: - name: Build Wheels env: CIBW_ARCHS_MACOS: arm64 - CIBW_BEFORE_BUILD: | # conan<2.0.0 on arm64 (turns to be 1.66.0) complains about not supporting Clang 17 - python -m pip install "conan<2.0.0" - conan config init --force - sed -i '' 's/"16.0"/"16.0", "17.0"/' ~/.conan/settings.yml run: cibuildwheel --output-dir wheelhouse - uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1caea13abc..b9cbacfb2f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -101,6 +101,7 @@ jobs: env: AER_THRUST_BACKEND: OMP + AER_CMAKE_OPENMP_BUILD: 1 QISKIT_TEST_CAPTURE_STREAMS: 1 # Needed to suppress a warning in jupyter-core 5.x by eagerly migrating to # a new internal interface that will be the default in jupyter-core 6.x. @@ -268,9 +269,15 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}- - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v2 + - name: Run Conan + run: | + pip install conan==2.* + conan profile detect --force + conan install . --output-folder=build --build=missing -s:h arch=x86_64 -s:b arch=x86_64 -s compiler.cppstd=17 -s build_type=Release - name: Build Aer Windows env: CMAKE_GENERATOR: "Visual Studio 17 2022" + CMAKE_TOOLCHAIN_FILE: build/conan_toolchain.cmake run: | set -e pip install build diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bbda7dccf..b9c57f222f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,12 @@ # For Mac, statically linking only happens with user libraries, system libraries cannot # be linked statically per Apple's indications. -cmake_minimum_required(VERSION 3.8 FATAL_ERROR) +cmake_minimum_required(VERSION 3.25 FATAL_ERROR) file(STRINGS "qiskit_aer/VERSION.txt" VERSION_NUM) +set(PYBIND11_FINDPYTHON ON) +find_package(Python COMPONENTS Interpreter REQUIRED) + # For ROCm builds we need to make sure the CXX and HIP compilers match and are clang. # We should do this before the project() call to make sure the compiler options are # properly assessed. @@ -48,6 +51,15 @@ endif() include(CheckLanguage) project(qasm_simulator VERSION ${VERSION_NUM} LANGUAGES CXX C ${EXTRA_LANGUAGES} ) +# load Conan packages +set(PYBIND11_FINDPYTHON ON) +find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) +find_package(OpenMP REQUIRED) +find_package(nlohmann_json REQUIRED) +find_package(spdlog REQUIRED) +find_package(fmt REQUIRED) +find_package(OpenBLAS REQUIRED) +find_package(pybind11 REQUIRED) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) list(APPEND CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/cmake) @@ -61,10 +73,9 @@ if(NOT DEFINED AER_THRUST_BACKEND AND DEFINED ENV{AER_THRUST_BACKEND}) endif() if(AER_THRUST_BACKEND STREQUAL "CUDA") - include(nvcc_add_compiler_options) set(CUDA_FOUND TRUE) - #include(FindCUDA) # for cuda_select_nvcc_arch_flags, CUDA_FOUND - include(FindCUDA/select_compute_arch) + enable_language(CUDA) + find_package(CUDAToolkit REQUIRED) else() # idiosyncrasy of CMake that it still creates a reference to this set(CMAKE_CUDA_COMPILE_WHOLE_COMPILATION "") @@ -90,8 +101,6 @@ endif() include(CTest) include(compiler_utils) include(Linter) -include(findBLASInSpecificPath) -include(dependency_utils) # Get version information get_version(${VERSION_NUM}) @@ -176,7 +185,6 @@ endif() # Looking for external libraries # set(BACKEND_REDIST_DEPS "") # List of redistributable dependencies -setup_dependencies() # If we do not set them with a space CMake fails afterwards if nothing is set for this vars! set(AER_LINKER_FLAGS " ") @@ -225,41 +233,9 @@ 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...") - if(NOT BLA_VENDOR) - set(BLA_VENDOR "OpenBLAS") - endif() - endif() - if(WIN32 AND USE_BUNDLED_BLAS_WIN) - 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}") +find_package(OpenBLAS REQUIRED) +set(BLAS_LIBRARIES OpenBLAS::OpenBLAS) +message(STATUS "Using Conan-provided OpenBLAS: ${BLAS_LIBRARIES}") if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64") if(APPLE OR UNIX) @@ -272,6 +248,7 @@ if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR endif() endif() + set(AER_THRUST_SUPPORTED TRUE) if(AER_THRUST_SUPPORTED) if(AER_THRUST_BACKEND STREQUAL "CUDA") @@ -294,16 +271,29 @@ if(AER_THRUST_SUPPORTED) set(CMAKE_CUDA_ARCHITECTURES "${AER_CUDA_ARCHITECTURES}") message(STATUS "CMAKE_CUDA_ARCHITECTURES = ${CMAKE_CUDA_ARCHITECTURES}") + if(NOT DEFINED AER_PYTHON_CUDA_ROOT) + execute_process( + COMMAND "${Python_EXECUTABLE}" -c "import site; print(site.getsitepackages()[0])" + OUTPUT_VARIABLE AER_PYTHON_CUDA_ROOT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + message(STATUS "Detected AER_PYTHON_CUDA_ROOT = ${AER_PYTHON_CUDA_ROOT}") + endif() if(NOT DEFINED AER_PYTHON_CUDA_ROOT AND DEFINED ENV{AER_PYTHON_CUDA_ROOT}) set(AER_PYTHON_CUDA_ROOT $ENV{AER_PYTHON_CUDA_ROOT}) endif() + if(NOT DEFINED AER_CIBUILD AND DEFINED ENV{AER_CIBUILD}) set(AER_CIBUILD $ENV{AER_CIBUILD}) endif() if(AER_PYTHON_CUDA_ROOT) find_package(Python) if(AER_CIBUILD) - set(PYTHON_SITE_PATH ${AER_PYTHON_CUDA_ROOT}/cpython-${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}.${Python_VERSION_PATCH}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages) + if(EXISTS "${AER_PYTHON_CUDA_ROOT}/cuquantum/include") + set(PYTHON_SITE_PATH "${AER_PYTHON_CUDA_ROOT}") + else() + set(PYTHON_SITE_PATH ${AER_PYTHON_CUDA_ROOT}/cpython-${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}.${Python_VERSION_PATCH}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages) + endif() set(STR_ORIGIN "\$$ORIGIN") else() set(PYTHON_SITE_PATH ${AER_PYTHON_CUDA_ROOT}/lib/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages) @@ -322,6 +312,10 @@ if(AER_THRUST_SUPPORTED) set(CUDA_NVCC_FLAGS "${AER_CUDA_ARCH_FLAGS_EXPAND} -DAER_THRUST_GPU -DAER_THRUST_CUDA -I${AER_SIMULATOR_CPP_SRC_DIR} -isystem ${AER_SIMULATOR_CPP_SRC_DIR}/third-party/headers -use_fast_math --expt-extended-lambda") set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -I${PYTHON_SITE_PATH}/cuquantum/include") set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -I${PYTHON_SITE_PATH}/cutensor/include") + include_directories( + ${PYTHON_SITE_PATH}/cuquantum/include + ${PYTHON_SITE_PATH}/cutensor/include + ) set(THRUST_DEPENDANT_LIBS "${THRUST_DEPENDANT_LIBS} -Wl,--disable-new-dtags") set(THRUST_DEPENDANT_LIBS "${THRUST_DEPENDANT_LIBS} -Wl,-rpath,'${STR_ORIGIN}/../../nvidia/cublas/lib'") set(THRUST_DEPENDANT_LIBS "${THRUST_DEPENDANT_LIBS} -Wl,-rpath,'${STR_ORIGIN}/../../nvidia/cusolver/lib'") @@ -502,8 +496,11 @@ if(AER_THRUST_SUPPORTED) if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") endif() +message(STATUS "CUDA include dirs: ${CUDAToolkit_INCLUDE_DIRS}") endif() + + if(AER_THRUST_SUPPORTED) set(AER_COMPILER_DEFINITIONS ${AER_COMPILER_DEFINITIONS} AER_THRUST_SUPPORTED=TRUE) else() @@ -535,11 +532,18 @@ endif() set(AER_LIBRARIES ${AER_LIBRARIES} ${BLAS_LIBRARIES} - AER_DEPENDENCY_PKG::nlohmann_json - AER_DEPENDENCY_PKG::spdlog + nlohmann_json::nlohmann_json + spdlog::spdlog Threads::Threads ${CMAKE_DL_LIBS}) +# Handle OpenMP differently depending on platform +if (TARGET OpenMP::OpenMP) + list(APPEND AER_LIBRARIES OpenMP::OpenMP) +elseif (MSVC AND OpenMP_CXX_FOUND) + list(APPEND AER_COMPILER_FLAGS "${OpenMP_CXX_FLAGS}") +endif() + set(AER_COMPILER_DEFINITIONS ${AER_COMPILER_DEFINITIONS} ${CONAN_DEFINES}) add_subdirectory(qiskit_aer/backends/wrappers) diff --git a/MANIFEST.in b/MANIFEST.in index 573dc7656e..e44e1eae51 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include MANIFEST.in include README.md include pyproject.toml +include conanfile.py recursive-include qiskit_aer *cpp recursive-include qiskit_aer *hpp graft src 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/FindPybind11.cmake b/cmake/FindPybind11.cmake deleted file mode 100644 index ed26dd1e41..0000000000 --- a/cmake/FindPybind11.cmake +++ /dev/null @@ -1,100 +0,0 @@ -find_package(PythonLibs) - -message(STATUS ${PYTHON_INCLUDE_DIRS}) -message(STATUS "PYTHON EXECUTABLE: ${PYTHON_EXECUTABLE}") - -# Pybind includes are searched for through python -# If they aren't found, we set them to the python include directories -# set by CMake -set(_find_pybind_includes_command " -import sys -import pybind11 -sys.stdout.write(pybind11.get_include()) -") -execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "${_find_pybind_includes_command}" - OUTPUT_VARIABLE _py_output - RESULT_VARIABLE _py_result) -if(_py_result EQUAL "0") - message(STATUS "PYCOMM RAW: ${_py_output}") - set(PYBIND_INCLUDE_DIRS "${_py_output}") -else() - message(WARNING "(NAIVE) CHECK COULD NOT FIND PYBIND!") - set(PYBIND_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS}) -endif() -message(STATUS "PYBIND INCLUDES: ${PYBIND_INCLUDE_DIRS}") - -if (NOT DEFINED PYTHON_EXTENSION_MODULE_SUFFIX) - execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'), end='')" - OUTPUT_VARIABLE PYTHON_EXTENSION_MODULE_SUFFIX) -endif() - -function(basic_pybind11_add_module target_name) - set(options MODULE SHARED EXCLUDE_FROM_ALL NO_EXTRAS SYSTEM THIN_LTO) - cmake_parse_arguments(ARG "${options}" "" "" ${ARGN}) - - if(ARG_MODULE AND ARG_SHARED) - message(FATAL_ERROR "Can't be both MODULE and SHARED") - elseif(ARG_SHARED) - set(lib_type SHARED) - else() - set(lib_type MODULE) - endif() - - if(ARG_EXCLUDE_FROM_ALL) - set(exclude_from_all EXCLUDE_FROM_ALL) - endif() - - add_library(${target_name} ${lib_type} ${exclude_from_all} ${ARG_UNPARSED_ARGUMENTS}) - - # This sets various properties (python include dirs) and links to python libs - target_include_directories(${target_name} PRIVATE ${PYTHON_INCLUDE_DIRS}) - target_include_directories(${target_name} PRIVATE ${PYBIND_INCLUDE_DIRS}) - - if(WIN32 OR CYGWIN) - # Link against the Python shared library on Windows - target_link_libraries(${target_name} ${PYTHON_LIBRARIES}) - elseif(APPLE) - # It's quite common to have multiple copies of the same Python version - # installed on one's system. E.g.: one copy from the OS and another copy - # that's statically linked into an application like Blender or Maya. - # If we link our plugin library against the OS Python here and import it - # into Blender or Maya later on, this will cause segfaults when multiple - # conflicting Python instances are active at the same time (even when they - # are of the same version). - - # Windows is not affected by this issue since it handles DLL imports - # differently. The solution for Linux and Mac OS is simple: we just don't - # link against the Python library. The resulting shared library will have - # missing symbols, but that's perfectly fine -- they will be resolved at - # import time. - # Set some general flags - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(AER_LINKER_FLAGS "${AER_LINKER_FLAGS} -undefined dynamic_lookup") - else() - # -flat_namespace linker flag is needed otherwise dynamic symbol resolution doesn't work as expected with GCC. - # Symbols with the same name exist in different .so, so the loader just takes the first one it finds, - # which is usually the one from the first .so loaded. - # See: Two-Leve namespace symbol resolution - set(AER_LINKER_FLAGS "${AER_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace") - endif() - if(ARG_SHARED) - set_target_properties(${target_name} PROPERTIES MACOSX_RPATH ON) - endif() - endif() - # -fvisibility=hidden is required to allow multiple modules compiled against - # different pybind versions to work properly, and for some features (e.g. - # py::module_local). We force it on everything inside the `pybind11` - # namespace; also turning it on for a pybind module compilation here avoids - # potential warnings or issues from having mixed hidden/non-hidden types. - set_target_properties(${target_name} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}") - set_target_properties(${target_name} PROPERTIES SUFFIX "${PYTHON_EXTENSION_MODULE_SUFFIX}") - set_target_properties(${target_name} PROPERTIES CXX_VISIBILITY_PRESET "hidden") - set_target_properties(${target_name} PROPERTIES CUDA_VISIBILITY_PRESET "hidden") - set_target_properties(${target_name} PROPERTIES - CXX_STANDARD 14 - LINKER_LANGUAGE CXX) - # Warning: Do not merge PROPERTIES when one of the variables can be empty, it breaks - # the rest of the properties so they are not properly added. - set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${AER_LINKER_FLAGS}) - set_target_properties(${target_name} PROPERTIES COMPILE_FLAGS ${AER_COMPILER_FLAGS}) -endfunction() diff --git a/cmake/conan.cmake b/cmake/conan.cmake deleted file mode 100644 index abdf4863fd..0000000000 --- a/cmake/conan.cmake +++ /dev/null @@ -1,612 +0,0 @@ -# The MIT License (MIT) - -# Copyright (c) 2018 JFrog - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - - - -# This file comes from: https://github.com/conan-io/cmake-conan. Please refer -# to this repository for issues and documentation. - -# Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is called. -# It will take CMake current settings (os, compiler, compiler version, architecture) -# and translate them to conan settings for installing and retrieving dependencies. - -# It is intended to facilitate developers building projects that have conan dependencies, -# but it is only necessary on the end-user side. It is not necessary to create conan -# packages, in fact it shouldn't be use for that. Check the project documentation. - -# version: 0.15.0 - -include(CMakeParseArguments) - -function(_get_msvc_ide_version result) - set(${result} "" PARENT_SCOPE) - if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) - set(${result} 8 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) - set(${result} 9 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) - set(${result} 10 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) - set(${result} 11 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) - set(${result} 12 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) - set(${result} 14 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) - set(${result} 15 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930) - set(${result} 16 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1930 AND MSVC_VERSION VERSION_LESS 1950) - set(${result} 17 PARENT_SCOPE) - else() - message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]") - endif() -endfunction() - -function(conan_cmake_settings result) - #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER}) - #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER_ID}) - #message(STATUS "VERSION " ${CMAKE_CXX_COMPILER_VERSION}) - #message(STATUS "FLAGS " ${CMAKE_LANG_FLAGS}) - #message(STATUS "LIB ARCH " ${CMAKE_CXX_LIBRARY_ARCHITECTURE}) - #message(STATUS "BUILD TYPE " ${CMAKE_BUILD_TYPE}) - #message(STATUS "GENERATOR " ${CMAKE_GENERATOR}) - #message(STATUS "GENERATOR WIN64 " ${CMAKE_CL_64}) - - message(STATUS "Conan: Automatic detection of conan settings from cmake") - - parse_arguments(${ARGV}) - - if(ARGUMENTS_BUILD_TYPE) - set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE}) - elseif(CMAKE_BUILD_TYPE) - set(_CONAN_SETTING_BUILD_TYPE ${CMAKE_BUILD_TYPE}) - else() - message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") - endif() - - string(TOUPPER ${_CONAN_SETTING_BUILD_TYPE} _CONAN_SETTING_BUILD_TYPE_UPPER) - if (_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "DEBUG") - set(_CONAN_SETTING_BUILD_TYPE "Debug") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELEASE") - set(_CONAN_SETTING_BUILD_TYPE "Release") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO") - set(_CONAN_SETTING_BUILD_TYPE "RelWithDebInfo") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL") - set(_CONAN_SETTING_BUILD_TYPE "MinSizeRel") - endif() - - if(ARGUMENTS_ARCH) - set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH}) - endif() - #handle -s os setting - if(CMAKE_SYSTEM_NAME) - #use default conan os setting if CMAKE_SYSTEM_NAME is not defined - set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) - if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - set(CONAN_SYSTEM_NAME Macos) - endif() - set(CONAN_SUPPORTED_PLATFORMS Windows Linux Macos Android iOS FreeBSD WindowsStore) - list (FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index) - if (${_index} GREATER -1) - #check if the cmake system is a conan supported one - set(_CONAN_SETTING_OS ${CONAN_SYSTEM_NAME}) - else() - message(FATAL_ERROR "cmake system ${CONAN_SYSTEM_NAME} is not supported by conan. Use one of ${CONAN_SUPPORTED_PLATFORMS}") - endif() - endif() - - get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) - if (";${_languages};" MATCHES ";CXX;") - set(LANGUAGE CXX) - set(USING_CXX 1) - elseif (";${_languages};" MATCHES ";C;") - set(LANGUAGE C) - set(USING_CXX 0) - else () - message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.") - endif() - - if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU) - # using GCC - # TODO: Handle other params - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(COMPILER_VERSION ${MAJOR}.${MINOR}) - if(${MAJOR} GREATER 4) - set(COMPILER_VERSION ${MAJOR}) - endif() - set(_CONAN_SETTING_COMPILER gcc) - set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang) - # using AppleClang - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(_CONAN_SETTING_COMPILER apple-clang) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang) - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(_CONAN_SETTING_COMPILER clang) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) - if(APPLE) - cmake_policy(GET CMP0025 APPLE_CLANG_POLICY) - if(NOT APPLE_CLANG_POLICY STREQUAL NEW) - message(STATUS "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it") - set(_CONAN_SETTING_COMPILER apple-clang) - endif() - endif() - if(${_CONAN_SETTING_COMPILER} STREQUAL clang AND ${MAJOR} GREATER 7) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}) - endif() - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC) - set(_VISUAL "Visual Studio") - _get_msvc_ide_version(_VISUAL_VERSION) - if("${_VISUAL_VERSION}" STREQUAL "") - message(FATAL_ERROR "Conan: Visual Studio not recognized") - else() - set(_CONAN_SETTING_COMPILER ${_VISUAL}) - set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) - endif() - - if(NOT _CONAN_SETTING_ARCH) - if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") - set(_CONAN_SETTING_ARCH x86_64) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") - message(STATUS "Conan: Using default ARM architecture from MSVC") - set(_CONAN_SETTING_ARCH armv6) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") - set(_CONAN_SETTING_ARCH x86) - else () - message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") - endif() - endif() - - conan_cmake_detect_vs_runtime(_vs_runtime) - message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}") - set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime}) - - if (CMAKE_GENERATOR_TOOLSET) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - endif() - else() - message(FATAL_ERROR "Conan: compiler setup not recognized") - endif() - - # If profile is defined it is used - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARGUMENTS_DEBUG_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_DEBUG_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_RELEASE_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND ARGUMENTS_RELWITHDEBINFO_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_RELWITHDEBINFO_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" AND ARGUMENTS_MINSIZEREL_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_MINSIZEREL_PROFILE}) - elseif(ARGUMENTS_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_PROFILE}) - endif() - - foreach(ARG ${_APPLIED_PROFILES}) - set(_SETTINGS ${_SETTINGS} -pr=${ARG}) - endforeach() - - if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") - set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version - compiler.runtime compiler.libcxx compiler.toolset) - endif() - - # Automatic from CMake - foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) - string(TOUPPER ${ARG} _arg_name) - string(REPLACE "." "_" _arg_name ${_arg_name}) - if(_CONAN_SETTING_${_arg_name}) - set(_SETTINGS ${_SETTINGS} -s ${ARG}=${_CONAN_SETTING_${_arg_name}}) - endif() - endforeach() - - foreach(ARG ${ARGUMENTS_SETTINGS}) - set(_SETTINGS ${_SETTINGS} -s ${ARG}) - endforeach() - - message(STATUS "Conan: Settings= ${_SETTINGS}") - - set(${result} ${_SETTINGS} PARENT_SCOPE) -endfunction() - - -function(conan_cmake_detect_unix_libcxx result) - # Take into account any -stdlib in compile options - get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) - - # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions - get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS) - foreach(define ${defines}) - if(define MATCHES "_GLIBCXX_USE_CXX11_ABI") - if(define MATCHES "^-D") - set(compile_options ${compile_options} "${define}") - else() - set(compile_options ${compile_options} "-D${define}") - endif() - endif() - endforeach() - - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "#include " - COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM - - OUTPUT_VARIABLE string_defines - ) - - if(string_defines MATCHES "#define __GLIBCXX__") - # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake - if(DEFINED _GLIBCXX_USE_CXX11_ABI) - if(_GLIBCXX_USE_CXX11_ABI) - set(${result} libstdc++11 PARENT_SCOPE) - return() - else() - set(${result} libstdc++ PARENT_SCOPE) - return() - endif() - endif() - - if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n") - set(${result} libstdc++11 PARENT_SCOPE) - else() - # Either the compiler is missing the define because it is old, and so - # it can't use the new abi, or the compiler was configured to use the - # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS) - set(${result} libstdc++ PARENT_SCOPE) - endif() - else() - set(${result} libc++ PARENT_SCOPE) - endif() -endfunction() - -function(conan_cmake_detect_vs_runtime result) - string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) - set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - foreach(variable ${variables}) - if(NOT "${${variable}}" STREQUAL "") - string(REPLACE " " ";" flags ${${variable}}) - foreach (flag ${flags}) - if(${flag} STREQUAL "/MD" OR ${flag} STREQUAL "/MDd" OR ${flag} STREQUAL "/MT" OR ${flag} STREQUAL "/MTd") - string(SUBSTRING ${flag} 1 -1 runtime) - set(${result} ${runtime} PARENT_SCOPE) - return() - endif() - endforeach() - endif() - endforeach() - if(${build_type} STREQUAL "DEBUG") - set(${result} "MDd" PARENT_SCOPE) - else() - set(${result} "MD" PARENT_SCOPE) - endif() -endfunction() - - -macro(parse_arguments) - set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD) - set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND) - set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE - PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO - INSTALL_ARGS CONFIGURATION_TYPES) - cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) -endmacro() - -function(conan_cmake_install) - # Calls "conan install" - # Argument BUILD is equivalant to --build={missing, PkgName,...} or - # --build when argument is 'BUILD all' (which builds all packages from source) - # Argument CONAN_COMMAND, to specify the conan path, e.g. in case of running from source - # cmake does not identify conan as command, even if it is +x and it is in the path - parse_arguments(${ARGV}) - - if(CONAN_CMAKE_MULTI) - set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake_multi) - else() - set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake) - endif() - - set(CONAN_BUILD_POLICY "") - foreach(ARG ${ARGUMENTS_BUILD}) - if(${ARG} STREQUAL "all") - set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build) - break() - else() - set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build=${ARG}) - endif() - endforeach() - if(ARGUMENTS_CONAN_COMMAND) - set(CONAN_CMD ${ARGUMENTS_CONAN_COMMAND}) - else() - conan_check(REQUIRED) - endif() - set(CONAN_OPTIONS "") - if(ARGUMENTS_CONANFILE) - set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE}) - # A conan file has been specified - apply specified options as well if provided - foreach(ARG ${ARGUMENTS_OPTIONS}) - set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG}) - endforeach() - else() - set(CONANFILE ".") - endif() - if(ARGUMENTS_UPDATE) - set(CONAN_INSTALL_UPDATE --update) - endif() - if(ARGUMENTS_NO_IMPORTS) - set(CONAN_INSTALL_NO_IMPORTS --no-imports) - endif() - set(CONAN_INSTALL_FOLDER "") - if(ARGUMENTS_INSTALL_FOLDER) - set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER}) - endif() - foreach(ARG ${ARGUMENTS_GENERATORS}) - set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG}) - endforeach() - foreach(ARG ${ARGUMENTS_ENV}) - set(CONAN_ENV_VARS ${CONAN_ENV_VARS} -e=${ARG}) - endforeach() - set(conan_args install ${CONANFILE} ${settings} ${CONAN_ENV_VARS} ${CONAN_GENERATORS} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_INSTALL_NO_IMPORTS} ${CONAN_OPTIONS} ${CONAN_INSTALL_FOLDER} ${ARGUMENTS_INSTALL_ARGS}) - - string (REPLACE ";" " " _conan_args "${conan_args}") - message(STATUS "Conan executing: ${CONAN_CMD} ${_conan_args}") - - if(ARGUMENTS_OUTPUT_QUIET) - execute_process(COMMAND ${CONAN_CMD} ${conan_args} - RESULT_VARIABLE return_code - OUTPUT_VARIABLE conan_output - ERROR_VARIABLE conan_output - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - else() - execute_process(COMMAND ${CONAN_CMD} ${conan_args} - RESULT_VARIABLE return_code - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - endif() - - if(NOT "${return_code}" STREQUAL "0") - message(FATAL_ERROR "Conan install failed='${return_code}'") - endif() - -endfunction() - - -function(conan_cmake_setup_conanfile) - parse_arguments(${ARGV}) - if(ARGUMENTS_CONANFILE) - get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME) - # configure_file will make sure cmake re-runs when conanfile is updated - configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk COPYONLY) - file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) - else() - conan_cmake_generate_conanfile(${ARGV}) - endif() -endfunction() - -function(conan_cmake_generate_conanfile) - # Generate, writing in disk a conanfile.txt with the requires, options, and imports - # specified as arguments - # This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR) - parse_arguments(${ARGV}) - set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt") - - file(WRITE ${_FN} "[generators]\ncmake\n\n[requires]\n") - foreach(ARG ${ARGUMENTS_REQUIRES}) - file(APPEND ${_FN} ${ARG} "\n") - endforeach() - - file(APPEND ${_FN} ${ARG} "\n[options]\n") - foreach(ARG ${ARGUMENTS_OPTIONS}) - file(APPEND ${_FN} ${ARG} "\n") - endforeach() - - file(APPEND ${_FN} ${ARG} "\n[imports]\n") - foreach(ARG ${ARGUMENTS_IMPORTS}) - file(APPEND ${_FN} ${ARG} "\n") - endforeach() -endfunction() - - -macro(conan_load_buildinfo) - if(CONAN_CMAKE_MULTI) - set(_CONANBUILDINFO conanbuildinfo_multi.cmake) - else() - set(_CONANBUILDINFO conanbuildinfo.cmake) - endif() - if(ARGUMENTS_INSTALL_FOLDER) - set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER}) - else() - set(_CONANBUILDINFOFOLDER ${CMAKE_CURRENT_BINARY_DIR}) - endif() - # Checks for the existence of conanbuildinfo.cmake, and loads it - # important that it is macro, so variables defined at parent scope - if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}") - message(STATUS "Conan: Loading ${_CONANBUILDINFO}") - include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}) - else() - message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}") - endif() -endmacro() - - -macro(conan_cmake_run) - parse_arguments(${ARGV}) - - if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES) - message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators") - elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE) - message(WARNING "CONFIGURATION_TYPES and BUILD_TYPE arguments should not be defined at the same time.") - endif() - - if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE AND NOT CONAN_EXPORTED - AND NOT ARGUMENTS_BUILD_TYPE) - set(CONAN_CMAKE_MULTI ON) - if (NOT ARGUMENTS_CONFIGURATION_TYPES) - set(ARGUMENTS_CONFIGURATION_TYPES "Release;Debug") - endif() - message(STATUS "Conan: Using cmake-multi generator") - else() - set(CONAN_CMAKE_MULTI OFF) - endif() - - if(NOT CONAN_EXPORTED) - conan_cmake_setup_conanfile(${ARGV}) - if(CONAN_CMAKE_MULTI) - foreach(CMAKE_BUILD_TYPE ${ARGUMENTS_CONFIGURATION_TYPES}) - set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE}) - conan_cmake_settings(settings ${ARGV}) - conan_cmake_install(SETTINGS ${settings} ${ARGV}) - endforeach() - set(CMAKE_BUILD_TYPE) - else() - conan_cmake_settings(settings ${ARGV}) - conan_cmake_install(SETTINGS ${settings} ${ARGV}) - endif() - endif() - - if (NOT ARGUMENTS_NO_LOAD) - conan_load_buildinfo() - endif() - - if(ARGUMENTS_BASIC_SETUP) - foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS SKIP_STD) - if(ARGUMENTS_${_option}) - if(${_option} STREQUAL "CMAKE_TARGETS") - list(APPEND _setup_options "TARGETS") - else() - list(APPEND _setup_options ${_option}) - endif() - endif() - endforeach() - conan_basic_setup(${_setup_options}) - endif() -endmacro() - -macro(conan_check) - # Checks conan availability in PATH - # Arguments REQUIRED and VERSION are optional - # Example usage: - # conan_check(VERSION 1.0.0 REQUIRED) - message(STATUS "Conan: checking conan executable") - set(options REQUIRED) - set(oneValueArgs VERSION) - cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN}) - - find_program(CONAN_CMD conan) - if(NOT CONAN_CMD AND CONAN_REQUIRED) - message(FATAL_ERROR "Conan executable not found!") - endif() - message(STATUS "Conan: Found program ${CONAN_CMD}") - execute_process(COMMAND ${CONAN_CMD} --version - OUTPUT_VARIABLE CONAN_VERSION_OUTPUT - ERROR_VARIABLE CONAN_VERSION_OUTPUT) - message(STATUS "Conan: Version found ${CONAN_VERSION_OUTPUT}") - - if(DEFINED CONAN_VERSION) - string(REGEX MATCH ".*Conan version ([0-9]+\.[0-9]+\.[0-9]+)" FOO - "${CONAN_VERSION_OUTPUT}") - if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION}) - message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \ - required: ${CONAN_VERSION}. Consider updating via 'pip \ - install conan==${CONAN_VERSION}'.") - endif() - endif() -endmacro() - -function(conan_add_remote) - # Adds a remote - # Arguments URL and NAME are required, INDEX and COMMAND are optional - # Example usage: - # conan_add_remote(NAME bincrafters INDEX 1 - # URL https://api.bintray.com/conan/bincrafters/public-conan) - set(oneValueArgs URL NAME INDEX COMMAND) - cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN}) - - if(DEFINED CONAN_INDEX) - set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}") - endif() - if(CONAN_COMMAND) - set(CONAN_CMD ${CONAN_COMMAND}) - else() - conan_check(REQUIRED) - endif() - message(STATUS "Conan: Adding ${CONAN_NAME} remote repository (${CONAN_URL})") - execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_URL} - ${CONAN_INDEX_ARG} -f) -endfunction() - -macro(conan_config_install) - # install a full configuration from a local or remote zip file - # Argument ITEM is required, arguments TYPE, SOURCE, TARGET and VERIFY_SSL are optional - # Example usage: - # conan_config_install(ITEM https://github.com/conan-io/cmake-conan.git - # TYPE git SOURCE source-folder TARGET target-folder VERIFY_SSL false) - set(oneValueArgs ITEM TYPE SOURCE TARGET VERIFY_SSL) - set(multiValueArgs ARGS) - cmake_parse_arguments(CONAN "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(CONAN_CONFIG_INSTALL_ARGS "") - - find_program(CONAN_CMD conan) - if(NOT CONAN_CMD AND CONAN_REQUIRED) - message(FATAL_ERROR "Conan executable not found!") - endif() - - if(DEFINED CONAN_VERIFY_SSL) - set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --verify-ssl ${CONAN_VERIFY_SSL}") - endif() - - if(DEFINED CONAN_TYPE) - set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --type ${CONAN_TYPE}") - endif() - - if(DEFINED CONAN_ARGS) - set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --args \"${CONAN_ARGS}\"") - endif() - - if(DEFINED CONAN_SOURCE) - set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --source-folder ${CONAN_SOURCE}") - endif() - - if(DEFINED CONAN_TARGET) - set(CONAN_CONFIG_INSTALL_ARGS "${CONAN_CONFIG_INSTALL_ARGS} --target-folder ${CONAN_TARGET}") - endif() - - message(STATUS "Conan: Installing config from ${CONAN_ITEM}") - execute_process(COMMAND ${CONAN_CMD} config install ${CONAN_CONFIG_INSTALL_ARGS} ${CONAN_ITEM}) -endmacro() diff --git a/cmake/conan_utils.cmake b/cmake/conan_utils.cmake deleted file mode 100644 index aefd4f8540..0000000000 --- a/cmake/conan_utils.cmake +++ /dev/null @@ -1,92 +0,0 @@ -include(conan) - -macro(_rename_conan_lib package) - add_library(AER_DEPENDENCY_PKG::${package} INTERFACE IMPORTED) - target_link_libraries(AER_DEPENDENCY_PKG::${package} PUBLIC INTERFACE CONAN_PKG::${package}) -endmacro() - -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.9.2) - list(APPEND AER_CONAN_LIBS nlohmann_json spdlog) - if(APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") - list(APPEND AER_CONAN_LIBS llvm-openmp) - if (DEFINED ENV{AER_CMAKE_OPENMP_BUILD}) - if(SKBUILD) - set(AER_CONAN_OPTIONS "llvm-openmp:shared=True") - else() - set(AER_CONAN_OPTIONS "llvm-openmp:shared=False") - endif() - conan_cmake_run(REQUIRES "llvm-openmp/12.0.1" - OPTIONS ${AER_CONAN_OPTIONS} - ENV CONAN_CMAKE_PROGRAM=${CMAKE_COMMAND} - BASIC_SETUP - CMAKE_TARGETS - KEEP_RPATHS - BUILD llvm-openmp*) - else() - set(REQUIREMENTS ${REQUIREMENTS} llvm-openmp/12.0.1) - if(SKBUILD) - set(CONAN_OPTIONS ${CONAN_OPTIONS} "llvm-openmp:shared=True") - endif() - endif() - endif() - - if(AER_THRUST_BACKEND AND NOT AER_THRUST_BACKEND STREQUAL "CUDA" AND NOT AER_THRUST_BACKEND STREQUAL "ROCM") - set(REQUIREMENTS ${REQUIREMENTS} thrust/1.9.5) - list(APPEND AER_CONAN_LIBS thrust) - string(TOLOWER ${AER_THRUST_BACKEND} THRUST_BACKEND) - set(CONAN_OPTIONS ${CONAN_OPTIONS} "thrust:device_system=${THRUST_BACKEND}") - if(THRUST_BACKEND MATCHES "tbb") - list(APPEND AER_CONAN_LIBS tbb) - endif() - endif() - - if(BUILD_TESTS) - set(REQUIREMENTS ${REQUIREMENTS} catch2/2.13.6) - list(APPEND AER_CONAN_LIBS catch2) - endif() - if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") - conan_cmake_run(REQUIRES ${REQUIREMENTS} - OPTIONS ${CONAN_OPTIONS} - ENV CONAN_CMAKE_PROGRAM=${CMAKE_COMMAND} - BASIC_SETUP - CMAKE_TARGETS - KEEP_RPATHS - ARCH armv8 - SETTINGS arch_build=armv8 - BUILD missing) - else() - conan_cmake_run(REQUIRES ${REQUIREMENTS} - OPTIONS ${CONAN_OPTIONS} - ENV CONAN_CMAKE_PROGRAM=${CMAKE_COMMAND} - BASIC_SETUP - CMAKE_TARGETS - KEEP_RPATHS - BUILD missing) - endif() - - # Headers includes - if(AER_THRUST_BACKEND AND NOT AER_THRUST_BACKEND STREQUAL "CUDA" AND NOT AER_THRUST_BACKEND STREQUAL "ROCM") - set(AER_SIMULATOR_CPP_EXTERNAL_LIBS ${AER_SIMULATOR_CPP_EXTERNAL_LIBS} ${CONAN_INCLUDE_DIRS_THRUST}) - endif() - - # Reassign targets from CONAN_PKG to AER_DEPENDENCY_PKG - foreach(CONAN_LIB ${AER_CONAN_LIBS}) - _rename_conan_lib(${CONAN_LIB}) - endforeach() - - if(APPLE) - set(OPENMP_FOUND TRUE) - if(NOT SKBUILD) - set(AER_LIBRARIES ${AER_LIBRARIES} AER_DEPENDENCY_PKG::llvm-openmp) - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CONAN_CXX_FLAGS_LLVM-OPENMP}") - set(AER_SIMULATOR_CPP_EXTERNAL_LIBS ${AER_SIMULATOR_CPP_EXTERNAL_LIBS} ${CONAN_INCLUDE_DIRS_LLVM-OPENMP}) - set(BACKEND_REDIST_DEPS ${BACKEND_REDIST_DEPS} "${CONAN_LIB_DIRS_LLVM-OPENMP}/libomp.dylib") - endif() - endif() -endmacro() diff --git a/cmake/dependency_utils.cmake b/cmake/dependency_utils.cmake deleted file mode 100644 index 8fd3003a55..0000000000 --- a/cmake/dependency_utils.cmake +++ /dev/null @@ -1,60 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2020 -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. - - -macro(setup_dependencies) - # Defines AER_DEPENDENCY_PKG alias which refers to either conan-provided or system libraries. - if(DISABLE_CONAN) - _use_system_libraries() - else() - include(conan_utils) - setup_conan() - endif() -endmacro() - -macro(_use_system_libraries) - # Use system libraries - _import_aer_system_dependency(nlohmann_json 3.1.1) - _import_aer_system_dependency(spdlog 1.9.2) - - if(AER_THRUST_BACKEND AND NOT AER_THRUST_BACKEND STREQUAL "CUDA") - string(TOLOWER ${AER_THRUST_BACKEND} THRUST_BACKEND) - _import_aer_system_dependency(Thrust 1.9.5) - endif() - - if(BUILD_TESTS) - _import_aer_system_dependency(Catch2 2.13.6) - endif() - - if(APPLE) - # Fix linking. See https://stackoverflow.com/questions/54068035 - link_directories(/usr/local/lib) #brew - link_directories(/opt/local/lib) #ports - endif() -endmacro() - -macro(_import_aer_system_dependency package version) - # Arguments: - # package: name of package to search for using find_package() - # version: version of package to search for - - find_package(${package} ${version} EXACT QUIET) - if(NOT ${package}_FOUND) - message(STATUS "${package} ${version} NOT found! Looking for any other version available.") - find_package(${package} REQUIRED) - message(STATUS "${package} version found: ${${package}_VERSION}. WARNING: This version may not work!!!") - endif() - string(TOLOWER ${package} PACKAGE_LOWER) # Conan use lowercase for every lib - add_library(AER_DEPENDENCY_PKG::${PACKAGE_LOWER} INTERFACE IMPORTED) - target_link_libraries(AER_DEPENDENCY_PKG::${PACKAGE_LOWER} PUBLIC INTERFACE ${package}) - message(STATUS "Using system-provided ${PACKAGE_LOWER} library") -endmacro() 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/cmake/nvcc_add_compiler_options.cmake b/cmake/nvcc_add_compiler_options.cmake deleted file mode 100644 index c943fe4543..0000000000 --- a/cmake/nvcc_add_compiler_options.cmake +++ /dev/null @@ -1,13 +0,0 @@ -function(nvcc_add_compiler_options_list inList outVarName) - set(L "${inList}") - list(TRANSFORM L PREPEND " --compiler-options ") - string(REPLACE ";" " " TMP ${L}) - set(${outVarName} ${TMP} PARENT_SCOPE) -endfunction() - -function(nvcc_add_compiler_options inStr outVarName) - string(REPLACE " " ";" L "${inStr}") - list(TRANSFORM L PREPEND " --compiler-options ") - string(REPLACE ";" " " TMP ${L}) - set(${outVarName} ${TMP} PARENT_SCOPE) -endfunction() diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000000..fcb71854fb --- /dev/null +++ b/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMakeDeps + +class AerConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + + def requirements(self): + self.requires("openblas/0.3.30") + self.requires("nlohmann_json/3.11.3") + self.requires("spdlog/1.13.0") + self.requires("fmt/10.2.1") + self.requires("pybind11/2.11.1") + self.requires("thrust/1.17.2") + + if self.settings.os in ["Linux", "Macos"]: + self.requires("llvm-openmp/20.1.6") + + def generate(self): + tc = CMakeToolchain(self) + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0091"] = "NEW" + if self.settings.get_safe("os") == "Windows": + tc.variables["CMAKE_MSVC_RUNTIME_LIBRARY"] = "MultiThreadedDLL" + tc.generate() + + deps = CMakeDeps(self) + deps.generate() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index ccf13f68a5..f3bbd6eb9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [build-system] requires = [ "setuptools", - "conan<2.0.0", + "conan>=2.0.0", "scikit-build>=0.11.0", - "cmake!=3.17.1,!=3.17.0", + "cmake>=3.17.1", "ninja", "pybind11>2.6", ] @@ -11,7 +11,6 @@ build-backend = "setuptools.build_meta" [tool.cibuildwheel] manylinux-x86_64-image = "manylinux2014" -manylinux-i686-image = "manylinux2014" skip = "pp* cp36* cp37* cp38* *musllinux*" test-skip = "cp3*-win32 cp3*-manylinux_i686" test-command = "python {project}/tools/verify_wheels.py" @@ -24,11 +23,14 @@ before-test = "pip install --only-binary=numpy,scipy numpy scipy" [tool.cibuildwheel.linux] before-all = "sed -i -e 's/^mirrorlist/#mirrorlist/' -e 's/^#baseurl/baseurl/' -e 's/mirror.centos.org/vault.centos.org/' /etc/yum.repos.d/*.repo && yum install -y openblas-devel" +[tool.cibuildwheel.linux.environment] +CONAN_HOST_PROFILE = "default" +CONAN_SETTINGS_ARCH = "x86_64" + [tool.cibuildwheel.windows] environment = { CMAKE_GENERATOR = "Visual Studio 17 2022"} [[tool.cibuildwheel.overrides]] -select = "cp3{9,10,11,12,13}-manylinux_i686" before-all = "sed -i -e 's/^mirrorlist/#mirrorlist/' -e 's/^#baseurl/baseurl/' -e 's/mirror.centos.org/vault.centos.org/' /etc/yum.repos.d/*.repo && yum install -y libatomic && yum install -y wget && bash {project}/tools/install_openblas_i686.sh && bash {project}/tools/install_rust.sh" [tool.black] diff --git a/qiskit_aer/backends/backend_utils.py b/qiskit_aer/backends/backend_utils.py index a9974175a5..b9133a9d42 100644 --- a/qiskit_aer/backends/backend_utils.py +++ b/qiskit_aer/backends/backend_utils.py @@ -15,6 +15,7 @@ Aer simulator backend utils """ import os +import json from math import log2 from types import SimpleNamespace @@ -26,9 +27,6 @@ from .compatibility import Statevector, DensityMatrix, StabilizerState, Operator, SuperOp -# pylint: disable=import-error, no-name-in-module, abstract-method -from .controller_wrappers import aer_initialize_libraries - # Available system memory SYSTEM_MEMORY_GB = psutil.virtual_memory().total / (1024**3) @@ -39,7 +37,6 @@ # Location where we put external libraries that will be # loaded at runtime by the simulator extension LIBRARY_DIR = os.path.dirname(__file__) -aer_initialize_libraries(LIBRARY_DIR) LEGACY_METHOD_MAP = { "statevector_cpu": ("statevector", "CPU"), @@ -442,7 +439,7 @@ def cpp_execute_circuits(controller, aer_circuits, noise_model, config): config.library_dir = LIBRARY_DIR noise_model = noise_model.to_dict(serializable=True) if noise_model else {} - + noise_model = json.dumps(noise_model) return controller.execute(aer_circuits, noise_model, config) diff --git a/qiskit_aer/backends/wrappers/CMakeLists.txt b/qiskit_aer/backends/wrappers/CMakeLists.txt index c20917fc9e..26a2675a3a 100644 --- a/qiskit_aer/backends/wrappers/CMakeLists.txt +++ b/qiskit_aer/backends/wrappers/CMakeLists.txt @@ -1,5 +1,4 @@ include(Linter) -find_package(Pybind11 REQUIRED) # We need to remove the -static flag, because Python Extension system only supports # dynamic linked libraries, but we want to build a shared libraries with the least @@ -21,23 +20,32 @@ if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR endif() set(AER_SIMULATOR_SOURCES "bindings.cc" "${SIMD_SOURCE_FILE}") -basic_pybind11_add_module(controller_wrappers "${AER_SIMULATOR_SOURCES}") +pybind11_add_module(controller_wrappers bindings.cc "${AER_SIMULATOR_SOURCES}") + +if (OpenMP_CXX_FOUND) + target_link_libraries(controller_wrappers PRIVATE OpenMP::OpenMP_CXX) +endif() if(AER_THRUST_BACKEND STREQUAL "CUDA") - include(nvcc_add_compiler_options) + target_compile_definitions(controller_wrappers PRIVATE AER_THRUST_CUDA) + enable_language(CUDA) set_source_files_properties(bindings.cc PROPERTIES LANGUAGE CUDA) - set_source_files_properties(bindings.cc PROPERTIES COMPILE_FLAGS "${CUDA_NVCC_FLAGS}") - if(DEFINED SIMD_SOURCE_FILE) - set_source_files_properties(${SIMD_SOURCE_FILE} PROPERTIES LANGUAGE CUDA) - nvcc_add_compiler_options_list("${SIMD_FLAGS_LIST}" SIMD_FLAGS_OUT) - set_source_files_properties(${SIMD_SOURCE_FILE} PROPERTIES COMPILE_FLAGS "${CUDA_NVCC_FLAGS} ${SIMD_FLAGS_OUT}") + set_source_files_properties(${SIMD_SOURCE_FILE} PROPERTIES LANGUAGE CUDA) endif() - string(STRIP ${AER_COMPILER_FLAGS} AER_COMPILER_FLAGS_STRIPPED) - nvcc_add_compiler_options(${AER_COMPILER_FLAGS_STRIPPED} AER_COMPILER_FLAGS_OUT) - set_target_properties(controller_wrappers PROPERTIES COMPILE_FLAGS "${AER_COMPILER_FLAGS_OUT}") - enable_language(CUDA) + set(CUDA_FLAGS "${CUDA_NVCC_FLAGS}") + + if(DEFINED SIMD_FLAGS_LIST) + string (REPLACE ";" " " SIMD_FLAGS_OUT "${SIMD_FLAGS_LIST}") + set_source_files_properties(${SIMD_SOURCE_FILE} + PROPERTIES COMPILE_FLAGS "${CUDA_FLAGS} ${SIMD_FLAGS_OUT}") + endif() + + string(STRIP "${AER_COMPILER_FLAGS}" AER_COMPILER_FLAGS_STRIPPED) + target_compile_options(controller_wrappers PRIVATE + $<$:${AER_COMPILER_FLAGS_STRIPPED}>) + elseif(AER_THRUST_BACKEND STREQUAL "ROCM") if(NOT DEFINED SIMD_SOURCE_FILE) @@ -61,7 +69,7 @@ else() endif() target_include_directories(controller_wrappers PRIVATE ${AER_SIMULATOR_CPP_SRC_DIR} PRIVATE ${AER_SIMULATOR_CPP_EXTERNAL_LIBS}) -target_link_libraries(controller_wrappers ${AER_LIBRARIES}) +target_link_libraries(controller_wrappers PRIVATE pybind11::headers pybind11::module ${AER_LIBRARIES}) target_compile_definitions(controller_wrappers PRIVATE ${AER_COMPILER_DEFINITIONS}) install(TARGETS controller_wrappers LIBRARY DESTINATION qiskit_aer/backends) diff --git a/qiskit_aer/backends/wrappers/aer_controller_binding.hpp b/qiskit_aer/backends/wrappers/aer_controller_binding.hpp index 02a5516f8c..0c529685b8 100644 --- a/qiskit_aer/backends/wrappers/aer_controller_binding.hpp +++ b/qiskit_aer/backends/wrappers/aer_controller_binding.hpp @@ -79,8 +79,6 @@ void read_value(const py::tuple &t, size_t index, T &v) { template void bind_aer_controller(MODULE m) { - m.def("aer_initialize_libraries", &initialize_libraries); - py::class_> aer_ctrl(m, "aer_controller_execute"); aer_ctrl.def(py::init<>()); @@ -88,16 +86,20 @@ void bind_aer_controller(MODULE m) { [aer_ctrl](const ControllerExecutor &self) { return py::make_tuple(aer_ctrl, py::tuple()); }); - aer_ctrl.def("execute", - [aer_ctrl](ControllerExecutor &self, - std::vector> &circuits, - py::object noise_model, AER::Config &config) { - Noise::NoiseModel noise_model_native; - if (noise_model) - noise_model_native.load_from_json(noise_model); + aer_ctrl.def("execute", [aer_ctrl]( + ControllerExecutor &self, + std::vector> &circuits, + py::object noise_model, AER::Config &config) { + Noise::NoiseModel noise_model_native; + if (noise_model) { + if (py::isinstance(noise_model)) { + auto noise_model_string = noise_model.cast(); + noise_model_native.load_from_json(json_t::parse(noise_model_string)); + } + } - return self.execute(circuits, noise_model_native, config); - }); + return self.execute(circuits, noise_model_native, config); + }); aer_ctrl.def("available_devices", [aer_ctrl](ControllerExecutor &self) { diff --git a/requirements-dev.txt b/requirements-dev.txt index 132c416eee..3786b35573 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,8 +1,8 @@ sympy qiskit>=2.0.0 stestr>=2.5.0 -cmake!=3.17.1,!=3.17.0 -conan<2.0.0 +cmake>=3.27 +conan>=2.0.0 scikit-build>=0.11.0 asv cvxpy<1.6.0 diff --git a/setup.py b/setup.py index cada1e3693..cba933c687 100644 --- a/setup.py +++ b/setup.py @@ -4,11 +4,14 @@ Main setup file for qiskit-aer """ import os +import pathlib import platform +import subprocess import setuptools from skbuild import setup +DEBUG_MODE = os.environ.get("DEBUG") is not None PACKAGE_NAME = os.getenv("QISKIT_AER_PACKAGE_NAME", "qiskit-aer") CUDA_MAJOR = os.getenv("QISKIT_AER_CUDA_MAJOR", "12") @@ -85,11 +88,91 @@ with open(README_PATH) as readme_file: README = readme_file.read() +# run Conan +BUILD_DIR = os.path.join(os.path.dirname(__file__), "build") +os.makedirs(BUILD_DIR, exist_ok=True) +print("PATH:", os.environ.get("PATH"), flush=True) +print("CC:", os.environ.get("CC"), flush=True) +print("CXX:", os.environ.get("CXX"), flush=True) +try: + result = subprocess.run( + ["which", "-a", "gcc"], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + print(f"which -a gcc result: {result.stdout.strip()}", flush=True) + result = subprocess.run( + ["gcc", "-dumpmachine"], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + print(f"gcc -dumpmachine gives: {result.stdout.strip()}", flush=True) + + result = subprocess.run( + ["gcc", "-dumpversion"], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + + print(f"gcc -dumpversion gives: {result.stdout.strip()}", flush=True) + +except Exception as e: + print(f"Failed to run 'gcc -dumpmachine':", flush=True) +try: + subprocess.check_call(["conan", "profile", "detect", "--force"], cwd=BUILD_DIR) + print("CONAN: New profile generated", flush=True) +except subprocess.CalledProcessError: + print("CONAN: profile already exists", flush=True) + +conan_profile_path = pathlib.Path.home() / ".conan2" / "profiles" / "default" +if conan_profile_path.exists(): + print(f"CONAN: Profile found:", flush=True) + print(conan_profile_path.read_text(), flush=True) +else: + print(f"CONAN: Profile not found", flush=True) + +subprocess.check_call( + [ + "conan", + "install", + os.path.dirname(__file__), + "--output-folder=build", + "--build=missing", + "-s", + "compiler.cppstd=17", + "-s:h", + "arch=x86_64", + "-s:b", + "arch=x86_64", + "-s", + f"build_type={'Debug' if DEBUG_MODE else 'Release'}", + "-v", + "debug", + ] +) + +CONAN_TOOLCHAIN_FILE = os.path.join(BUILD_DIR, "conan_toolchain.cmake") cmake_args = [] -is_win_32_bit = platform.system() == "Windows" and platform.architecture()[0] == "32bit" -if is_win_32_bit: - cmake_args.append("-DCMAKE_GENERATOR_PLATFORM=Win32") +cmake_args.append(f"-DCMAKE_TOOLCHAIN_FILE={CONAN_TOOLCHAIN_FILE}") +# try to be as verbose as possible +cmake_args.append(f"-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON") +cmake_args.append(f"-DCMAKE_MESSAGE_LOG_LEVEL=STATUS") +cmake_args.append(f"-DCMAKE_EXPORT_COMPILE_COMMANDS=ON") + +if DEBUG_MODE: + cmake_args.append(f"-DCMAKE_BUILD_TYPE=Debug") + +if platform.system() == "Windows": + cmake_args.append(f"-DCMAKE_POLICY_DEFAULT_CMP0091=NEW") + if platform.architecture()[0] == "32bit": + cmake_args.append("-DCMAKE_GENERATOR_PLATFORM=Win32") setup( diff --git a/src/controllers/controller_execute.hpp b/src/controllers/controller_execute.hpp index a0f114c477..492b559391 100644 --- a/src/controllers/controller_execute.hpp +++ b/src/controllers/controller_execute.hpp @@ -15,7 +15,6 @@ #ifndef _aer_controller_execute_hpp_ #define _aer_controller_execute_hpp_ -#include "misc/hacks.hpp" #include #include "framework/config.hpp" @@ -29,12 +28,6 @@ namespace AER { -void initialize_libraries(const std::string &lib_dir) { - // Fix for MacOS and OpenMP library double initialization crash. - // Issue: https://github.com/Qiskit/qiskit-aer/issues/1 - Hacks::maybe_load_openmp(lib_dir); -} - template Result controller_execute(std::vector> &input_circs, AER::Noise::NoiseModel &noise_model, diff --git a/src/framework/pybind_basics.hpp b/src/framework/pybind_basics.hpp index cfcb1f2fe5..416a318f80 100644 --- a/src/framework/pybind_basics.hpp +++ b/src/framework/pybind_basics.hpp @@ -186,7 +186,11 @@ py::array_t to_numpy(matrix &&src) { matrix *src_ptr = new matrix(std::move(src)); auto capsule = py::capsule( src_ptr, [](void *p) { delete reinterpret_cast *>(p); }); - return py::array_t(shape, src_ptr->data(), capsule); + std::array strides{ + static_cast(sizeof(T)), + static_cast(sizeof(T) * src_ptr->GetRows())}; + return py::array_t(shape, strides, src_ptr->data(), + capsule); } template @@ -195,9 +199,10 @@ py::array_t to_numpy(AER::Vector &&src) { auto capsule = py::capsule( src_ptr, [](void *p) { delete reinterpret_cast *>(p); }); return py::array_t( - src_ptr->size(), // shape of array - src_ptr->data(), // c-style contiguous strides for vector - capsule // numpy array references this parent + {src_ptr->size()}, // shape of array + {sizeof(T)}, // strides data (1 stride here) + src_ptr->data(), // c-style contiguous strides for vector + capsule // numpy array references this parent ); } @@ -207,9 +212,10 @@ py::array_t to_numpy(std::vector &&src) { auto capsule = py::capsule( src_ptr, [](void *p) { delete reinterpret_cast *>(p); }); return py::array_t( - src_ptr->size(), // shape of array - src_ptr->data(), // c-style contiguous strides for vector - capsule // numpy array references this parent + {src_ptr->size()}, // shape of array + {sizeof(T)}, // strides data (1 stride here) + src_ptr->data(), // c-style contiguous strides for vector + capsule // numpy array references this parent ); } diff --git a/src/misc/hacks.hpp b/src/misc/hacks.hpp deleted file mode 100644 index d4992567cf..0000000000 --- a/src/misc/hacks.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/** - * This code is part of Qiskit. - * - * (C) Copyright IBM 2018, 2019. - * - * This code is licensed under the Apache License, Version 2.0. You may - * obtain a copy of this license in the LICENSE.txt file in the root directory - * of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. - * - * Any modifications or derivative works of this code must retain this - * copyright notice, and modified files need to carry a notice indicating - * that they have been altered from the originals. - */ - -#ifndef _aer_misc_hacks_hpp_ -#define _aer_misc_hacks_hpp_ - -// We only need this hack for MacOS builds, -// on Linux and Windows everything works fine -#ifdef __APPLE__ -#include -#include -#include -#include -#include -#include -#include - -#if defined(__clang__) -#include "clang_omp_symbols.hpp" -#elif defined(__GNUC__) || defined(__GNUG__) -#include "gcc_omp_symbols.hpp" -#endif - -namespace { -/* - * Returns the path to the already loaded OpenMP library, if there's no - * library loaded, then load our default one. - */ - -auto _apple_get_loaded_openmp_library = - [](const std::string &default_path) -> std::string { - // Iterate through all images currently in memory - for (int32_t i = _dyld_image_count(); i >= 0; i--) { - const char *image_name = _dyld_get_image_name(i); - if (image_name) { - // These are the only libraries we know that implement OpenMP on Mac - // and that clash each other - if (strstr(image_name, "libomp.dylib") || - strstr(image_name, "libiomp5.dylib") || - strstr(image_name, "libgomp.dylib")) { - return std::string(image_name); - } - } - } - return default_path + "/libomp.dylib"; -}; - -/* - * I hope this is a temporary hack, for fixing Issue: - * https://github.com/Qiskit/qiskit-aer/issues/1 - */ -auto _apple_maybe_load_openmp = [](const std::string &library_path) -> void { - // dlopen() will return a handle to the library if this is already loaded - void *handle = - dlopen(_apple_get_loaded_openmp_library(library_path).c_str(), RTLD_LAZY); - if (handle == nullptr) { - fprintf(stderr, - "WARNING: Couldn't load libomp.dylib but we needed to. Error: %s\n", - dlerror()); - fprintf(stderr, "Make sure you have libomp.dylib or libiomp5.dylib " - "accesible to the program\n"); - } - AER::Hacks::populate_hooks(handle); -}; -} // namespace - -#endif // endif __APPLE__ - -namespace AER { -namespace Hacks { -#ifdef __APPLE__ -const auto maybe_load_openmp = ::_apple_maybe_load_openmp; -#else -const auto maybe_load_openmp = [](const std::string &dummy) -> void {}; -#endif -} // namespace Hacks -} // namespace AER - -#endif