Skip to content

Commit

Permalink
Adding affinity scripts to PALS mpiexec settings (#282)
Browse files Browse the repository at this point in the history
Added an option to specify an affinity script for the PALSMpiexecSettings
and add it to the run command after the run arguments, with no "--" prefix.
Optional arguments can be passed after the affinity script.

[ committed by @rickybalin ]
[ reviewed by @al-rigazzi ]
  • Loading branch information
rickybalin authored Oct 18, 2023
1 parent 63d1fa5 commit c6ec746
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions smartsim/settings/mpiSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
**kwargs,
)
self.mpmd: t.List[RunSettings] = []
self.affinity_script: t.List[str] = []

if not shutil.which(self._run_command):
msg = (
Expand Down
14 changes: 14 additions & 0 deletions smartsim/settings/palsSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ def set_walltime(self, walltime: str) -> None:
"""
logger.warning("set_walltime not supported under PALS")

def set_gpu_affinity_script(self, affinity: str, *args: t.Any) -> None:
""" Set the GPU affinity through a bash script
:param affinity: path to the affinity script
:type affinity: str
"""
self.affinity_script.append(str(affinity))
for arg in args:
self.affinity_script.append(str(arg))

def format_run_args(self) -> t.List[str]:
"""Return a list of MPI-standard formatted run arguments
Expand All @@ -199,6 +209,10 @@ def format_run_args(self) -> t.List[str]:
args += [prefix + opt]
else:
args += [prefix + opt, str(value)]

if self.affinity_script:
args += self.affinity_script

return args

def format_env_vars(self) -> t.List[str]:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_pals_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
# with pytest.raises(SSUnsupportedError):
# func(None)

def test_affinity_script():
settings = PalsMpiexecSettings(default_exe, **default_kwargs)
settings.set_gpu_affinity_script("/path/to/set_affinity_gpu.sh", 1, 2)
assert settings.format_run_args() == ["/path/to/set_affinity_gpu.sh", "1", "2"]


def test_cpu_binding_type():
settings = PalsMpiexecSettings(default_exe, **default_kwargs)
Expand Down

0 comments on commit c6ec746

Please sign in to comment.