Skip to content

Commit

Permalink
Merge branch 'main' into restore_arm64_macos
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorii authored Aug 21, 2024
2 parents 868d9e3 + eaba16c commit ad34ede
Show file tree
Hide file tree
Showing 56 changed files with 150 additions and 2,960 deletions.
109 changes: 0 additions & 109 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,117 +8,8 @@ concurrency:
group: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
standalone:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["macos-13", "ubuntu-latest", "windows-2019"]
steps:
- uses: actions/checkout@v4
- name: Set up Python '3.10'
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install deps
run: pip install "conan<2.0.0"
- 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@v2
if: runner.os == 'Windows'
- name: Compile Standalone Windows
run: |
set -e
mkdir out; cd out; cmake .. -DBUILD_TESTS=1
cmake --build . --config Release
shell: bash
if: runner.os == 'Windows'
- name: Compile Standalone
run: |
set -e
mkdir out; cd out; cmake .. -DBUILD_TESTS=1
make
shell: bash
if: runner.os != 'Windows'
- name: Run Unit Tests
run: |
cd out/bin
for test in test*
do echo $test
if ! ./$test
then
ERR=1
fi
done
if [ ! -z "$ERR" ]
then
exit 1
fi
shell: bash
- name: Run qobj
run: |
pip install -U qiskit
python tools/generate_qobj.py
cd out
Release/qasm_simulator ../qobj.json | python ../tools/verify_standalone_results.py
shell: bash
mpi_standalone:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
steps:
- uses: actions/checkout@v4
- name: Set up Python '3.10'
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install deps
run: pip install "conan<2.0.0"
- name: Install openblas and mpi
run: |
set -e
sudo apt-get update
sudo apt-get install -y libopenblas-dev openmpi-bin libopenmpi-dev
shell: bash
- name: Compile Standalone
run: |
set -e
mkdir out; cd out; cmake .. -DBUILD_TESTS=1 -DAER_MPI=True
make
shell: bash
- name: Run Unit Tests with mpi
run: |
cd out/bin
for test in test*
do echo $test
if ! /usr/bin/mpirun.openmpi -host localhost:2 -np 2 ./$test
then
ERR=1
fi
done
if [ ! -z "$ERR" ]
then
exit 1
fi
shell: bash
- name: Run qobj
run: |
pip install -U qiskit
python tools/generate_qobj.py
cd out
/usr/bin/mpirun.openmpi -host localhost:2 -np 2 Release/qasm_simulator ../qobj.json | python ../tools/verify_standalone_results.py
env:
USE_MPI: 1
shell: bash
wheel:
runs-on: ${{ matrix.os }}
needs: ["standalone"]
strategy:
matrix:
os: ["macos-13", "ubuntu-latest", "windows-2019"]
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,3 @@ docs/_build/
docs/stubs/
docs/api/

