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

CI/CD with Github Actions #14

Merged
merged 5 commits into from
Mar 4, 2025
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
266 changes: 266 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
name: Build mfaktc software

on:
push:
pull_request:
workflow_dispatch:

jobs:
# Begin job "build-linux"
build-linux:
runs-on: ubuntu-latest

strategy:
# When fail-fast set to true, if one job fails, all others within the same
# matrix (i.e. Linux or Windows builds) will be aborted at the same time.
fail-fast: false

matrix:
sys:
# Specified version combination must exist as CUDA container image from NVidia: nvcr.io/nvidia/cuda:${{ matrix.sys.cuda_version }}-devel-${{ matrix.sys.ct_os }}
# Available versions can be found here: https://catalog.ngc.nvidia.com/orgs/nvidia/containers/cuda/tags (note that only Ubuntus are supported by this action)
- { cuda_version: '12.8.0', ct_os: 'ubuntu24.04' }
- { cuda_version: '12.6.3', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.6.2', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.6.1', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.6.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '12.5.1', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.5.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '12.4.1', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.4.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '12.3.2', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.3.1', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.3.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '12.2.2', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.2.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '12.1.1', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.1.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '12.0.1', ct_os: 'ubuntu22.04' }
# - { cuda_version: '12.0.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '11.8.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '11.7.1', ct_os: 'ubuntu22.04' }
# - { cuda_version: '11.7.0', ct_os: 'ubuntu22.04' }
- { cuda_version: '11.6.2', ct_os: 'ubuntu20.04' }
# - { cuda_version: '11.6.1', ct_os: 'ubuntu20.04' }
# - { cuda_version: '11.6.0', ct_os: 'ubuntu20.04' }
- { cuda_version: '11.5.2', ct_os: 'ubuntu20.04' }
# - { cuda_version: '11.5.1', ct_os: 'ubuntu20.04' }
# - { cuda_version: '11.5.0', ct_os: 'ubuntu20.04' }
- { cuda_version: '11.4.3', ct_os: 'ubuntu20.04' }
- { cuda_version: '11.3.1', ct_os: 'ubuntu20.04' }
- { cuda_version: '11.2.2', ct_os: 'ubuntu20.04' }
- { cuda_version: '11.1.1', ct_os: 'ubuntu20.04' }
- { cuda_version: '11.0.3', ct_os: 'ubuntu20.04' }
- { cuda_version: '10.2', ct_os: 'ubuntu18.04' }
- { cuda_version: '9.2', ct_os: 'ubuntu18.04' }
- { cuda_version: '8.0', ct_os: 'ubuntu16.04' }

env:
# We can't use GitHub direct container support on old Ubuntu versions, because actions will fail running from these due to old glibc version.
# As a workaround, Docker containers will be launched separately, running build related actions inside the container via 'docker exec', while generic actions will run on the
# host runner VM itself.
CONTAINER: "nvcr.io/nvidia/cuda:${{ matrix.sys.cuda_version }}-devel-${{ matrix.sys.ct_os }}"
base_name: mfaktc-${{ github.ref_name }}-linux64-cuda${{ matrix.sys.cuda_version }}

steps:

- name: Start Docker Container
run: |
docker pull $CONTAINER
docker run --name build-container -d -v ${{ github.workspace }}:/workspace $CONTAINER tail -f /dev/null

- name: Fix GPG keys for NVidia repo on Ubuntu 16.04
if: matrix.sys.ct_os == 'ubuntu16.04'
env:
SCRIPT: apt-key add /workspace/3bf863cc.pub
run: |
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/3bf863cc.pub
docker exec build-container bash -c "$SCRIPT"

- name: Update & install required packages inside the container
id: packages
env:
SCRIPT: |
apt-get update
apt-get -y full-upgrade
apt-get install -y build-essential curl git make python3 sudo unzip wget zip
run: docker exec build-container bash -c "$SCRIPT"

- name: Checkout repo
uses: actions/checkout@v4

- name: Prepare sources and gather info
id: prepare
env:
SCRIPT: |
cd /workspace
bash .github/workflows/scripts/build_helper.sh ${{ matrix.sys.cuda_version }}
run: |
docker exec build-container bash -c "$SCRIPT"
cat .github/workflows/scripts/build_helper.sh.out >> $GITHUB_OUTPUT

- name: Build from sources
env:
SCRIPT: cd /workspace/src && make -j$(nproc)
run: docker exec build-container bash -c "$SCRIPT"

- name: Prepare zip archive with the description
env:
SCRIPT: |
cd /workspace
zip -9 -j ${{ env.base_name }}.zip *
echo "[${{ env.base_name }}.zip](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ env.base_name }}.zip) | \
${{ matrix.sys.cuda_version }} | ${{ steps.prepare.outputs.CC_MIN }}-${{ steps.prepare.outputs.CC_MAX }} | ${{ steps.prepare.outputs.OS_VER }} | \
${{ steps.prepare.outputs.COMPILER_VER }} | ${{ steps.prepare.outputs.NVCC_VER }}" > ${{ env.base_name }}.txt
run: docker exec build-container bash -c "$SCRIPT"

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.base_name }}
path: ${{ env.base_name }}.*
# End job "build-linux"

