Skip to content

Commit f4eb190

Browse files
authored
Merge pull request GoogleCloudPlatform#4546 from sharabiani/gres-gpu-type
Add GPU type to Slurm's gres.config
2 parents 3f75e9b + c89825a commit f4eb190

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

  • community/modules/scheduler/schedmd-slurm-gcp-v6-controller/modules/slurm_files/scripts

community/modules/scheduler/schedmd-slurm-gcp-v6-controller/modules/slurm_files/scripts/conf.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,28 +367,36 @@ def install_jobsubmit_lua(lkp: util.Lookup) -> None:
367367
util.chown_slurm(conf_file, 0o600)
368368

369369

370-
def gen_cloud_gres_conf(lkp: util.Lookup) -> None:
371-
"""generate cloud_gres.conf"""
370+
def gen_cloud_gres_conf_lines(lkp: util.Lookup) -> str:
371+
"""generate cloud_gres.conf's content"""
372372

373373
gpu_nodes = defaultdict(list)
374374
for nodeset in lkp.cfg.nodeset.values():
375375
ti = lkp.template_info(nodeset.instance_template)
376376
gpu_count = ti.gpu.count if ti.gpu else 0
377+
gpu_type = ti.gpu.type if ti.gpu else None
377378
if gpu_count:
378-
gpu_nodes[gpu_count].append(lkp.nodelist(nodeset))
379+
gpu_nodes[(gpu_count, gpu_type)].append(lkp.nodelist(nodeset))
379380

380381
lines = [
381382
dict_to_conf(
382383
{
383384
"NodeName": names,
384385
"Name": "gpu",
385-
"File": "/dev/nvidia{}".format(f"[0-{i-1}]" if i > 1 else "0"),
386+
"Type": gpu_type,
387+
"File": "/dev/nvidia{}".format(f"[0-{gpu_count-1}]" if gpu_count > 1 else "0"),
386388
}
387389
)
388-
for i, names in gpu_nodes.items()
390+
for (gpu_count, gpu_type), names in gpu_nodes.items()
389391
]
390392
lines.append("\n")
391-
content = FILE_PREAMBLE + "\n".join(lines)
393+
return "\n".join(lines)
394+
395+
396+
def gen_cloud_gres_conf(lkp: util.Lookup) -> None:
397+
"""create cloud_gres.conf file"""
398+
399+
content = FILE_PREAMBLE + gen_cloud_gres_conf_lines(lkp)
392400

393401
conf_file = lkp.etc_dir / "cloud_gres.conf"
394402
conf_file.write_text(content)

community/modules/scheduler/schedmd-slurm-gcp-v6-controller/modules/slurm_files/scripts/tests/test_conf.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,25 @@ def test_conflines(cfg, want):
190190

191191
cfg.cloud_parameters = addict.Dict(cfg.cloud_parameters)
192192
assert conf.conflines(util.Lookup(cfg)) == want
193+
194+
195+
@pytest.mark.parametrize(
196+
"cfg,gputype,gpucount,want",
197+
[
198+
(TstCfg(),
199+
"",
200+
0,
201+
"\n"),
202+
(TstCfg(
203+
nodeset={"turbo": TstNodeset("turbo")}
204+
),
205+
"Popov",
206+
8,
207+
"Name=gpu Type=Popov File=/dev/nvidia[0-7]\n\n"),
208+
])
209+
def test_gen_cloud_gres_conf_lines(cfg, gputype, gpucount, want):
210+
lkp = util.Lookup(cfg)
211+
lkp.template_info = Mock(return_value=TstTemplateInfo(
212+
gpu=util.AcceleratorInfo(type=gputype, count=gpucount)
213+
))
214+
assert conf.gen_cloud_gres_conf_lines(lkp) == want

0 commit comments

Comments
 (0)