Skip to content

Commit ea79374

Browse files
authored
Merge branch 'main' into evolve_until_walttime
2 parents 5758798 + 84506a6 commit ea79374

5 files changed

Lines changed: 273 additions & 16 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ repos:
6565
# - id: shellcheck
6666

6767
- repo: https://github.com/python-jsonschema/check-jsonschema
68-
rev: 0.37.2
68+
rev: 0.37.3
6969
hooks:
7070
- id: check-github-workflows
7171
log_file: log_precommit_check-github-workflows
@@ -80,7 +80,7 @@ repos:
8080
log_file: log_precommit_clang-format
8181

8282
- repo: https://github.com/astral-sh/ruff-pre-commit
83-
rev: v0.15.16
83+
rev: v0.15.17
8484
hooks:
8585
- id: ruff-check
8686
args:
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Everything before this line will be provided by the new-env script
2+
3+
# ---- Modules ----
4+
module purge
5+
module load cpe/25.09
6+
module load craype-accel-amd-gfx90a craype-x86-trento
7+
module load PrgEnv-cray
8+
module load amd-mixed
9+
module load rocm
10+
module load cray-python
11+
module load cmake
12+
module load ninja
13+
module load CCE-GPU-5.0.0
14+
module load boost/1.88.0-mpi
15+
16+
# ---- AdaptiveCpp config ----
17+
export ACPP_VERSION=v24.10.0
18+
export ACPP_TARGETS="hip:gfx90a"
19+
export ACPP_GIT_DIR=$BUILD_DIR/.env/acpp-git
20+
export ACPP_BUILD_DIR=$BUILD_DIR/.env/acpp-builddir
21+
export ACPP_INSTALL_DIR=$BUILD_DIR/.env/acpp-installdir
22+
23+
export C_INCLUDE_PATH=$ROCM_PATH/llvm/include
24+
export CPLUS_INCLUDE_PATH=$ROCM_PATH/llvm/include
25+
26+
export MPICH_GPU_SUPPORT_ENABLED=1
27+
28+
export BOOST_ROOT_PATH="${BOOST_ROOT:-/opt/software/gaia/prod/5.0.0/boost-1.88.0-cce-18.0.0-ml3z}"
29+
export BOOST_SYMLINK_DIR=$BUILD_DIR/.env/boost-symlinks
30+
31+
function setupboost {
32+
# here I lost 2hrs of my life
33+
mkdir -p "${BOOST_SYMLINK_DIR}"
34+
for tagged in "${BOOST_ROOT_PATH}/lib"/libboost_*-mt-x64.so; do
35+
# e.g. libboost_context-mt-x64.so -> libboost_context.so
36+
base=$(basename "$tagged")
37+
untagged="${base/-mt-x64/}"
38+
if [ ! -e "${BOOST_SYMLINK_DIR}/${untagged}" ]; then
39+
ln -s "$tagged" "${BOOST_SYMLINK_DIR}/${untagged}"
40+
fi
41+
done
42+
}
43+
44+
setupboost
45+
46+
export LD_LIBRARY_PATH="${BOOST_SYMLINK_DIR}:${BOOST_ROOT_PATH}/lib:${LD_LIBRARY_PATH}"
47+
48+
# ---- Compiler setup ----
49+
function setupcompiler {
50+
echo " ---- Running AdaptiveCpp compiler setup ----"
51+
echo " -- Module list"
52+
module list
53+
54+
clone_acpp || return
55+
56+
cmake -S ${ACPP_GIT_DIR} -B ${ACPP_BUILD_DIR} \
57+
-DCMAKE_INSTALL_PREFIX=${ACPP_INSTALL_DIR} \
58+
-DROCM_PATH=$ROCM_PATH \
59+
-DCMAKE_C_COMPILER=${ROCM_PATH}/llvm/bin/clang \
60+
-DCMAKE_CXX_COMPILER=${ROCM_PATH}/llvm/bin/clang++ \
61+
-DWITH_ACCELERATED_CPU=ON \
62+
-DWITH_CPU_BACKEND=ON \
63+
-DWITH_CUDA_BACKEND=OFF \
64+
-DWITH_ROCM_BACKEND=ON \
65+
-DWITH_OPENCL_BACKEND=OFF \
66+
-DWITH_LEVEL_ZERO_BACKEND=OFF \
67+
-DACPP_TARGETS="gfx90a" \
68+
-DBOOST_ROOT="${BOOST_ROOT_PATH}" \
69+
-DBoost_DIR="${BOOST_ROOT_PATH}/lib/cmake" \
70+
-DBoost_NO_BOOST_CMAKE=FALSE \
71+
-DBoost_NO_SYSTEM_PATHS=TRUE \
72+
-DWITH_SSCP_COMPILER=OFF \
73+
-DLLVM_DIR=${ROCM_PATH}/llvm/lib/cmake/llvm/ || return
74+
75+
(cd ${ACPP_BUILD_DIR} && $MAKE_EXEC "${MAKE_OPT[@]}" && $MAKE_EXEC install) || return
76+
}
77+
78+
if [ ! -f "$ACPP_INSTALL_DIR/bin/acpp" ]; then
79+
echo " ----- acpp is not configured, compiling it ... -----"
80+
setupcompiler || return
81+
echo " ----- acpp configured ! -----"
82+
fi
83+
84+
# ---- Shamrock configure ----
85+
function shamconfigure {
86+
cmake \
87+
-S $SHAMROCK_DIR \
88+
-B $BUILD_DIR \
89+
-DSHAMROCK_ENABLE_BACKEND=SYCL \
90+
-DSYCL_IMPLEMENTATION=ACPPDirect \
91+
-DCMAKE_CXX_COMPILER="${ACPP_INSTALL_DIR}/bin/acpp" \
92+
-DACPP_PATH="${ACPP_INSTALL_DIR}" \
93+
-DCMAKE_BUILD_TYPE="${SHAMROCK_BUILD_TYPE}" \
94+
-DCMAKE_CXX_FLAGS="-march=znver3 -isystem ${CRAY_MPICH_PREFIX}/include" \
95+
-DCMAKE_SHARED_LINKER_FLAGS="-L\"${BOOST_SYMLINK_DIR}\" -Wl,-rpath,${BOOST_SYMLINK_DIR}" \
96+
-DCMAKE_MODULE_LINKER_FLAGS="-L\"${BOOST_SYMLINK_DIR}\" -Wl,-rpath,${BOOST_SYMLINK_DIR}" \
97+
-DCMAKE_EXE_LINKER_FLAGS="-lpthread -L\"${CRAY_MPICH_PREFIX}/lib\" -lmpi ${PE_MPICH_GTL_DIR_amd_gfx90a} ${PE_MPICH_GTL_LIBS_amd_gfx90a} -L\"${BOOST_SYMLINK_DIR}\" -Wl,-rpath,${BOOST_SYMLINK_DIR}" \
98+
-DBUILD_TEST=Yes \
99+
-DCXX_FLAG_ARCH_NATIVE=off \
100+
-DPYTHON_EXECUTABLE=$(python3 -c "import sys; print(sys.executable)") \
101+
"${CMAKE_OPT[@]}" || return
102+
}
103+
104+
# ---- Shamrock build ----
105+
function shammake {
106+
(cd $BUILD_DIR && $MAKE_EXEC "${MAKE_OPT[@]}" "${@}") || return
107+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
#SBATCH --account=<project account>
3+
#SBATCH --job-name=<jobname>
4+
#SBATCH --constraint=MI250
5+
#SBATCH --nodes=1
6+
#SBATCH --exclusive
7+
#SBATCH --time=01:00:00
8+
#SBATCH --output=job.%j.out
9+
#SBATCH --error=job.%j.out # Same file for both!
10+
11+
12+
. /opt/cray/pe/cpe/25.09/restore_lmod_system_defaults.sh
13+
module list
14+
15+
export SYCL_DEVICE_ALLOCATOR=aligned
16+
17+
WORKDIR=<path-to-Shamrock-build-directory>
18+
19+
export SHAM_MAX_ALLOC_SIZE=4294967296
20+
21+
. ./activate
22+
23+
srun --ntasks-per-node=8 --cpus-per-task=8 --threads-per-core=1 --gpus-per-task=1 --gpu-bind=closest -- ./shamrock --smi-full --sycl-cfg auto:HIP --force-dgpu-off --loglevel 1 --rscript runscript.py
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import argparse
2+
import os
3+
4+
import utils.amd_arch
5+
import utils.envscript
6+
import utils.intel_llvm
7+
import utils.sysinfo
8+
from utils.oscmd import *
9+
from utils.setuparg import *
10+
11+
NAME = "Adastra Intel AdaptiveCpp ROCM/LLVM"
12+
PATH = "machine/adastra/mi250/acpp-rocm-llvm"
13+
14+
15+
def setup(arg: SetupArg, envgen: EnvGen):
16+
argv = arg.argv
17+
builddir = arg.builddir
18+
shamrockdir = arg.shamrockdir
19+
buildtype = arg.buildtype
20+
lib_mode = arg.lib_mode
21+
22+
# Get current file path
23+
cur_file = os.path.realpath(os.path.expanduser(__file__))
24+
25+
parser = argparse.ArgumentParser(prog=PATH, description=NAME + " env for Shamrock")
26+
args = parser.parse_args(argv)
27+
args.gen = "ninja"
28+
29+
gen, gen_opt, cmake_gen, cmake_build_type = utils.sysinfo.select_generator(args, buildtype)
30+
31+
##############################
32+
# Generate env script header
33+
##############################
34+
35+
cmake_extra_args = ""
36+
37+
envgen.export_list = {
38+
"SHAMROCK_DIR": shamrockdir,
39+
"BUILD_DIR": builddir,
40+
"CMAKE_GENERATOR": cmake_gen,
41+
"MAKE_EXEC": gen,
42+
"MAKE_OPT": f"({gen_opt})",
43+
"CMAKE_OPT": f"({cmake_extra_args})",
44+
"SHAMROCK_BUILD_TYPE": f"'{cmake_build_type}'",
45+
}
46+
47+
envgen.ext_script_list = [
48+
shamrockdir + "/env/helpers/clone-acpp.sh",
49+
shamrockdir + "/env/helpers/pull_reffiles.sh",
50+
]
51+
52+
envgen.copy_env_file("exemple_batch.sh", "exemple_batch.sh")
53+
envgen.gen_env_file("env_built_acpp.sh")

src/pylib/shamrock/utils/dump/__init__.py

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import shamrock.sys
66

77

8-
def purge_old_dumps(dump_prefix, keep_first=1, keep_last=3, ext=".sham"):
8+
def helper_purge_old_dumps(dump_prefix, keep_first=1, keep_last=3, ext=".sham") -> None:
9+
"""
10+
Purge old dump files.
11+
"""
912
if shamrock.sys.world_rank() == 0:
1013
res = glob.glob(dump_prefix + "*" + ext)
1114
res.sort()
@@ -17,7 +20,10 @@ def purge_old_dumps(dump_prefix, keep_first=1, keep_last=3, ext=".sham"):
1720
os.remove(f)
1821

1922

20-
def get_last_dump(dump_prefix, ext=".sham"):
23+
def helper_get_last_dump(dump_prefix, ext=".sham") -> int | None:
24+
"""
25+
Get the last dump number.
26+
"""
2127
res = glob.glob(dump_prefix + "*" + ext)
2228

2329
num_max = -1
@@ -38,6 +44,10 @@ def get_last_dump(dump_prefix, ext=".sham"):
3844

3945
class ShamrockDumpHandleHelper:
4046
def __init__(self, model, dump_prefix, ext=".sham", metadata=False):
47+
"""
48+
Helper class to handle dump files.
49+
"""
50+
4151
self.model = model
4252
self.dump_prefix = dump_prefix
4353
self.ext = ext
@@ -47,16 +57,50 @@ def __init__(self, model, dump_prefix, ext=".sham", metadata=False):
4757
def get_dump_name_extension(self, idump, ext):
4858
return self.dump_prefix + f"{idump:07}" + ext
4959

50-
def get_dump_name(self, idump):
51-
return self.get_dump_name_extension(idump, self.ext)
52-
53-
def get_last_dump(self):
54-
return get_last_dump(self.dump_prefix, self.ext)
60+
def get_dump_name_extension(self, idump, ext) -> str:
61+
"""Get the name of the dump file with the extension"""
62+
return self.dump_prefix + f"{idump:07}" + ext
5563

56-
def purge_old_dumps(self, keep_first=1, keep_last=3):
57-
purge_old_dumps(self.dump_prefix, keep_first, keep_last, self.ext)
64+
def get_dump_name(self, idump) -> str:
65+
"""Get the name of the dump file (extension from self.ext)"""
66+
return self.get_dump_name_extension(idump, self.ext)
5867

59-
def load_dump(self, idump):
68+
def get_last_dump(self) -> int | None:
69+
"""Find the last dump number"""
70+
return helper_get_last_dump(self.dump_prefix, self.ext)
71+
72+
def purge_old_dumps(self, keep_first=1, keep_last=3) -> None:
73+
"""
74+
Purge old dump files.
75+
76+
Parameters
77+
----------
78+
keep_first : int, optional
79+
Number of oldest dump files to keep (default is 1, i.e. keep the first dump).
80+
keep_last : int, optional
81+
Number of newest dump files to keep (default is 3, i.e. keep the last 3 dumps).
82+
83+
Returns
84+
-------
85+
None
86+
This method does not return a value.
87+
"""
88+
helper_purge_old_dumps(self.dump_prefix, keep_first, keep_last, self.ext)
89+
90+
def load_dump(self, idump) -> None:
91+
"""
92+
Load a dump file.
93+
94+
Parameters
95+
----------
96+
idump : int
97+
The dump identifier to load.
98+
99+
Returns
100+
-------
101+
None
102+
This method does not return a value.
103+
"""
60104
dump_name = self.get_dump_name(idump)
61105
if shamrock.sys.world_rank() == 0:
62106
print(f"Loading dump: {dump_name} i={idump}")
@@ -69,6 +113,27 @@ def load_dump(self, idump):
69113
return None
70114

71115
def write_dump(self, idump, metadata=None, purge_old_dumps=False, keep_first=1, keep_last=3):
116+
"""
117+
Write a dump file.
118+
119+
Parameters
120+
----------
121+
idump : int
122+
The dump identifier to write.
123+
metadata: object
124+
Metadata to be dumped alongside the checkpoint as json
125+
purge_old_dumps : bool, optional
126+
Whether to purge old dumps (default is False).
127+
keep_first : int, optional
128+
Number of oldest dump files to keep (default is 1, i.e. keep the first dump).
129+
keep_last : int, optional
130+
Number of newest dump files to keep (default is 3, i.e. keep the last 3 dumps).
131+
132+
Returns
133+
-------
134+
None
135+
This method does not return a value.
136+
"""
72137
dump_name = self.get_dump_name(idump)
73138
self.model.dump(dump_name)
74139

@@ -82,10 +147,19 @@ def write_dump(self, idump, metadata=None, purge_old_dumps=False, keep_first=1,
82147
if purge_old_dumps:
83148
self.purge_old_dumps(keep_first, keep_last)
84149

85-
def load_last_dump_or(self, functor_no_last_dump):
150+
def load_last_dump_or(self, functor_no_last_dump) -> None:
151+
"""
152+
Load the last dump or call a function if no dump is found.
153+
154+
Parameters
155+
----------
156+
functor_no_last_dump : callable
157+
The function to call if no dump are found (i.e. the setup function).
158+
"""
86159
idump = self.get_last_dump()
87160
if idump is None:
88-
functor_no_last_dump()
89-
return None
161+
result = functor_no_last_dump()
162+
if result is not None:
163+
raise ValueError("functor_no_last_dump must not return a value")
90164
else:
91-
return self.load_dump(idump)
165+
self.load_dump(idump)

0 commit comments

Comments
 (0)