# Begin job "build-win"
build-win:
runs-on: ${{ matrix.sys.os }}

strategy:
# When fail-fast set to true, if one job fails, all others within the same
# matrix (i.e. Linux or Windows builds) will be aborted at the same time.
fail-fast: false

matrix:
# Available version can be viewed at the Jimver/cuda-toolkit action sources:
# https://github.com/Jimver/cuda-toolkit/blob/v0.2.21/src/links/windows-links.ts
sys:
- { cuda_version: '12.8.0', os: 'windows-2022' }
- { cuda_version: '12.6.3', os: 'windows-2022' }
- { cuda_version: '12.5.1', os: 'windows-2022' }
- { cuda_version: '12.4.1', os: 'windows-2022' }
- { cuda_version: '12.3.2', os: 'windows-2022' }
- { cuda_version: '12.2.2', os: 'windows-2022' }
- { cuda_version: '12.1.1', os: 'windows-2022' }
- { cuda_version: '12.0.1', os: 'windows-2022' }
- { cuda_version: '11.8.0', os: 'windows-2022' }
- { cuda_version: '11.7.1', os: 'windows-2022' }
- { cuda_version: '11.6.2', os: 'windows-2022' }
- { cuda_version: '11.5.2', os: 'windows-2022' }
- { cuda_version: '11.4.4', os: 'windows-2022' }
- { cuda_version: '11.3.1', os: 'windows-2022' }
- { cuda_version: '11.2.2', os: 'windows-2019' }
- { cuda_version: '11.1.1', os: 'windows-2019' }
- { cuda_version: '11.0.1', os: 'windows-2019' }
- { cuda_version: '10.0.130', os: 'windows-2019' }
- { cuda_version: '9.2.148', os: 'windows-2019' }
- { cuda_version: '8.0.61', os: 'windows-2019' }

env:
base_name: mfaktc-${{ github.ref_name }}-win64-cuda${{ matrix.sys.cuda_version }}

steps:

- name: Checkout repo
uses: actions/checkout@v4

- name: Installing CUDA Toolkit
id: cuda-toolkit
uses: Jimver/[email protected]
with:
cuda: ${{ matrix.sys.cuda_version }}
sub-packages: ${{ startsWith(matrix.sys.cuda_version, '8.') && '[]' || '[ "nvcc", "cudart" ]' }}

- name: Add CUDA bin dir to PATH
shell: powershell
run: |
[System.Environment]::SetEnvironmentVariable('PATH', "$env:CUDA_PATH\bin;$env:PATH", 'User')

- name: Prepare sources and gather info
id: prepare
shell: bash
run: |
bash .github/workflows/scripts/build_helper.sh ${{ matrix.sys.cuda_version }}
cat .github/workflows/scripts/build_helper.sh.out >> $GITHUB_OUTPUT

# MSVC 2022 installed on Windows 2022 Github Runner has PowerShell script for a Dev Shell.
- name: Build from sources (PowerShell with MSVC 2022)
if: ${{ matrix.sys.os == 'windows-2022' }}
shell: powershell
run: |
& 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Launch-VsDevShell.ps1' -Arch amd64 -HostArch amd64
cd "${{ github.workspace }}\src"
Copy-Item mfaktc.ini ..
make SHELL="powershell.exe" -f Makefile.win

# MSVC 2019 on Windows 2019 has similar script, but it doesn't allows setting arch & host_arch and defaults to x86 (32 bit) env.
# So we have to run bat file for the env, but Make uses PowerShell afterward because it's much better at handling long paths &
# quotes when invoked from Make.
# -vcvars_ver=14.0 switch enables MSVC 14.0 (2015) build environment. It's a component of MSVC 2019, not a complete MSVC instance.
- name: Build from sources (cmd.exe with MSVC 2019)
if: ${{ matrix.sys.os == 'windows-2019' }}
shell: cmd
run: |
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" x64 ${{ env.VCVARS_VER }} & cd src & copy mfaktc.ini .. & make SHELL="powershell.exe" -f Makefile.win
env:
VCVARS_VER: ${{ steps.prepare.outputs.CUDA_VER_MAJOR <= 10 && '-vcvars_ver=14.0' || '' }}

