Skip to content

Commit 8f5ebbe

Browse files
committed
feat: implement DVM allocation method for complete ranks without core reduction
1 parent d1f7aed commit 8f5ebbe

5 files changed

Lines changed: 197 additions & 1 deletion

File tree

‎ipsframework/resource_manager.py‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ def get_allocation(
371371
whole_nodes = True
372372
whole_socks = True
373373

374+
if (
375+
str(self.CM.get_platform_parameter('MPIRUN_VERSION', silent=True)).upper()
376+
== 'OPENMPI-DVM'
377+
):
378+
return self._get_dvm_allocation(
379+
comp_id, nproc, task_id, whole_nodes, whole_socks, ppn, task_cpp, task_gpp
380+
)
381+
374382
# Are there enough cores to satisfy the request?
375383
# Returns the list of nodes that fit the bill
376384
allocation_possible = False
@@ -525,6 +533,97 @@ def get_allocation(
525533
cores_allocated=cores_allocated,
526534
)
527535

536+
def _get_dvm_allocation(
537+
self,
538+
comp_id: str,
539+
nproc: int,
540+
task_id: int,
541+
whole_nodes: bool,
542+
whole_socks: bool,
543+
ppn: int,
544+
task_cpp: int,
545+
task_gpp: int,
546+
) -> Allocation:
547+
"""Reserve complete ranks for a DVM launch without reducing their core count.
548+
549+
:param comp_id: Identifier of the requesting component.
550+
:param nproc: Number of MPI ranks requested.
551+
:param task_id: Identifier used to track and release the allocation.
552+
:param whole_nodes: Whether to reserve entire nodes.
553+
:param whole_socks: Whether to reserve entire sockets.
554+
:param ppn: Maximum ranks per node requested by the caller.
555+
:param task_cpp: Physical cores per rank; zero retains launcher defaults.
556+
:param task_gpp: GPUs per rank.
557+
:returns: Allocation containing rank counts and reserved physical cores.
558+
:raises ValueError: If the rank or core count is invalid.
559+
:raises BadResourceRequestError: If the request exceeds total capacity.
560+
:raises InsufficientResourcesError: If capacity is temporarily occupied.
561+
"""
562+
if nproc < 1 or not isinstance(task_cpp, int) or task_cpp < 0:
563+
raise ValueError('DVM tasks require positive nproc and nonnegative integer task_cpp')
564+
cpp = task_cpp or 1
565+
ppn = min(ppn, self.cores_per_node // cpp)
566+
total_capacity = sum(min(ppn, node.total_cores // cpp) for node in self.nodes.values())
567+
requested_nodes = ceil(nproc / max(ppn, 1))
568+
if nproc > total_capacity:
569+
raise BadResourceRequestError(
570+
comp_id, task_id, requested_nodes, max(1, requested_nodes - len(self.nodes))
571+
)
572+
if not self.check_gpus(ppn, task_gpp):
573+
raise GpuResourceRequestMismatchError(comp_id, task_id, ppn, task_gpp, self.gpn)
574+
575+
# Plan first so a failed request never consumes a partial allocation.
576+
plan = []
577+
remaining = nproc
578+
for name in self.avail_nodes:
579+
node = self.nodes[name]
580+
available = node.avail_cores
581+
if whole_nodes:
582+
available = available if available == node.total_cores else 0
583+
elif whole_socks:
584+
available = sum(
585+
sock.avail_cores
586+
for sock in node.sockets
587+
if sock.avail_cores == sock.total_cores
588+
)
589+
ranks = min(ppn, available // cpp, remaining)
590+
if ranks:
591+
plan.append((name, ranks))
592+
remaining -= ranks
593+
if not remaining:
594+
break
595+
if remaining:
596+
raise InsufficientResourcesError(
597+
comp_id, task_id, requested_nodes, ceil(remaining / ppn)
598+
)
599+
600+
entries = []
601+
cores_allocated = 0
602+
for name, ranks in plan:
603+
node = self.nodes[name]
604+
count, cores = node.allocate(whole_nodes, whole_socks, task_id, comp_id, ranks * cpp)
605+
entries.append((name, cores))
606+
cores_allocated += count
607+
if name not in self.alloc_nodes:
608+
self.alloc_nodes.append(name)
609+
if not node.avail_cores:
610+
self.avail_nodes.remove(name)
611+
self.processes += nproc
612+
self.alloc_cores += cores_allocated
613+
self.avail_cores -= cores_allocated
614+
self.active_tasks[task_id] = (comp_id, nproc, cores_allocated)
615+
self.report_rm_status('allocation for DVM task %d' % task_id)
616+
return Allocation(
617+
partial_node=not whole_nodes,
618+
nodelist=[name for name, _ in plan],
619+
corelist=None if whole_nodes else entries,
620+
ppn=ppn,
621+
max_ppn=self.max_ppn,
622+
cpp=task_cpp,
623+
accurate_nodes=self.accurate_nodes,
624+
cores_allocated=cores_allocated,
625+
)
626+
528627
def check_whole_node_cap(self, nproc, ppn):
529628
"""
530629
Determine if it is currently possible to allocate *nproc* processes

‎ipsframework/services.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def launch_task(self, nproc: int, working_dir: str, binary: str, *args, **keywor
956956
manage how the binary is launched. Keywords may be the following:
957957
958958
* *task_ppn* : the processes per node value for this task
959-
* *task_cpp* : the cores per process, only used when ``MPIRUN=srun`` commands
959+
* *task_cpp* : cores per process
960960
* *task_gpp* : the gpus per process, only used when ``MPIRUN=srun`` commands
961961
* *omp* : If ``True`` the task will be launch with the correct OpenMP environment
962962
variables set, only used when ``MPIRUN=srun``

‎ipsframework/task_manager.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ def build_launch_cmd(
460460
str(nproc),
461461
]
462462
)
463+
if cpp:
464+
cmd += f' --map-by slot:PE={cpp}:CORECPUS --bind-to core'
463465
elif smp_node:
464466
cmd = ' '.join([mpicmd, nproc_flag, str(nproc)])
465467
else:

‎tests/new/test_resource_manager.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,36 @@ def test_allocations(tmpdir):
375375
assert lines[6] == 'core: 1 - task_id: 0 - owner: comp0'
376376
assert lines[7] == 'core: 2 - task_id: 0 - owner: comp0'
377377
assert lines[8] == 'core: 3 - task_id: 0 - owner: comp0'
378+
379+
380+
@pytest.mark.parametrize('cpp', [2, 4])
381+
def test_dvm_complete_ranks(tmp_path, cpp: int) -> None:
382+
"""Ensure ranks cannot be split across nodes with fragmented capacity.
383+
384+
:param tmp_path: Isolated resource report directory.
385+
:param cpp: Physical cores per MPI rank.
386+
:returns: None.
387+
"""
388+
cm = mock.Mock()
389+
cm.fwk_sim_name = 'test'
390+
cm.sim_map = {'test': mock.Mock(sim_root=str(tmp_path))}
391+
cm.get_platform_parameter.return_value = 'HOST'
392+
rm = ResourceManager(mock.Mock())
393+
rm.initialize(mock.Mock(), mock.Mock(), cm, cmd_nodes=2, cmd_ppn=4)
394+
cm.get_platform_parameter.return_value = 'OPENMPI-DVM'
395+
# One rank on each node leaves fewer than cpp free cores on each.
396+
rm.get_allocation('first', 2, 1, False, False, task_ppn=1, task_cpp=3)
397+
with pytest.raises(InsufficientResourcesError):
398+
rm.get_allocation('second', 1, 2, False, False, task_cpp=cpp)
399+
assert rm.avail_cores == 2
400+
assert rm.processes == 2
401+
rm.release_allocation(1, 0)
402+
result = rm.get_allocation('second', 2, 3, False, False, task_cpp=cpp)
403+
assert result.cores_allocated == 2 * cpp
404+
assert result.ppn == min(2, 4 // cpp)
405+
rm.release_allocation(3, 0)
406+
assert rm.avail_cores == 8
407+
for invalid in (-1, 1.5, '4'):
408+
with pytest.raises(ValueError):
409+
rm.get_allocation('invalid', 1, 4, False, False, task_cpp=invalid)
410+
rm.reporting_file.close()

‎tests/new/test_task_manager.py‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,3 +1056,65 @@ def test_build_launch_cmd_prun_uses_explicit_dvm_uri(monkeypatch):
10561056
monkeypatch.setenv('IPS_DVM_URI_FILE', '/work/dvm.uri.nid001.42')
10571057
cmd, _ = tm.build_launch_cmd(**kwargs)
10581058
assert cmd.startswith('/usr/bin/prun --dvm-uri file:/work/dvm.uri.nid001.42 ')
1059+
1060+
1061+
@pytest.mark.parametrize('cpp', [0, 1, 4])
1062+
@pytest.mark.parametrize('whole_nodes,whole_socks', [(False, False), (False, True), (True, True)])
1063+
def test_dvm_task_core_budget(
1064+
tmp_path, monkeypatch, cpp: int, whole_nodes: bool, whole_socks: bool
1065+
) -> None:
1066+
"""Exercise allocation, command generation, exhaustion, and release together.
1067+
1068+
:param tmp_path: Isolated resource report directory.
1069+
:param monkeypatch: Fixture setting the DVM rendezvous file.
1070+
:param cpp: Requested cores per rank, including the default sentinel.
1071+
:param whole_nodes: Whether to reserve whole nodes.
1072+
:param whole_socks: Whether to reserve whole sockets.
1073+
:returns: None.
1074+
"""
1075+
fwk = mock.Mock()
1076+
cm = mock.Mock()
1077+
cm.fwk_sim_name = 'test'
1078+
cm.sim_map = {'test': mock.Mock(sim_root=str(tmp_path))}
1079+
cm.get_platform_parameter.return_value = 'HOST'
1080+
tm = TaskManager(fwk)
1081+
rm = ResourceManager(fwk)
1082+
tm.initialize(mock.Mock(), rm, cm)
1083+
rm.initialize(mock.Mock(), tm, cm, cmd_nodes=1, cmd_ppn=4)
1084+
cm.get_platform_parameter.return_value = 'OPENMPI-DVM'
1085+
tm.task_launch_cmd = 'mpirun'
1086+
tm.mpicmd = '/usr/bin/prun'
1087+
monkeypatch.setenv('IPS_DVM_URI_FILE', '/tmp/test-dvm-uri')
1088+
task_id, cmd, _, reserved = tm._init_task(
1089+
'component',
1090+
1,
1091+
'executable',
1092+
str(tmp_path),
1093+
0,
1094+
cpp,
1095+
False,
1096+
0,
1097+
whole_nodes,
1098+
whole_socks,
1099+
[],
1100+
None,
1101+
)
1102+
assert '-np 1' in cmd
1103+
if cpp:
1104+
assert f'--map-by slot:PE={cpp}:CORECPUS --bind-to core' in cmd
1105+
else:
1106+
assert '--map-by' not in cmd
1107+
expected = 4 if whole_nodes or whole_socks else (cpp or 1)
1108+
assert reserved == expected
1109+
assert rm.alloc_cores == expected
1110+
assert rm.processes == 1
1111+
with pytest.raises(InsufficientResourcesError):
1112+
rm.get_allocation('other', 1, 99, False, False, task_cpp=4)
1113+
assert rm.alloc_cores == expected
1114+
rm.release_allocation(task_id, 0)
1115+
assert rm.avail_cores == 4
1116+
assert rm.alloc_cores == rm.processes == 0
1117+
with pytest.raises(BadResourceRequestError):
1118+
rm.get_allocation('other', 1, 100, False, False, task_cpp=5)
1119+
assert rm.avail_cores == 4
1120+
rm.reporting_file.close()

0 commit comments

Comments
 (0)