From 4e1a0e47cb32c53cec2e004cf608f44b11ff4226 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Tue, 23 Jan 2024 15:41:25 +0100 Subject: [PATCH] Factorize builds --- .github/workflows/base_images.yaml | 46 +++++++ .github/workflows/cmake.yml | 186 +++++++++++------------------ docker/{nvidia => cuda}/Dockerfile | 0 docker/{amd => hip}/Dockerfile | 0 install_test/bin/install_cuda.sh | 4 +- install_test/bin/install_hip.sh | 4 +- 6 files changed, 119 insertions(+), 121 deletions(-) create mode 100644 .github/workflows/base_images.yaml rename docker/{nvidia => cuda}/Dockerfile (100%) rename docker/{amd => hip}/Dockerfile (100%) diff --git a/.github/workflows/base_images.yaml b/.github/workflows/base_images.yaml new file mode 100644 index 00000000..310ba851 --- /dev/null +++ b/.github/workflows/base_images.yaml @@ -0,0 +1,46 @@ +name: Build base images + +on: + workflow_call: + # push: + # branches: + # - main + # pull_request: + # branches: + # - main + # schedule: + # # TODO enable scheduler + # cron: "0 1 2,16 * *" # every 2nd and 16th of the month at 1am UTC + +jobs: + build_base: + runs-on: ubuntu-latest + + strategy: + matrix: + backend: + # - openmp + - cuda + # - hip + + steps: + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@v1.2.0 + with: + tool-cache: true + large-packages: false + + - name: Checkout repository + uses: actions/checkout@v3 + + # TODO check if current build has a different Dockerfile + + - name: Build image + # TODO improve with caching https://docs.docker.com/engine/reference/commandline/image_build/#cache-from + run: docker build -t base_${{ matrix.backend }} docker/${{ matrix.backend }} + + - name: Login in GitHub Containers Repository + run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: docker push ghcr.io/cexa-project/kokkos-fft/base_${{ matrix.backend }} diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 2755d1ce..699306d1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,8 +1,9 @@ -name: CMake +name: Build and test on: pull_request: - branches: [ "main" ] + branches: + - main env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) @@ -20,128 +21,79 @@ jobs: extensions: 'hpp,cpp' clangFormatVersion: 12 - build_nvidia: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. - # You can convert this to a matrix build if you need cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: ubuntu-latest - - env: - backends: OPENMP CUDA CUDA_HOST_DEVICE - CUDA_ARCHITECTURES: AMPERE80 - CMAKE_CXX_COMPILER: /work/tpls/kokkos/bin/nvcc_wrapper - container: nvidia_env - - steps: - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@v1.2.0 - with: { tool-cache: true, large-packages: false } - - - name: Checkout built branch - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Update submodules - run: git submodule update --remote --recursive - - - name: Build docker - run: docker build -t ${{ env.container }} docker/nvidia - - - name: Configure CMake for OpenMP backend - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_OPENMP \ - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=g++ \ - -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_OPENMP=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON - - - name: Configure CMake for CUDA backend - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_CUDA \ - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \ - -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON -DKokkosFFT_INTERNAL_Kokkos=ON - - - name: Configure CMake for CUDA backend with HOST and DEVICE option - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_CUDA_HOST_DEVICE \ - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \ - -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_${{env.CUDA_ARCHITECTURES}}=ON -DBUILD_TESTING=ON \ - -DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON -DKokkosFFT_INTERNAL_Kokkos=ON - - - name: Build - # Build your program with the given configuration - run: | - for backend in ${{ env.backends }}; do - docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake --build build_${backend} --config ${{env.BUILD_TYPE}} -j 2 - done - - - name: Test for OpenMP backend - # Execute tests defined by the CMake configuration. Testing on CPUs only - run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} ctest --output-on-failure --test-dir build_OPENMP -C ${{env.BUILD_TYPE}} - - - name: Install test for OpenMP backend - run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} ./install_test/bin/install_cpu.sh /tmp + build_base: + uses: ./.github/workflows/base_images.yaml - - name: Install test for CUDA backend - run: | - for backend in ${{ env.backends }}; do - if [ ${backend} != "OPENMP" ]; then - docker run -v ${{github.workspace}}:/work ${{ env.container }} ./install_test/bin/install_cuda.sh /tmp ${backend} - fi - done - - build_amd: - # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. - # You can convert this to a matrix build if you need cross-platform coverage. - # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + build: runs-on: ubuntu-latest - env: - #backends: HIP HIP_HOST_DEVICE - architecture: VEGA90A - CMAKE_CXX_COMPILER: hipcc - container: amd_env - strategy: matrix: - backend: [ {name: HIP, option: ""}, {name: HIP_HOST_DEVICE, option: "-DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON"} ] + backend: + # - name: openmp + # cmake_flags: -DKokkos_ENABLE_OPENMP + - name: cuda + cmake_flags: -DKokkos_ENABLE_CUDA -DKokkos_ARCH_AMPERE80 + # - name: hip + # cmake_flags: -DKokkos_ENABLE_HIP -DKokkos_ARCH_VEGA90A + target: + - name: native + cmake_flags: "" + - name: host_device + cmake_flags: -DKokkosFFT_ENABLE_HOST_AND_DEVICE=ON + exclude: + - backend: + name: openmp + target: + name: host_device + + needs: + - build_base steps: - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@v1.2.0 - with: { tool-cache: true, large-packages: false } - - - name: Checkout built branch - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Update submodules - run: git submodule update --remote --recursive - - - name: Build docker - run: docker build -t ${{ env.container }} docker/amd - - - name: Configure CMake for HIP backend - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake -B build_${{matrix.backend.name}} \ - -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{env.CMAKE_CXX_COMPILER}} \ - -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_HIP=ON -DKokkosFFT_INTERNAL_Kokkos=ON -DKokkos_ARCH_${{env.architecture}}=ON -DBUILD_TESTING=ON ${{matrix.backend.option}} - - - name: Build - # Build your program with the given configuration - run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} cmake --build build_${{matrix.backend.name}} --config ${{env.BUILD_TYPE}} -j 2 + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@v1.2.0 + with: + tool-cache: true + large-packages: false + + - name: Checkout built branch + uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Login in GitHub Containers Repository + run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Pull image + run: docker pull ghcr.io/cexa-project/kokkos-fft/base_${{ matrix.backend.name }} + + - name: Configure + run: | + docker run -v ${{github.workspace}}:/work base_${{ matrix.backend.name }} \ + cmake -B build \ + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ + -DCMAKE_CXX_STANDARD=17 \ + -DBUILD_TESTING=ON \ + -DKokkosFFT_INTERNAL_Kokkos=ON \ + ${{ matrix.backend.cmake_flags }} \ + ${{ matrix.target.cmake_flags }} \ + + - name: Build + run: | + docker run -v ${{github.workspace}}:/work base_${{ matrix.backend.name }} \ + cmake --build build -j 2 + + - name: Save image + run: docker commit nvidia_base ghcr.io/cexa-project/kokkos-fft/kokkos_fft_${{ matrix.backend.name }} + + - name: Install + run: docker run -v ${{github.workspace}}:/work base_${{ matrix.backend.name }} \ + ./install_test/bin/install_${{ matrix.backend.name }}.sh /tmp ${{ matrix.backend.name }} + + - name: Push image + run: docker push ghcr.io/cexa-project/kokkos-fft/kokkos_fft_${{ matrix.backend.name }} - name: Install test for HIP backend run: | - docker run -v ${{github.workspace}}:/work ${{ env.container }} ./install_test/bin/install_hip.sh /tmp ${{matrix.backend.name}} \ No newline at end of file + docker run -v ${{github.workspace}}:/work ${{ env.container }} ./install_test/bin/install_hip.sh /tmp ${{matrix.target.name}} diff --git a/docker/nvidia/Dockerfile b/docker/cuda/Dockerfile similarity index 100% rename from docker/nvidia/Dockerfile rename to docker/cuda/Dockerfile diff --git a/docker/amd/Dockerfile b/docker/hip/Dockerfile similarity index 100% rename from docker/amd/Dockerfile rename to docker/hip/Dockerfile diff --git a/install_test/bin/install_cuda.sh b/install_test/bin/install_cuda.sh index 7efaf85f..4ea77d8f 100755 --- a/install_test/bin/install_cuda.sh +++ b/install_test/bin/install_cuda.sh @@ -36,7 +36,7 @@ fi # Install KokkosFFT cd ${WK_DIR} mkdir ${KOKKOSFFT_BUILD_DIR} && cd ${KOKKOSFFT_BUILD_DIR} -if [ $TARGET == "CUDA" ]; then +if [ $TARGET == "native" ]; then cmake -DCMAKE_CXX_COMPILER=${CXX_COMPILER} \ -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_CUDA=ON -DKokkos_ARCH_AMPERE80=ON \ -DCMAKE_INSTALL_PREFIX=${KOKKOSFFT_INSTALL_PREFIX} .. @@ -61,4 +61,4 @@ if [ $? -eq 0 ]; then else echo "*** install test: build FAILED ***" exit 1; -fi \ No newline at end of file +fi diff --git a/install_test/bin/install_hip.sh b/install_test/bin/install_hip.sh index 01e8c9fc..8796ab41 100755 --- a/install_test/bin/install_hip.sh +++ b/install_test/bin/install_hip.sh @@ -35,7 +35,7 @@ fi # Install KokkosFFT cd ${WK_DIR} mkdir ${KOKKOSFFT_BUILD_DIR} && cd ${KOKKOSFFT_BUILD_DIR} -if [ $TARGET == "HIP" ]; then +if [ $TARGET == "native" ]; then cmake -DCMAKE_CXX_COMPILER=hipcc \ -DCMAKE_CXX_STANDARD=17 -DKokkos_ENABLE_HIP=ON -DKokkos_ARCH_VEGA90A=ON \ -DCMAKE_INSTALL_PREFIX=${KOKKOSFFT_INSTALL_PREFIX} .. @@ -61,4 +61,4 @@ if [ $? -eq 0 ]; then else echo "*** install test: build FAILED ***" exit 1; -fi \ No newline at end of file +fi