- name: Prepare build archive with description
shell: bash
run: |
choco install -y --no-progress zip
zip -9 -j "${{ env.base_name }}.zip" *
echo "[${{ env.base_name }}.zip](https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ env.base_name }}.zip) | \
${{ matrix.sys.cuda_version }} | ${{ steps.prepare.outputs.CC_MIN }}-${{ steps.prepare.outputs.CC_MAX }} | ${{ steps.prepare.outputs.OS_VER }} | \
${{ steps.prepare.outputs.COMPILER_VER }} | ${{ steps.prepare.outputs.NVCC_VER }}" > ${{ env.base_name }}.txt

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.base_name }}
path: ${{ env.base_name }}.*
# End job "build-win"

# Begin job "upload-release"
upload-release:
if: startsWith(github.ref, 'refs/tags/')
needs: [ build-linux, build-win ]
runs-on: ubuntu-latest

permissions:
contents: write

steps:

- name: Download artifacts
uses: actions/download-artifact@v4

- name: Prepare list of release files & release notes
id: makeinfo
run: |
{
echo "Binary releases (automated builds) below."
echo "Compute Capability (CC) in the table means minimum and maximum versions supported."
echo "CC versions are listed without the dot (i.e. 90 means 9.0 compute capability)."
echo
echo "File | CUDA version | Compute Capability | Build OS | Compiler version | NVCC version"
echo "--- | --- | --- | --- | --- | ---"
sort -Vr mfaktc-${{ github.ref_name }}-*-cuda*/mfaktc-${{ github.ref_name }}-*-cuda*.txt
} > RELEASE_NOTES.txt
{
echo 'RELEASE_FILES<<EOF'
printf '%s\n' mfaktc-${{ github.ref_name }}-*-cuda*/mfaktc-${{ github.ref_name }}-*-cuda*.zip | sort -Vr
echo 'EOF'
} > $GITHUB_OUTPUT

- name: Make and upload release
uses: softprops/[email protected]
with:
fail_on_unmatched_files: false
files: |
${{ steps.makeinfo.outputs.RELEASE_FILES }}
preserve_order: true
generate_release_notes: true
body_path: RELEASE_NOTES.txt
make_latest: true
# End job "upload-release"
# SPDX-License-Identifier: GPL-3.0-or-later
105 changes: 105 additions & 0 deletions .github/workflows/scripts/build_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
#
# build_helper.sh
# This script are used by the CI/CD builds with Github Actions workflow.
# It gathers some info on software versions and saves it to file
# build_helper.sh.out which are later used by the actions workflow.
# It also patches Makefiles to support building under Github Action
# runners environment and compile kernels for every compute capability
# device supported by the NVCC.
#
# Copyright (c) 2025 NStorm (https://github.com/N-Storm/)
# This file is part of mfaktc.
# Copyright (C) 2009, 2010, 2011 Oliver Weihe ([email protected])
#
# mfaktc is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# mfaktc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mfaktc. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

if [[ -z "$1" ]]; then
echo "Usage: $0 <CUDA version>" >&2
exit 1
fi

# Windows may have it's sort first on PATH, this is the shortcut
# to call GNU sort by the full path
export GSORT='/usr/bin/sort'

declare -a CUDA_VERSION
CUDA_VERSION=( $(echo "$1" | head -n1 | grep -Eom1 -e '^[1-9]([0-9])?\.[0-9]{1,2}(\.[0-9]{1,3})?$' | tr '.' ' ') )
if [[ -z "${CUDA_VERSION[*]}" ]]; then
echo "ERROR! Can't parse CUDA version $1" >&2
exit 2
fi

CUDA_VER_MAJOR=${CUDA_VERSION[0]}
CUDA_VER_MINOR=${CUDA_VERSION[1]}
CUDA_VER="${CUDA_VER_MAJOR}${CUDA_VER_MINOR}"
echo -e "CUDA_VER_MAJOR=${CUDA_VER_MAJOR}\nCUDA_VER_MINOR=${CUDA_VER_MINOR}" > "$0.out"

# Starting from 11.0.0 CUDA has --list-gpu-arch flag.
# For older versions we have to grep out supported CC versions from help.
[ $CUDA_VER -gt 110 ] && NVCC_OPTS='--list-gpu-arch' || NVCC_OPTS='--help'
NVCC_REGEX='compute_[1-9][0-9]{1,2}'
# Special case with CUDA 11.0.x. It's help lists compute_32 and higher, but only CCs from 35 are supported.
[ $CUDA_VER -eq 110 ] && NVCC_REGEX='compute_(3[5-9]|[4-9][0-9])'

