Skip to content

Commit 8953247

Browse files
authored
Refactor supports_gpu_directives to focus on GresTypes (#556)
1 parent 2f23f0d commit 8953247

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

src/cloudai/systems/slurm/slurm_system.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,13 @@ def supports_gpu_directives(self) -> bool:
178178
self.supports_gpu_directives_cache = True
179179
return True
180180

181-
has_gres_gpu = False
182-
has_gpu_gres_type = False
183-
184181
for line in stdout.splitlines():
185-
if "AccountingStorageTRES" in line and "gres/gpu" in line:
186-
has_gres_gpu = True
187-
if "GresTypes" in line and "gpu" in line and "(null)" not in line:
188-
has_gpu_gres_type = True
182+
if "GresTypes" in line and "gpu" in line:
183+
self.supports_gpu_directives_cache = True
184+
return True
189185

190-
self.supports_gpu_directives_cache = has_gres_gpu and has_gpu_gres_type
191-
return self.supports_gpu_directives_cache
186+
self.supports_gpu_directives_cache = False
187+
return False
192188

193189
@field_serializer("install_path", "output_path")
194190
def _path_serializer(self, v: Path) -> str:

tests/test_slurm_system.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,33 +535,29 @@ def test_per_step_isolation(self, mock_get_nodes: Mock, slurm_system: SlurmSyste
535535
@pytest.mark.parametrize(
536536
"scontrol_output,expected_support",
537537
[
538-
# Case 1: gres/gpu in AccountingStorageTRES and gpu in GresTypes - should be supported
538+
# Case 1: GresTypes includes gpu - should be supported
539539
(
540540
"""Configuration data as of 2023-06-14T16:28:09
541-
AccountingStorageTRES = cpu,mem,energy,node,billing,fs/disk,vmem,pages,gres/gpu,gres/gpumem,gres/gpuutil
542541
GresTypes = gpu""",
543542
True,
544543
),
545-
# Case 2: gres/gpu in AccountingStorageTRES but GresTypes is (null) - should NOT be supported
544+
# Case 2: GresTypes is (null) - should NOT be supported
546545
(
547546
"""Configuration data as of 2023-06-14T16:28:09
548-
AccountingStorageTRES = cpu,mem,energy,node,billing,fs/disk,vmem,pages,gres/gpu,gres/gpumem,gres/gpuutil
549547
GresTypes = (null)""",
550548
False,
551549
),
552-
# Case 3: No gres/gpu in AccountingStorageTRES - should NOT be supported
550+
# Case 3: GresTypes does not include gpu - should NOT be supported
553551
(
554552
"""Configuration data as of 2023-06-14T16:28:09
555-
AccountingStorageTRES = cpu,mem,energy,node,billing,fs/disk,vmem,pages
556-
GresTypes = gpu""",
553+
GresTypes = cpu""",
557554
False,
558555
),
559-
# Case 4: No gres/gpu in AccountingStorageTRES and GresTypes is (null) - should NOT be supported
556+
# Case 4: GresTypes includes multiple types including gpu - should be supported
560557
(
561558
"""Configuration data as of 2023-06-14T16:28:09
562-
AccountingStorageTRES = cpu,mem,energy,node,billing,fs/disk,vmem,pages
563-
GresTypes = (null)""",
564-
False,
559+
GresTypes = cpu,gpu,fpga""",
560+
True,
565561
),
566562
],
567563
)
@@ -571,3 +567,14 @@ def test_supports_gpu_directives(
571567
):
572568
mock_fetch_command_output.return_value = (scontrol_output, "")
573569
assert slurm_system.supports_gpu_directives == expected_support
570+
571+
572+
@pytest.mark.parametrize(
573+
"cache_value",
574+
[True, False],
575+
)
576+
@patch("cloudai.systems.slurm.slurm_system.SlurmSystem.fetch_command_output")
577+
def test_supports_gpu_directives_cache(mock_fetch_command_output, cache_value: bool, slurm_system: SlurmSystem):
578+
slurm_system.supports_gpu_directives_cache = cache_value
579+
assert slurm_system.supports_gpu_directives is cache_value
580+
mock_fetch_command_output.assert_not_called()

0 commit comments

Comments
 (0)