Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: Switch from aomp to clang for amd #2058

Merged
merged 5 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions .github/workflows/pytest-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
pytest-gpu-acc-nvidia,
pytest-gpu-omp-amd
]
test_examples: ["examples/seismic/tti/tti_example.py examples/seismic/acoustic/acoustic_example.py examples/seismic/viscoacoustic/viscoacoustic_example.py examples/seismic/viscoelastic/viscoelastic_example.py examples/seismic/elastic/elastic_example.py"]

include:
- name: pytest-gpu-omp-nvidia
test_files: "tests/test_adjoint.py tests/test_gpu_common.py tests/test_gpu_openmp.py"
FabioLuporini marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -62,9 +64,7 @@ jobs:
flags: '--gpus all --rm --name testrun-nvc'

- name: pytest-gpu-omp-amd
# We only test the OpenMP generation due to issue with the offloading discussed in
# https://github.com/ROCm-Developer-Tools/aomp/issues/397
test_files: "tests/test_gpu_openmp.py"
test_files: "tests/test_adjoint.py tests/test_gpu_common.py tests/test_gpu_openmp.py"
tags: ["self-hosted", "amdgpu"]
base: "devitocodes/bases:amd"
test_drive_cmd: "rocm-smi"
Expand Down Expand Up @@ -93,17 +93,8 @@ jobs:

- name: Test examples
run: |
docker run ${{ matrix.flags }} ${{ matrix.name }} pytest examples/seismic/acoustic/acoustic_example.py
docker run ${{ matrix.flags }} ${{ matrix.name }} pytest examples/seismic/elastic/elastic_example.py
docker run ${{ matrix.flags }} ${{ matrix.name }} pytest examples/seismic/tti/tti_example.py
docker run ${{ matrix.flags }} ${{ matrix.name }} pytest examples/seismic/viscoacoustic/viscoacoustic_example.py
docker run ${{ matrix.flags }} ${{ matrix.name }} pytest examples/seismic/viscoelastic/viscoelastic_example.py
docker run ${{ matrix.flags }} ${{ matrix.name }} pytest ${{ matrix.test_examples }}

- name: Test examples with MPI
if: matrix.name != 'pytest-gpu-omp-amd'
run: |
docker run ${{ matrix.flags }} --env DEVITO_MPI=1 ${{ matrix.name }} mpirun -n 2 pytest examples/seismic/acoustic/acoustic_example.py
docker run ${{ matrix.flags }} --env DEVITO_MPI=1 ${{ matrix.name }} mpirun -n 2 pytest examples/seismic/elastic/elastic_example.py
docker run ${{ matrix.flags }} --env DEVITO_MPI=1 ${{ matrix.name }} mpirun -n 2 pytest examples/seismic/tti/tti_example.py
docker run ${{ matrix.flags }} --env DEVITO_MPI=1 ${{ matrix.name }} mpirun -n 2 pytest examples/seismic/viscoacoustic/viscoacoustic_example.py
docker run ${{ matrix.flags }} --env DEVITO_MPI=1 ${{ matrix.name }} mpirun -n 2 pytest examples/seismic/viscoelastic/viscoelastic_example.py
docker run ${{ matrix.flags }} --env DEVITO_MPI=1 ${{ matrix.name }} mpiexec -n 2 pytest ${{ matrix.test_examples }}
7 changes: 6 additions & 1 deletion .github/workflows/tutorials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ jobs:

- name: Seismic notebooks
run: |
${{ env.RUN_CMD }} py.test --nbval -k 'not dask' examples/seismic/tutorials/ # Horrible, but we're still at a loss
${{ env.RUN_CMD }} py.test --nbval -k 'not dask' -k 'not synthetics' examples/seismic/tutorials/
${{ env.RUN_CMD }} py.test --nbval examples/seismic/acoustic/accuracy.ipynb

- name: Failing notebooks
continue-on-error: true
run: |
${{ env.RUN_CMD }} py.test --nbval examples/seismic/tutorials/14_creating_synthetics.ipynb

- name: Dask notebooks
if: runner.os != 'macOS'
run: |
Expand Down
16 changes: 7 additions & 9 deletions devito/arch/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,15 @@ def __init__(self, *args, **kwargs):
else:
self.cflags.append('-march=native')

