Qiskit-aer is high-performance quantum computing simulators and ROCm is the computing platform for AMD GPUs like Radeon and Instinct.
As you know, the most powerful and prevalent GPU framework for numerical computation purposes today is NVIDIA CUDA, and AMD has been slow to develop software stacks for that application.
Qiskit-aer's GPU support is available through the cuQuantum library and its own implementation. The cuQuantum library can only run on NVIDIA GPUs. However, Qiskit-aer's own implementation can run on AMD GPUs.
First, we prepare a clone of Qiskit-aer.
git clone https://github.com/Qiskit/qiskit-aer.git
We use Podman, which has a different architecture than Docker, but is used in much the same way. If you are not familiar with it, you may use Docker. Rye is a Python package manager.
FROM rocm/rocm-terminal:latest
ARG UID=1000
ARG GID=1000
RUN sudo apt update && \
sudo apt install -y cmake libspdlog-dev libopenblas-dev python3-dev mpich ninja-build rocblas rocthrust && \
sudo mkdir /work && \
sudo chown $UID:$GID /work
USER $UID
WORKDIR /work
RUN curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash
COPY build.sh /work
CMD ["bash", "/work/build.sh"]
And, we prepare build script.
#!/bin/bash
PY_VERSION=3.11
# Change to workdir
cd /work
# Make and activate Python environment
source $HOME/.rye/env
rye init --virtual .
rye pin $PY_VERSION
rye add pybind11 scikit-build setuptools wheel
rye add "conan<2.0.0"
rye sync
. .venv/bin/activate
# Build qiskit-aer
cd /work/qiskit-aer
# You can add ROCm architecture to edit `-DAER_ROCM_ARCH=...`
# You can disable MPI to remove `-DAER_MPI=ON`
QISKIT_AER_PACKAGE_NAME='qiskit-aer-gpu-rocm' python3 setup.py bdist_wheel -- \
-DCPPFLAGS+=-I.venv/lib/python${PY_VERSION}/site-packages/pybind11/include/ \
-DAER_THRUST_BACKEND=ROCM -DAER_MPI=ON -DAER_ROCM_ARCH=gfx1101
Then, we run podman.
podman build . -t qiskit-aer-rocm
podman run -it --rm -v $PWD/qiskit-aer:/work/qiskit-aer --userns=keep-id qiskit-aer-rocm
Compiled binary file is created as wheel file in qiskit-aer/dist
directory.
Install a wheel.
pip install qiskit-aer/dist/qiskit_aer_gpu_rocm-0.15.0-cp311-cp311-linux_x86_64.whl
Run GPU simulator.
gpusim = AerSimulator(method='statevector', device='GPU')
circ = transpile(QuantumVolume(25, 25, seed=0), basis_gates=["rz", "sx", "ecr"])
circ.measure_all()
result = gpusim.run(circ, shots=10000).result()
The results are posted on benchmark.ipynb. In this result, GPU is 8x faster than CPU.
I am trying to compile it using your instruction (but without podman because I keep getting some errors), I was able to create the wheel but then I get:
Any idea on what it may be caused by?
I am using a condo env on python 3.11.11