Skip to content

Commit adec3af

Browse files
authored
Add NVIDIA Compiler Support (#53)
* add nvidia-hpc compiler option * test versions from 20.7 to 22.11
1 parent 05091bb commit adec3af

File tree

7 files changed

+178
-13
lines changed

7 files changed

+178
-13
lines changed

.github/actions/test-cc/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ runs:
1414
- name: Check compiler version
1515
shell: bash
1616
run: |
17-
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
17+
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]] && [[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
1818
# only last line of output captured by command substitution, write to temp file instead
1919
${{ env.CC }} //QV > "$RUNNER_TEMP/${{ env.CC }}.ver" 2>&1
2020
ccv=$(cat "$RUNNER_TEMP/${{ env.CC }}.ver" | head -n 1)
2121
ccv=${ccv#*Version }
2222
ccv=${ccv%% Build*}
23-
else
23+
elif ([ "$RUNNER_OS" == "Linux" ] && [[ "${{ inputs.compiler }}" == "nvidia-hpc" ]]); then
24+
# Get the compiler version and extract the version number
25+
ccv=$(${{ env.CC }} --version 2>&1 | awk '/nvc/ {print $2}' | cut -d'-' -f1)
26+
elif ([[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
2427
ccv=$(${{ env.CC }} --version | head -n 1)
2528
ccv=$(echo "$ccv" | grep -woE '[0123456789.]+' | head -n 1)
2629
fi

.github/actions/test-cxx/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ runs:
1414
- name: Check compiler version
1515
shell: bash
1616
run: |
17-
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ matrix.toolchain.compiler }}" =~ "intel" ]]); then
17+
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ matrix.toolchain.compiler }}" =~ "intel" ]] && [[ "${{ matrix.toolchain.compiler }}" != "nvidia-hpc" ]]); then
1818
# only last line of output captured by command substitution, write to temp file instead
1919
${{ env.CXX }} //QV > "$RUNNER_TEMP/${{ env.CXX }}.ver" 2>&1
2020
cxxv=$(cat "$RUNNER_TEMP/${{ env.CXX }}.ver" | head -n 1)
2121
cxxv=${cxxv#*Version }
2222
cxxv=${cxxv%% Build*}
23-
else
23+
elif ([ "$RUNNER_OS" == "Linux" ] && [[ "${{ matrix.toolchain.compiler}}" == "nvidia-hpc" ]]); then
24+
# Get the compiler version and extract the version number
25+
cxxv=$(${{ env.CXX }} --version 2>&1 | awk '/nvc++/ {print $2}' | cut -d'-' -f1)
26+
elif ([[ "${{ matrix.toolchain.compiler}}" != "nvidia-hpc" ]]); then
2427
cxxv=$(${{ env.CXX }} --version | head -n 1)
2528
cxxv=$(echo "$cxxv" | grep -woE '[0123456789.]+' | head -n 1)
2629
fi

.github/actions/test-fc/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ runs:
1414
- name: Check compiler version
1515
shell: bash
1616
run: |
17-
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]]); then
17+
if ([ "$RUNNER_OS" == "Windows" ] && [[ "${{ inputs.compiler }}" =~ "intel" ]] && [[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
1818
# only last line of output captured by command substitution, write to temp file instead
1919
${{ env.FC }} //QV > "$RUNNER_TEMP/${{ env.FC }}.ver" 2>&1
2020
fcv=$(cat "$RUNNER_TEMP/${{ env.FC }}.ver" | head -n 1)
2121
fcv=${fcv#*Version }
2222
fcv=${fcv%% Build*}
23-
else
23+
elif ([ "$RUNNER_OS" == "Linux" ] && [[ "${{ inputs.compiler }}" == "nvidia-hpc" ]]); then
24+
# Get the compiler version and extract the version number
25+
fcv=$(${{ env.FC }} --version 2>&1 | awk '/nvfortran/ {print $2}' | cut -d'-' -f1)
26+
elif ([[ "${{ inputs.compiler }}" != "nvidia-hpc" ]]); then
2427
fcv=$(${{ env.FC }} --version | head -n 1)
2528
fcv=$(echo "$fcv" | grep -woE '[0123456789.]+' | head -n 1)
2629
fi

.github/workflows/test.yml

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,28 @@ jobs:
3333
- {compiler: gcc, version: 13}
3434
- {compiler: intel, version: '2023.2'}
3535
- {compiler: intel-classic, version: '2021.10'}
36+
- {compiler: nvidia-hpc, version: '23.11'}
3637
exclude:
37-
# ifx not available for mac
38-
- os: macos-13
39-
toolchain: {compiler: intel}
40-
- os: macos-12
41-
toolchain: {compiler: intel}
42-
- os: macos-11
43-
toolchain: {compiler: intel}
38+
# ifx not available for mac
39+
- os: macos-13
40+
toolchain: {compiler: intel}
41+
- os: macos-12
42+
toolchain: {compiler: intel}
43+
- os: macos-11
44+
toolchain: {compiler: intel}
45+
# nvidia-hpc not available for mac
46+
- os: macos-13
47+
toolchain: {compiler: nvidia-hpc}
48+
- os: macos-12
49+
toolchain: {compiler: nvidia-hpc}
50+
- os: macos-11
51+
toolchain: {compiler: nvidia-hpc}
52+
# nvidia-hpc not available for windows
53+
- os: windows-2022
54+
toolchain: {compiler: nvidia-hpc}
55+
- os: windows-2019
56+
toolchain: {compiler: nvidia-hpc}
57+
4458
steps:
4559
- name: Checkout repository
4660
uses: actions/checkout@v4
@@ -123,6 +137,29 @@ jobs:
123137
- {compiler: intel-classic, version: '2021.2'}
124138
- {compiler: intel-classic, version: '2021.1.2'}
125139
- {compiler: intel-classic, version: '2021.1'}
140+
- {compiler: nvidia-hpc, version: '23.11'}
141+
- {compiler: nvidia-hpc, version: '23.9'}
142+
- {compiler: nvidia-hpc, version: '23.7'}
143+
- {compiler: nvidia-hpc, version: '23.5'}
144+
- {compiler: nvidia-hpc, version: '23.3'}
145+
- {compiler: nvidia-hpc, version: '23.1'}
146+
- {compiler: nvidia-hpc, version: '22.11'}
147+
- {compiler: nvidia-hpc, version: '22.9'}
148+
- {compiler: nvidia-hpc, version: '22.7'}
149+
- {compiler: nvidia-hpc, version: '22.5'}
150+
- {compiler: nvidia-hpc, version: '22.3'}
151+
- {compiler: nvidia-hpc, version: '22.2'}
152+
- {compiler: nvidia-hpc, version: '22.1'}
153+
- {compiler: nvidia-hpc, version: '21.11'}
154+
- {compiler: nvidia-hpc, version: '21.9'}
155+
- {compiler: nvidia-hpc, version: '21.7'}
156+
- {compiler: nvidia-hpc, version: '21.5'}
157+
- {compiler: nvidia-hpc, version: '21.3'}
158+
- {compiler: nvidia-hpc, version: '21.2'}
159+
- {compiler: nvidia-hpc, version: '21.1'}
160+
- {compiler: nvidia-hpc, version: '20.11'}
161+
- {compiler: nvidia-hpc, version: '20.9'}
162+
- {compiler: nvidia-hpc, version: '20.7'}
126163
exclude:
127164
# ifx not available for mac
128165
- os: macos-13
@@ -131,6 +168,18 @@ jobs:
131168
toolchain: {compiler: intel}
132169
- os: macos-11
133170
toolchain: {compiler: intel}
171+
# nvidia-hpc not available for mac
172+
- os: macos-13
173+
toolchain: {compiler: nvidia-hpc}
174+
- os: macos-12
175+
toolchain: {compiler: nvidia-hpc}
176+
- os: macos-11
177+
toolchain: {compiler: nvidia-hpc}
178+
# nvidia-hpc not available for windows
179+
- os: windows-2022
180+
toolchain: {compiler: nvidia-hpc}
181+
- os: windows-2019
182+
toolchain: {compiler: nvidia-hpc}
134183
steps:
135184
- name: Checkout repository
136185
uses: actions/checkout@v4

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ jobs:
3535
- {compiler: gcc, version: 13}
3636
- {compiler: intel, version: '2023.2'}
3737
- {compiler: intel-classic, version: '2021.10'}
38+
- {compiler: nvidia-hpc, version: '23.11'}
3839
include:
3940
- os: ubuntu-latest
4041
toolchain: {compiler: gcc, version: 12}
4142
exclude:
4243
- os: macos-latest
4344
toolchain: {compiler: intel, version: '2023.2'}
45+
- os: macos-latest
46+
toolchain: {compiler: nvidia-hpc, version: '23.11'}
47+
- os: windows-latest
48+
toolchain: {compiler: nvidia-hpc, version: '23.11'}
4449

4550
steps:
4651
- uses: fortran-lang/setup-fortran@v1
@@ -61,6 +66,7 @@ jobs:
6166
- *gcc* (for `gfortran`)
6267
- *intel* (for `ifx`)
6368
- *intel-classic* (for `ifort`)
69+
- *nvidia-hpc* (for `nvfortran`)
6470
- *version*: Version of the compiler toolchain. See [runner compatibility](#runner-compatibility) charts below.
6571

6672

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ runs:
7070
version=${VERSION:-2023.2.0}
7171
install_intel $platform false
7272
;;
73+
nvidia-hpc)
74+
version=${VERSION:-23.11}
75+
install_nvidiahpc $platform
76+
;;
7377
*)
7478
exit 1
7579
;;

setup-fortran.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ require_fetch()
1414
fi
1515
}
1616

17+
# Function to install environment-modules via apt
18+
# https://github.com/cea-hpc/modules
19+
install_environment_modules_apt() {
20+
echo "Installing environment-modules package..."
21+
sudo apt-get install -y environment-modules
22+
echo "Environment-modules installed."
23+
echo "Sourcing modules.sh script to set up environment modules..."
24+
source /etc/profile.d/modules.sh
25+
echo "Environment modules set up completed."
26+
}
27+
1728
install_gcc_brew()
1829
{
1930
# check if gcc preinstalled via brew
@@ -504,3 +515,89 @@ install_intel()
504515
;;
505516
esac
506517
}
518+
519+
export_nvidiahpc_vars()
520+
{
521+
local version=$1
522+
523+
# to convert version format from X.Y to X-Y
524+
local cversion=$(echo "$version" | tr '.' '-')
525+
526+
cat >> $GITHUB_ENV <<EOF
527+
NVARCH=`uname -s`_`uname -m`;
528+
NVCOMPILERS=/opt/nvidia/hpc_sdk;
529+
MANPATH=$MANPATH:$NVCOMPILERS/$NVARCH/$cversion/compilers/man;
530+
PATH=$NVCOMPILERS/$NVARCH/$cversion/compilers/bin:$PATH;
531+
PATH=$NVCOMPILERS/$NVARCH/$cversion/comm_libs/mpi/bin:$PATH
532+
MANPATH=$MANPATH:$NVCOMPILERS/$NVARCH/$cversion/comm_libs/mpi/man
533+
EOF
534+
for path in ${PATH//:/ }; do
535+
echo $path >> $GITHUB_PATH
536+
done
537+
}
538+
539+
install_nvidiahpc_apt()
540+
{
541+
local version=$1
542+
543+
# install environment-modules
544+
install_environment_modules_apt
545+
546+
# to convert version format from X.Y to X-Y
547+
local cversion=$(echo "$version" | tr '.' '-')
548+
549+
# install NVIDIA HPC SDK
550+
echo "Installing NVIDIA HPC SDK $version..."
551+
curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg
552+
echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | sudo tee /etc/apt/sources.list.d/nvhpc.list
553+
sudo apt-get update -y
554+
sudo apt-get install -y nvhpc-$cversion
555+
echo "NVIDIA HPC SDK $version installed."
556+
557+
# load NVIDIA HPC SDK module
558+
echo "Loading NVIDIA HPC SDK $version module..."
559+
NVCOMPILERS=/opt/nvidia/hpc_sdk; export NVCOMPILERS
560+
export MODULEPATH=$NVCOMPILERS/modulefiles:$MODULEPATH
561+
module load nvhpc
562+
echo "NVIDIA HPC SDK $version module loaded."
563+
564+
# set environment variables
565+
echo "Setting environment variables..."
566+
export_nvidiahpc_vars $version
567+
568+
# set environment variables
569+
export FC="nvfortran"
570+
export CC="nvc"
571+
export CXX="nvc++"
572+
echo "Environment variables set."
573+
}
574+
575+
install_nvidiahpc()
576+
{
577+
local platform=$1
578+
case $platform in
579+
linux*)
580+
install_nvidiahpc_apt $version
581+
;;
582+
darwin*)
583+
echo "NVIDIA HPC SDK is not supported on macOS."
584+
exit 1
585+
;;
586+
mingw*)
587+
echo "NVIDIA HPC SDK is not supported on Windows."
588+
exit 1
589+
;;
590+
msys*)
591+
echo "NVIDIA HPC SDK is not supported on MSYS."
592+
exit 1
593+
;;
594+
cygwin*)
595+
echo "NVIDIA HPC SDK is not supported on Cygwin."
596+
exit 1
597+
;;
598+
*)
599+
echo "Unsupported platform: $platform"
600+
exit 1
601+
;;
602+
esac
603+
}

0 commit comments

Comments
 (0)