# For MPI, mpicc is compiled against amdclang not aompcc, so need the flags back.
if kwargs.get('mpi'):
self.ldflags.extend(['-target', 'x86_64-pc-linux-gnu'])
self.ldflags.extend(['-fopenmp',
'-fopenmp-targets=amdgcn-amd-amdhsa',
'-Xopenmp-target=amdgcn-amd-amdhsa'])
self.ldflags.append('-march=%s' % platform.march)
# amdclang flags, used to be part of aompcc
self.ldflags.extend(['-target', 'x86_64-pc-linux-gnu'])
self.ldflags.extend(['-fopenmp', '-fopenmp-targets=amdgcn-amd-amdhsa',
'-Xopenmp-target=amdgcn-amd-amdhsa'])
self.ldflags.append('-march=%s' % platform.march)

def __lookup_cmds__(self):
self.CC = 'aompcc'
self.CXX = 'aompcc'
self.CC = 'amdclang'
self.CXX = 'amdclang++'
self.MPICC = 'mpicc'
self.MPICXX = 'mpicxx'

Expand Down
29 changes: 22 additions & 7 deletions docker/Dockerfile.amd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ ENV ROCM_HOME /opt/rocm
ENV HIP_HOME $ROCM_HOME/hip

# Some utils needed
RUN apt-get update && apt-get install -y wget git autoconf dh-autoreconf flex python3-venv python3-dev vim libnuma1 tmux
RUN apt-get update && \
apt-get install -y wget git autoconf dh-autoreconf flex \
python3-venv python3-dev \
vim libnuma-dev tmux numactl

# Install tmpi
RUN curl https://raw.githubusercontent.com/Azrael3000/tmpi/master/tmpi -o /usr/local/bin/tmpi
Expand All @@ -25,11 +28,12 @@ RUN curl https://raw.githubusercontent.com/Azrael3000/tmpi/master/tmpi -o /usr/l
# https://github.com/ROCmSoftwarePlatform/rocHPCG/blob/develop/install.sh
# UCX. Clang does not support some of the flags such as '-dynamic-list-data' so build UCX with gcc
RUN mkdir -p /deps && mkdir -p /opt/ucx && cd /deps && \
git clone --branch v1.11.x https://github.com/openucx/ucx.git ucx && \
git clone --branch v1.13.0 https://github.com/openucx/ucx.git ucx && \
cd ucx && ./autogen.sh && \
mkdir build && cd build && \
../contrib/configure-opt --prefix=/opt/ucx/ --with-rocm=${with_rocm} \
--without-knem --without-cuda --without-java \
../contrib/configure-release --prefix=/opt/ucx/ --with-rocm=${with_rocm} \
--without-cuda --without-java \
--disable-params-check --disable-logging --disable-assertions --disable-debug \
--enable-optimizations && \
make -j $(( $(lscpu | awk '/^Socket\(s\)/{ print $2 }') * $(lscpu | awk '/^Core\(s\) per socket/{ print $4 }') )) && \
make install && \
Expand All @@ -38,10 +42,10 @@ RUN mkdir -p /deps && mkdir -p /opt/ucx && cd /deps && \
# OpenMPI
# Build OpenMPI with `amdclang` so that `mpicc` links to the correct compiler
RUN mkdir -p /opt/openmpi && cd /deps && \
git clone --branch v4.1.x https://github.com/open-mpi/ompi.git openmpi && \
git clone --recursive --branch v4.1.4 https://github.com/open-mpi/ompi.git openmpi && \
cd openmpi && ./autogen.pl && \
mkdir build && cd build && \
../configure CC=$AOMP/bin/clang CXX=$AOMP/bin/clang++ FC=$AOMP/bin/flang \
../configure CC=$AOMP/bin/amdclang CXX=$AOMP/bin/amdclang++ FC=$AOMP/bin/amdflang \
--prefix=/opt/openmpi/ --with-ucx=/opt/ucx \
--enable-mca-no-build=btl-uct --enable-mpi1-compatibility && \
make -j $(( $(lscpu | awk '/^Socket\(s\)/{ print $2 }') * $(lscpu | awk '/^Core\(s\) per socket/{ print $4 }') )) && \
Expand All @@ -51,7 +55,18 @@ RUN mkdir -p /opt/openmpi && cd /deps && \
# Set OpenMPI path
ENV PATH=${PATH}:/opt/openmpi/bin:$AOMP/bin
ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/opt/openmpi/lib:$AOMP/lib
ENV OMPI_CC=$AOMP/bin/clang
ENV OMPI_CC=$AOMP/bin/amdclang
ENV OMPI_CXX=$AOMP/bin/amdclang++
ENV OMPI_F90=$AOMP/bin/flan

