Skip to content

Commit f50d903

Browse files
committed
Initial commit
0 parents  commit f50d903

39 files changed

+6108
-0
lines changed

.clang-format

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 2
3+
Language: Cpp
4+
ColumnLimit: 100

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
target/
2+
topic2_dataset/
3+
output*
4+
labs/.ipynb_checkpoint*
5+
labs/topic0_daxpy/.ipynb_checkpoint*
6+
labs/topic0_daxpy/daxpy
7+
labs/topic0_daxpy/solutions/.ipynb_checkpoint*
8+
labs/topic1_heat/.ipynb_checkpoint*
9+
labs/topic1_heat/heat*
10+
labs/topic1_heat/output*
11+
labs/topic1_heat/solutions/.ipynb_checkpoint*
12+
labs/topic2_tree/.ipynb_checkpoint*
13+
labs/topic2_tree/tree*
14+
labs/topic2_tree/*.txt
15+
labs/topic2_tree/solutions/.ipynb_checkpoint*

ci/compile

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/usr/bin/env sh
2+
#
3+
# ./ci/compile [compiler] [mode]
4+
set -e
5+
hlp="./ci/compile <compiler> <mode> <mpi> <std> <path>\n compilers: g++,clang++,nvc++\n mode: debug,release,*-nomanaged\n mpi: 0|1\n std: 17|20"
6+
7+
CXX=$1
8+
mode=$2
9+
mpi=$3
10+
std=$4
11+
path=$5
12+
13+
IFLAGS="\
14+
-Iinclude/ \
15+
-isystem/usr/local/range-v3/include \
16+
-isystem/usr/local/execution/include \
17+
-isystem/usr/local/execution/examples \
18+
-isystem/opt/nvidia/hpc_sdk/Linux_x86_64/2022/cuda/include \
19+
"
20+
CXXFLAGS="-std=c++${std} ${IFLAGS}"
21+
22+
case $CXX in
23+
nvc++)
24+
LFLAGS="-lpthread -ldl"
25+
CXXFLAGS="${CXXFLAGS} --display_error_number --diag_suppress 186"
26+
case $mode in
27+
release)
28+
CXXFLAGS="${CXXFLAGS} -stdpar=gpu -fast -Mllvm-fast -DNDEBUG -gpu=managed,fastmath,fma"
29+
;;
30+
release-cpu)
31+
CXXFLAGS="${CXXFLAGS} -stdpar=multicore -fast -Mllvm-fast -DNDEBUG"
32+
;;
33+
release-nomanaged)
34+
CXXFLAGS="${CXXFLAGS} -stdpar=gpu -fast -Mllvm-fast -DNDEBUG -gpu=nomanaged,fastmath,fma -DCUDA_ALLOC "
35+
;;
36+
debug)
37+
CXXFLAGS="${CXXFLAGS} -stdpar=gpu -gpu=debug -O0"
38+
;;
39+
debug-nomanaged)
40+
CXXFLAGS="${CXXFLAGS} -stdpar=gpu -O0 -g -Mdwarf3 -gpu=nomanaged,debug -DCUDA_ALLOC"
41+
;;
42+
*)
43+
echo "Unknown mode: ${2}"
44+
echo $hlp
45+
exit 1
46+
;;
47+
esac
48+
;;
49+
g++)
50+
LFLAGS="-lpthread -ldl -ltbb"
51+
case $mode in
52+
release*)
53+
CXXFLAGS="${CXXFLAGS} -Ofast -DNDEBUG"
54+
;;
55+
debug*)
56+
CXXFLAGS="${CXXFLAGS} -O0 -g3"
57+
;;
58+
*)
59+
echo "Unknown mode: ${2}"
60+
echo $hlp
61+
exit 1
62+
;;
63+
esac
64+
;;
65+
clang++)
66+
LFLAGS="-lpthread -ldl -ltbb"
67+
case $mode in
68+
release-libcxx)
69+
CXXFLAGS="${CXXFLAGS} -Ofast -DNDEBUG -stdlib=libc++"
70+
;;
71+
debug-libcxx)
72+
CXXFLAGS="${CXXFLAGS} -O0 -g3 -stdlib=libc++"
73+
;;
74+
release*)
75+
CXXFLAGS="${CXXFLAGS} -Ofast -DNDEBUG"
76+
;;
77+
debug*)
78+
CXXFLAGS="${CXXFLAGS} -O0 -g3"
79+
;;
80+
*)
81+
echo "Unknown mode: ${2}"
82+
echo $hlp
83+
exit 1
84+
;;
85+
esac
86+
;;
87+
*)
88+
echo "Unknown compiler: ${1}"
89+
echo $help
90+
exit 1
91+
;;
92+
esac
93+
94+
CMD=$CXX
95+
case $mpi in
96+
0)
97+
;;
98+
1)
99+
CMD="OMPI_CXX=$CXX mpicxx"
100+
;;
101+
*)
102+
echo "mpi value must be 0 or 1"
103+
echo "$help"
104+
exit 1
105+
;;
106+
esac
107+
108+
case $std in
109+
17|20)
110+
;;
111+
*)
112+
echo "The C++ std must be 17 or 20"
113+
echo "$help"
114+
exit 1
115+
;;
116+
esac
117+
118+
if [ -z $path ]; then
119+
echo "path: $path not set"
120+
echo "$help"
121+
exit 1
122+
fi
123+
124+
rm -r target || true
125+
mkdir -p target/$(dirname $path)
126+
127+
echo "$CXX $CXXFLAGS $path -o target/$path $LFLAGS"
128+
$CXX $CXXFLAGS $path -o target/$path $LFLAGS

ci/fmt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
3+
set -ex
4+
5+
find labs/ -iname *.hpp -o -iname *.cpp | xargs clang-format -i

ci/recipe_dev.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
HPCCM development container for the C++ HPC tutorial
3+
https://github.com/NVIDIA/hpc-container-maker/
4+
"""
5+
nvhpc_ver = '22.3'
6+
cuda_ver = '11.6'
7+
8+
Stage0 += baseimage(image = f'nvcr.io/nvidia/nvhpc:{nvhpc_ver}-devel-cuda{cuda_ver}-ubuntu20.04')
9+
10+
Stage0 += packages(ospackages=[
11+
'libtbb-dev', # Required for GCC C++ parallel STL
12+
'python3', 'python3-pip', 'python-is-python3', 'python3-setuptools',
13+
'nginx', 'zip', 'make', 'build-essential', 'curl',
14+
'git', 'bc', 'debianutils', 'libnuma1', 'openssh-client', 'wget', 'numactl',
15+
])
16+
17+
# Install GNU and LLVM toolchains and CMake
18+
Stage0 += gnu(version='11', extra_repository=True)
19+
Stage0 += llvm(version='15', upstream=True, extra_tools=True, toolset=True)
20+
Stage0 += cmake(eula=True, version='3.22.2')
21+
22+
# Install NSight Systems profiler
23+
Stage0 += nsight_systems(eula=True)
24+
25+
#
26+
Stage0 += shell(commands=[
27+
'set -ex', # Exit on first error and debug output
28+
29+
# Configure the HPC SDK toolchain to pick the latest GCC
30+
f'cd /opt/nvidia/hpc_sdk/Linux_x86_64/{nvhpc_ver}/compilers/bin/',
31+
'makelocalrc -d . -x .',
32+
33+
# Install required python packages for the notebooks
34+
'pip install --upgrade pip',
35+
'pip install numpy matplotlib conan gdown jupyterlab ipywidgets',
36+
37+
# Install latest versions of range-v3 and std::execution
38+
'mkdir -p /var/tmp',
39+
'cd /var/tmp',
40+
'git clone https://github.com/ericniebler/range-v3.git',
41+
'cp -r range-v3 /usr/local/range-v3',
42+
'git clone https://github.com/brycelelbach/wg21_p2300_std_execution.git',
43+
'cp -r wg21_p2300_std_execution /usr/local/execution',
44+
'cd -',
45+
'rm -rf /var/tmp',
46+
])
47+
48+
# libc++abi : make sure clang with -stdlib=libc++ can find it
49+
Stage0 += shell(commands=[
50+
'ln -sf /usr/lib/llvm-15/lib/libc++abi.so.1 /usr/lib/llvm-15/lib/libc++abi.so',
51+
])
52+
Stage0 += environment(variables={
53+
'LD_LIBRARY_PATH':'/usr/lib/llvm-15/lib:$LD_LIBRARY_PATH',
54+
'LIBRARY_PATH':'/usr/lib/llvm-15/lib:$LIBRARY_PATH',
55+
})

ci/recipe_lab.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
HPCCM deployment container for the C++ HPC tutorial
3+
https://github.com/NVIDIA/hpc-container-maker/
4+
"""
5+
6+
hpccm.include('recipe_dev.py')
7+
8+
Stage0 += copy(src='labs/', dest='/labs/')
9+
Stage0 += workdir(directory='/labs/')
10+
Stage0 += runscript(commands=[
11+
'jupyter-lab --no-browser --allow-root --ip=0.0.0.0 --port=8888 --NotebookApp.token="" --notebook-dir=/labs'
12+
])

ci/run_docker

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env sh
2+
set -ex
3+
4+
IMG_DEV=cpp_hpc_tutorial:dev-latest
5+
IMG_LAB=cpp_hpc_tutorial:lab-latest
6+
PORT=8888
7+
8+
DOCKER_CMDS="\
9+
--gpus=all \
10+
-u $(id -u):$(id -g) \
11+
-h $(hostname) \
12+
-v $(pwd):/src \
13+
-v $(pwd)/conan:/.conan \
14+
-w /src \
15+
$IMG_DEV \
16+
"
17+
18+
case $1 in
19+
build)
20+
rm -r target/ || true
21+
mkdir -p target
22+
hpccm --recipe=ci/recipe_dev.py | docker build -t $IMG_DEV -
23+
hpccm --recipe=ci/recipe_lab.py > target/Dockerfile
24+
docker build -t $IMG_LAB -f target/Dockerfile .
25+
;;
26+
fmt)
27+
docker run $DOCKER_CMDS bash -c "set -ex && ./ci/fmt"
28+
;;
29+
it)
30+
docker run -it $DOCKER_CMDS bash
31+
;;
32+
serve-dev)
33+
mkdir -p target/local
34+
docker run -p ${PORT}:8888 \
35+
-v "$(pwd)/target/local":"/.local" $DOCKER_CMDS bash -c "jupyter-lab --no-browser --allow-root --ip=0.0.0.0 --port=8888 --NotebookApp.token="" --notebook-dir=/src/labs"
36+
;;
37+
serve)
38+
rm -r target/ || true
39+
mkdir -p target
40+
hpccm --recipe=ci/recipe_lab.py > target/Dockerfile
41+
docker build -t $IMG_LAB -f target/Dockerfile .
42+
docker run --gpus=all -p ${PORT}:8888 $IMG_LAB
43+
;;
44+
*)
45+
exit 1
46+
;;
47+
esac

ci/test_exercises

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Compile all inputs and solutions
4+
5+
set -e
6+
7+
compilers="nvc++ g++ clang++"
8+
modes="release release-cpu debug"
9+
stds="17 20"
10+
11+
# Topic 1: Heat equation
12+
daxpy="topic1_heat/starting_point.cpp"
13+
echo "${compilers}" | tr ' ' '\n' | while read compiler; do
14+
echo "${modes}" | tr ' ' '\n' | while read mode; do
15+
echo "${stds}" | tr ' ' '\n' | while read std; do
16+
echo "${daxpy}" | tr ' ' '\n' | while read file; do
17+
./ci/compile ${compiler} ${mode} 0 ${std} labs/${file}
18+
echo "./target/labs/${file} 2048 1024"
19+
./target/labs/${file} 2048 1024
20+
done
21+
done
22+
done
23+
done
24+
25+
# Topic 0: DAXPY: compile and run full solutions
26+
files="topic0_daxpy/starting_point.cpp topic0_daxpy/solutions/exercise0.cpp topic0_daxpy/solutions/exercise0_indices.cpp topic0_daxpy/solutions/exercise1.cpp"
27+
echo "${compilers}" | tr ' ' '\n' | while read compiler; do
28+
echo "${modes}" | tr ' ' '\n' | while read mode; do
29+
echo "${stds}" | tr ' ' '\n' | while read std; do
30+
echo "${files}" | tr ' ' '\n' | while read file; do
31+
./ci/compile ${compiler} ${mode} 0 ${std} labs/${file}
32+
echo "./target/labs/${file} 100"
33+
./target/labs/${file} 100
34+
done
35+
done
36+
done
37+
done
38+
39+
# Topic 0: DAXPY: compile partial solutions
40+
files="topic0_daxpy/exercise0.cpp topic0_daxpy/exercise1.cpp"
41+
echo "${compilers}" | tr ' ' '\n' | while read compiler; do
42+
echo "${modes}" | tr ' ' '\n' | while read mode; do
43+
echo "${stds}" | tr ' ' '\n' | while read std; do
44+
echo "${files}" | tr ' ' '\n' | while read file; do
45+
./ci/compile ${compiler} ${mode} 0 ${std} labs/${file}
46+
done
47+
done
48+
done
49+
done
50+
51+
52+
# Topic 2: Tree
53+
tree="topic2_tree/starting_point.cpp topic2_tree/solutions/exercise0.cpp topic2_tree/solutions/exercise0_gpu.cpp"
54+
if [ ! -d topic2_dataset ]; then
55+
mkdir -p topic2_dataset
56+
(
57+
cd topic2_dataset
58+
./../labs/topic2_tree/books.sh
59+
)
60+
fi
61+
echo "${compilers}" | tr ' ' '\n' | while read compiler; do
62+
echo "${modes}" | tr ' ' '\n' | while read mode; do
63+
echo "${tree}" | tr ' ' '\n' | while read file; do
64+
if [ "${mode}" = "release" ] || [ "${mode}" = "debug" ] && [ "${compiler}" = "nvc++" ] && [ "${file}" = "topic2_tree/solutions/exercise0.cpp" ] ; then
65+
continue
66+
elif [ "${mode}" = "debug" ] && [ "${compiler}" = "nvc++" ] ; then
67+
continue
68+
elif [ "${compiler}" = "nvc++" ] && [ "${file}" = "topic2_tree/solutions/exercise0_gpu.cpp" ] ; then
69+
./ci/compile ${compiler} ${mode} 0 17 labs/${file}
70+
echo "./target/labs/${file}"
71+
cp ./target/labs/${file} topic2_dataset/tree_bin
72+
(
73+
cd topic2_dataset
74+
./tree_bin
75+
)
76+
else
77+
./ci/compile ${compiler} ${mode} 0 20 labs/${file}
78+
echo "./target/labs/${file}"
79+
cp ./target/labs/${file} topic2_dataset/tree_bin
80+
(
81+
cd topic2_dataset
82+
./tree_bin
83+
)
84+
fi
85+
done
86+
done
87+
done
88+
89+
# Topic 2: Tree: compile partial solution
90+
files="topic2_tree/exercise0.cpp"
91+
echo "${compilers}" | tr ' ' '\n' | while read compiler; do
92+
echo "${modes}" | tr ' ' '\n' | while read mode; do
93+
echo "${files}" | tr ' ' '\n' | while read file; do
94+
./ci/compile ${compiler} ${mode} 0 20 labs/${file}
95+
done
96+
done
97+
done

conan/profiles/clang

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[settings]
2+
os=Linux
3+
os_build=Linux
4+
arch=x86_64
5+
arch_build=x86_64
6+
compiler=clang
7+
compiler.version=15
8+
compiler.libcxx=libc++
9+
build_type=Release
10+
[options]
11+
[build_requires]
12+
[env]
13+
CC=clang
14+
CXX=clang++

0 commit comments

Comments
 (0)