Skip to content

Commit 2a9c0f8

Browse files
committed
support multiple gres per node
1 parent 81b0759 commit 2a9c0f8

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

ansible/roles/openondemand/filter_plugins/filters.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,47 @@
55
# Apache 2 License
66

77
def to_gres_options(stdout):
8+
""" Convert sinfo output into a list of GRES options for an Ondemand `select`
9+
widget.
10+
11+
Parameters:
12+
stdout: Text from `sinfo --noheader --format "%R %G"`
13+
14+
Returns a list of [label, value] items. This is the format required for
15+
the `options` attribute of a `select` widget [1] where:
16+
- value (str) is a valid entry for the srun/sbatch --gres option [2].
17+
- label (str) is a user-friendly label with gres name, gres type and
18+
maximum gres count where relevant.
19+
The returned list will always include an entry for no GRES request.
20+
21+
For example with a single GRES defined of `gpu:H200:8' the following
22+
entries are returned:
23+
- ['None', 'none']
24+
- ['Any gpu (max count: 8)', 'gpu']
25+
- ['H200 gpu' (max count: 8)', 'gpu:H200']
26+
27+
[1] https://osc.github.io/ood-documentation/latest/how-tos/app-development/interactive/form-widgets.html#form-widgets
28+
[2] https://slurm.schedmd.com/srun.html#OPT_gres
29+
"""
830
gres_data = {} # k=gres_opt, v=[label, max_count] # where gres_opt is what would be passed to --gres
931
gres_data['none'] = ['None', 0]
1032

1133
for line in stdout.splitlines():
12-
if '(null)' in line:
13-
continue
14-
partition, gres = line.split(' ')
15-
gres_name, gres_type, gres_number_cores = gres.split(':', maxsplit=2)
16-
gres_count, gres_cores = gres_number_cores.split('(')
17-
18-
for gres_opt in [gres_name, f'{gres_name}:{gres_type}']:
19-
if gres_opt not in gres_data:
20-
label = f'{gres_type} {gres_name}' if ':' in gres_opt else f'Any {gres_opt}'
21-
gres_data[gres_opt] = [label, gres_count]
22-
elif gres_count > gres_data[gres_name][1]:
23-
gres_data[gres_opt][1] = gres_count
34+
partition, gres_definitions = line.split() # e.g. 'part1 gpu:H200:8(S:0-1),test:foo:1', or 'part2 (null)'
35+
for gres in gres_definitions.split(','):
36+
if '(null)' in gres:
37+
continue
38+
gres_name, gres_type, gres_count_cores = gres.split(':', maxsplit=2)
39+
gres_count = gres_count_cores.split('(')[0] # may or may not have the e.g. '(S:0-1)' core definition
40+
for gres_opt in [gres_name, f'{gres_name}:{gres_type}']:
41+
if gres_opt not in gres_data:
42+
label = f'{gres_type} {gres_name}' if ':' in gres_opt else f'Any {gres_opt}'
43+
gres_data[gres_opt] = [label, gres_count]
44+
elif len(gres_data[gres_name]) == 1:
45+
raise ValueError(gres_data[gres_name])
46+
elif gres_count > gres_data[gres_name][1]:
47+
gres_data[gres_opt][1] = gres_count
48+
2449
gres_options = []
2550
for gres_opt in gres_data:
2651
max_count = gres_data[gres_opt][1]

ansible/roles/openondemand/tasks/main.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
command:
4444
cmd: sinfo --noheader --format "%R %G" # can't use , or : as separator
4545
register: _openondemand_sinfo_gres
46-
# partition_name gres
47-
# e.g.
48-
# gpu gpu:H200:8(S:0-1)
49-
# normal (null)
50-
# no_smi (null)
5146

5247
- ansible.builtin.include_role:
5348
name: osc.ood

environments/common/inventory/group_vars/all/openondemand.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ openondemand_apps_jupyter_default:
204204
extra_jupyter_args: ""
205205
bc_queue:
206206
value: "{{ openondemand_jupyter_partition | default(none) }}"
207-
node: ""
208207
submit: |
209208
---
210209
batch_connect:

0 commit comments

Comments
 (0)