declare -a CC_LIST
CC_LIST=( $(nvcc $NVCC_OPTS | grep -Eoe "$NVCC_REGEX" | cut -d '_' -f2 | $GSORT -un | xargs) )
if [ ${#CC_LIST[*]} -eq 0 ]; then
echo "ERROR! Unable to parse a list of CCs" >&2
exit 3
elif [ ${#CC_LIST[*]} -lt 3 ]; then
echo "WARN Number of supported CC versions less than 3" >&2
fi

echo "All supported CCs: ${CC_LIST[*]}, CC_MIN=${CC_LIST[0]}, CC_MAX=${CC_LIST[-1]}"
echo -e "CC_LIST=\"${CC_LIST[*]}\"\nCC_MIN=${CC_LIST[0]}\nCC_MAX=${CC_LIST[-1]}" >> "$0.out"

echo 'Removing NVCCFLAGS strings with CC arch entries from the Makefile & Makefile.win and populating with discovered supported values.'
sed -i '/^NVCCFLAGS += --generate-code arch=compute.*/d' src/Makefile.win src/Makefile
for CC in "${CC_LIST[@]}"; do
sed -i "/^NVCCFLAGS = .*\$/a NVCCFLAGS += --generate-code arch=compute_${CC},code=sm_${CC}" src/Makefile src/Makefile.win
done

if [ $CUDA_VER -ge 110 ]; then
echo 'Adding NVCCFLAGS to allow unsupported MSVC compiler versions...'
sed -i '/^NVCCFLAGS = .*/a NVCCFLAGS += -allow-unsupported-compiler -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH' src/Makefile.win
fi
if [ $CUDA_VER -lt 120 ]; then
echo "Adding libraries to LDFLAGS to support static build on older Ubuntu versions..."
sed -i -E 's/^(LDFLAGS = .*? -lcudart_static) (.*)/\1 -ldl -lrt -lpthread \2/' src/Makefile
fi

echo 'Gathering version info on generic compiler and nvcc...'
if [[ -x "$(command -v vswhere.exe)" ]]; then
CC_VSPROD="$(vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property displayName)"
COMPILER_VER="${CC_VSPROD}, $(vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion)"
elif [[ -x "$(command -v powershell.exe)" ]]; then
CC_VSINFO="$(powershell -Command Get-VSSetupInstance)"
CC_VSPROD="$(echo "$CC_VSINFO" | grep DisplayName | cut -d':' -f2 | xargs)"
COMPILER_VER="${CC_VSPROD}, $(echo "$CC_VSINFO" | grep InstallationVersion | cut -d':' -f2 | xargs)"
else
COMPILER_VER="$(gcc --version | head -n1)"
source /etc/os-release
OS_VER="${PRETTY_NAME}"
fi

if [[ -x "$(command -v powershell.exe)" ]]; then
OS_VER="$(powershell -Command "[System.Environment]::OSVersion.VersionString")"
fi

NVCC_VER="$(nvcc --version | tail -n1 | sed -E 's/^Build //')"

echo -e "COMPILER_VER=$COMPILER_VER\nNVCC_VER=$NVCC_VER\nOS_VER=${OS_VER}" | tee -a $0.out
6 changes: 2 additions & 4 deletions src/Makefile.win
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
CUDA_DIR = "$(CUDA_PATH)"

CC = cl
CFLAGS = /Ox /Oy /W2 /fp:fast /I$(CUDA_DIR)\include /I$(CUDA_DIR)\include\cudart /nologo
CFLAGS = /Ox /Oy /W2 /fp:fast /I"$(CUDA_PATH)\include" /I"$(CUDA_PATH)\include\cudart" /nologo

NVCCFLAGS = -m64 --ptxas-options=-v
CUFLAGS = -DWIN64 -Xcompiler "/EHsc /W3 /nologo /Ox" $(NVCCFLAGS)
Expand Down Expand Up @@ -33,7 +31,7 @@ CUSRC = tf_72bit.cu tf_96bit.cu tf_barrett96.cu tf_barrett96_gs.cu gpusieve.cu
CUOBJS = $(CUSRC:.cu=.obj) tf_75bit.obj
COBJS = $(CSRC:.c=.obj)

LIBS = $(CUDA_DIR)\lib\x64\cudart_static.lib
LIBS = "$(CUDA_PATH)\lib\x64\cudart_static.lib"

INSTALL = copy

Expand Down
2 changes: 1 addition & 1 deletion src/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ code path */
*******************************************************************************
******************************************************************************/

#define MFAKTC_VERSION "0.23.1" /* DO NOT CHANGE! */
#define MFAKTC_VERSION "0.23.2" /* DO NOT CHANGE! */



Expand Down