# Ignore DASK temporary files
dask-worker-space/*
151 changes: 1 addition & 150 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ include(dependency_utils)

# Get version information
get_version(${VERSION_NUM})
configure_file("${PROJECT_SOURCE_DIR}/contrib/standalone/version.hpp.in"
"${PROJECT_SOURCE_DIR}/contrib/standalone/version.hpp")

set(AER_SIMULATOR_CPP_SRC_DIR "${PROJECT_SOURCE_DIR}/src")
set(AER_SIMULATOR_CPP_EXTERNAL_LIBS
Expand Down Expand Up @@ -543,153 +541,6 @@ set(AER_LIBRARIES
${CMAKE_DL_LIBS})

set(AER_COMPILER_DEFINITIONS ${AER_COMPILER_DEFINITIONS} ${CONAN_DEFINES})
if(SKBUILD) # Terra Addon build
add_subdirectory(qiskit_aer/backends/wrappers)
else() # Standalone build
set(AER_LIBRARIES
${AER_LIBRARIES}
${THRUST_DEPENDANT_LIBS}
${MPI_DEPENDANT_LIBS})

function(build_cuda target src_file is_exec)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64")
if (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
# We build SIMD filed separately, because they will be reached only if the
# machine running the code has SIMD support
set(SIMD_SOURCE_FILE "${PROJECT_SOURCE_DIR}/src/simulators/statevector/qv_avx2.cpp")
endif()
endif()
set_source_files_properties(${SIMD_SOURCE_FILE} PROPERTIES LANGUAGE CUDA)
set_source_files_properties(${src_file} PROPERTIES LANGUAGE CUDA)
set_source_files_properties(${src_file} PROPERTIES COMPILE_FLAGS "${CUDA_NVCC_FLAGS}")
if(DEFINED SIMD_FLAGS_LIST)
nvcc_add_compiler_options_list("${SIMD_FLAGS_LIST}" SIMD_FLAGS)
set_source_files_properties(${SIMD_SOURCE_FILE} PROPERTIES COMPILE_FLAGS "${CUDA_NVCC_FLAGS} ${SIMD_FLAGS}")
endif()
if(${is_exec})
add_executable(${target} ${src_file} ${SIMD_SOURCE_FILE})
else()
add_library(${target} ${src_file} ${SIMD_SOURCE_FILE})
endif()
target_link_libraries(${target} ${AER_LIBRARIES})
string(STRIP ${AER_COMPILER_FLAGS} AER_COMPILER_FLAGS_STRIPPED)
nvcc_add_compiler_options(${AER_COMPILER_FLAGS_STRIPPED} AER_COMPILER_FLAGS_OUT)

set_target_properties(${target} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 14
COMPILE_FLAGS ${AER_COMPILER_FLAGS_OUT}
LINK_FLAGS ${AER_LINKER_FLAGS}
RUNTIME_OUTPUT_DIRECTORY_DEBUG Debug
RUNTIME_OUTPUT_DIRECTORY_RELEASE Release)
endfunction()

function(build_rocm target src_file is_exec)
# ROCm is only supported in x86_64 devices so it should be safe to leverage AVX2.
set(SIMD_SOURCE_FILE "${PROJECT_SOURCE_DIR}/src/simulators/statevector/qv_avx2.cpp")

set_source_files_properties(
${SIMD_SOURCE_FILE}
${src_file}
PROPERTIES LANGUAGE CXX)

if(${is_exec})
add_executable(${target} ${src_file} ${SIMD_SOURCE_FILE})
else()
add_library(${target} ${src_file} ${SIMD_SOURCE_FILE})
endif()

target_compile_options(${target} PRIVATE ${ROCM_EXTRA_FLAGS} ${SIMD_FLAGS_LIST})
target_compile_definitions(${target} PRIVATE ${ROCM_EXTRA_DEFS} ${AER_COMPILER_DEFINITIONS})

target_link_libraries(${target} PRIVATE ${AER_LIBRARIES})

set_target_properties(${target} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 14
COMPILE_FLAGS ${AER_COMPILER_FLAGS}
LINK_FLAGS ${AER_LINKER_FLAGS}
RUNTIME_OUTPUT_DIRECTORY_DEBUG Debug
RUNTIME_OUTPUT_DIRECTORY_RELEASE Release)
endfunction()

function(build_cpu target src_file is_exec)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64")
if (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
# We build SIMD filed separately, because they will be reached only if the
# machine running the code has SIMD support
set(SIMD_SOURCE_FILE "${PROJECT_SOURCE_DIR}/src/simulators/statevector/qv_avx2.cpp")
endif()
endif()
string(REPLACE ";" " " SIMD_FLAGS "${SIMD_FLAGS_LIST}")
set_source_files_properties(${SIMD_SOURCE_FILE} PROPERTIES COMPILE_FLAGS "${SIMD_FLAGS}")
if(${is_exec})
add_executable(${target} ${src_file} ${SIMD_SOURCE_FILE})
else()
add_library(${target} SHARED ${src_file} ${SIMD_SOURCE_FILE})
endif()
target_link_libraries(${target} PRIVATE ${AER_LIBRARIES})
set_target_properties(${target} PROPERTIES
LINKER_LANGUAGE CXX
CXX_STANDARD 14
COMPILE_FLAGS ${AER_COMPILER_FLAGS}
LINK_FLAGS ${AER_LINKER_FLAGS}
RUNTIME_OUTPUT_DIRECTORY_DEBUG Debug
RUNTIME_OUTPUT_DIRECTORY_RELEASE Release)

target_include_directories(${target}
PRIVATE ${AER_SIMULATOR_CPP_SRC_DIR}
PRIVATE ${AER_SIMULATOR_CPP_EXTERNAL_LIBS})
target_compile_definitions(${target}
PRIVATE ${AER_COMPILER_DEFINITIONS})
if(WIN32 AND NOT AER_BLAS_LIB_PATH)
add_custom_command(TARGET ${target} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different
${BACKEND_REDIST_DEPS}
$<TARGET_FILE_DIR:${target}>)
install(FILES ${BACKEND_REDIST_DEPS} DESTINATION bin)
endif()
endfunction()

# build qasm_simulator
set(AER_SIMULATOR_SOURCE "${PROJECT_SOURCE_DIR}/contrib/standalone/qasm_simulator.cpp")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
if(CUDA_FOUND AND AER_THRUST_BACKEND STREQUAL "CUDA")
build_cuda(qasm_simulator ${AER_SIMULATOR_SOURCE} TRUE)
elseif(HIP_FOUND AND AER_THRUST_BACKEND STREQUAL "ROCM")
build_rocm(qasm_simulator ${AER_SIMULATOR_SOURCE} TRUE)
else()
build_cpu(qasm_simulator ${AER_SIMULATOR_SOURCE} TRUE)
endif()

install(TARGETS qasm_simulator DESTINATION bin)
add_subdirectory(qiskit_aer/backends/wrappers)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(AER_RUNTIME_SOURCE "${PROJECT_SOURCE_DIR}/contrib/runtime/aer_runtime.cpp")
if(CUDA_FOUND AND AER_THRUST_BACKEND STREQUAL "CUDA")
build_cuda(aer ${AER_RUNTIME_SOURCE} FALSE)
elseif(HIP_FOUND AND AER_THRUST_BACKEND STREQUAL "ROCM")
build_rocm(aer ${AER_RUNTIME_SOURCE} FALSE)
else()
build_cpu(aer ${AER_RUNTIME_SOURCE} FALSE)
endif()
install(TARGETS aer)

# Tests
if(BUILD_TESTS AND NOT AER_MPI)
add_executable(test_libaer "${PROJECT_SOURCE_DIR}/test/runtime/runtime_sample.c")
target_include_directories(test_libaer PUBLIC "${PROJECT_SOURCE_DIR}/contrib/runtime/")
# AER_LINKER_FLAGS carry eventual OpenMP linking flags.
set_target_properties(test_libaer PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE bin
LINK_FLAGS ${AER_LINKER_FLAGS})
target_link_libraries(test_libaer PRIVATE ${AER_LIBRARIES})
target_link_libraries(test_libaer PRIVATE aer)
add_test(NAME aer_runtime_test COMMAND bin/test_libaer)
endif()
endif()

endif()

# Tests
if(BUILD_TESTS)
add_subdirectory(test)
endif()
Loading

0 comments on commit ad34ede

Please sign in to comment.