# Set mpiexec flags for gpu aware mpi
RUN echo "--mca btl '^openib' -x UCX_TLS=sm,self,rocm_copy,rocm_ipc --mca pml ucx" > /opt/openmpi/etc/mpiexec.conf

# Build mpi4py against amdclang
RUN python3 -m venv /venv && \
/venv/bin/pip install --no-cache-dir --upgrade pip && \
CC=$AOMP/bin/amdclang CXX=$AOMP/bin/amdclang++ /venv/bin/pip install --no-cache-dir mpi4py && \
rm -rf ~/.cache/pip

########################################################################
# AOMP for GPUs (OpenMP offloading)
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ FROM ${pyversion} as base
ENV DEBIAN_FRONTEND noninteractive

# Install for basic base not containing it
RUN apt-get update && apt-get install -y vim wget git libnuma1 tmux
RUN apt-get update && apt-get install -y vim wget git libnuma-dev tmux numactl

# Install tmpi
RUN curl https://raw.githubusercontent.com/Azrael3000/tmpi/master/tmpi -o /usr/local/bin/tmpi
Expand All @@ -24,7 +24,7 @@ RUN apt-get install -y libgl1-mesa-glx
##############################################################
FROM base as gcc

RUN apt-get install -y mpich libmpich-dev
RUN apt-get install -y mpich libmpich-dev
mloubout marked this conversation as resolved.
Show resolved Hide resolved
# Env vars defaults
ENV DEVITO_ARCH="gcc"
ENV DEVITO_LANGUAGE="openmp"
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile.nvidia
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ FROM ${pyversion}-slim-bullseye as sdk-base

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update -y && apt-get install -y -q gpg apt-utils curl wget vim libnuma1 tmux
RUN apt-get update -y && apt-get install -y -q gpg apt-utils curl wget vim libnuma-dev tmux numactl

# nodesource: nvdashboard requires nodejs>=10
RUN curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | gpg --yes --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg
Expand All @@ -28,7 +28,7 @@ ARG ver=nvhpc
# install the latest nvhpc-x-y no matter which version nvhpc-x-z is requested which would double (extra 10Gb) the size of the image.
# So for specific version we directly download the specific deb and install it.
RUN if [ "$ver" = "nvhpc" ]; then \
apt-get install -y -q ${ver}; \
apt-get install -y -q --allow-unauthenticated ${ver}; \
else \
export year=$(echo $ver | cut -d "-" -f 2) && export minor=$(echo $ver | cut -d "-" -f 3) && \
wget https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64/nvhpc-20${year}_${year}.${minor}_amd64.deb && \
Expand Down
3 changes: 0 additions & 3 deletions tests/test_gpu_openmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def test_init_omp_env(self):
assert str(op.body.init[0].body[0]) ==\
'if (deviceid != -1)\n{\n omp_set_default_device(deviceid);\n}'

@skipif('device-aomp')
@pytest.mark.parallel(mode=1)
def test_init_omp_env_w_mpi(self):
grid = Grid(shape=(3, 3, 3))
Expand Down Expand Up @@ -345,7 +344,6 @@ def test_iso_acoustic(self, opt):

class TestMPI(object):

@skipif('device-aomp')
@pytest.mark.parallel(mode=[2, 4])
def test_mpi_nocomms(self):
grid = Grid(shape=(3, 3, 3))
Expand All @@ -362,7 +360,6 @@ def test_mpi_nocomms(self):

assert np.all(np.array(u.data[0, :, :, :]) == time_steps)

@skipif('device-aomp')
@pytest.mark.parallel(mode=[2, 4])
def test_iso_ac(self):
TestOperator().iso_acoustic(opt='advanced')