Skip to content

Commit 8d9a83b

Browse files
authored
fix gpu templates for real though (#1077)
1 parent 6c380cd commit 8d9a83b

File tree

16 files changed

+47
-74
lines changed

16 files changed

+47
-74
lines changed

toolchain/mfc/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def add_common_arguments(p: argparse.ArgumentParser, mask = None):
5959
if "m" not in mask:
6060
for f in dataclasses.fields(config):
6161
if f.name == 'gpu':
62-
p.add_argument(f"--{f.name}", action="store", nargs='?', const= gpuConfigOptions.ACC.value,default=gpuConfigOptions.ACC.value, dest=f.name, choices=[e.value for e in gpuConfigOptions], help=f"Turn the {f.name} option to OpenACC or OpenMP.")
62+
p.add_argument(f"--{f.name}", action="store", nargs='?', const= gpuConfigOptions.ACC.value,default=gpuConfigOptions.NONE.value, dest=f.name, choices=[e.value for e in gpuConfigOptions], help=f"Turn the {f.name} option to OpenACC or OpenMP.")
6363
p.add_argument(f"--no-{f.name}", action="store_const", const = gpuConfigOptions.NONE.value, dest=f.name, help=f"Turn the {f.name} option OFF.")
6464
continue
6565
p.add_argument( f"--{f.name}", action="store_true", help=f"Turn the {f.name} option ON.")

toolchain/mfc/run/run.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from ..build import get_targets, build, REQUIRED_TARGETS, SIMULATION
99
from ..printer import cons
10-
from ..state import ARG, ARGS, CFG
10+
from ..state import ARG, ARGS, CFG, gpuConfigOptions
1111
from ..common import MFCException, isspace, file_read, does_command_exist
1212
from ..common import MFC_TEMPLATE_DIR, file_write, system, MFC_ROOT_DIR
1313
from ..common import format_list_to_string, file_dump_yaml
@@ -99,6 +99,20 @@ def __generate_job_script(targets, case: input.MFCInputFile):
9999
'HIP_VISIBLE_DEVICES': gpu_ids
100100
})
101101

102+
# Compute GPU mode booleans for templates
103+
gpu_mode = ARG('gpu')
104+
105+
# Validate gpu_mode is one of the expected values
106+
valid_gpu_modes = {e.value for e in gpuConfigOptions}
107+
if gpu_mode not in valid_gpu_modes:
108+
raise MFCException(
109+
f"Invalid GPU mode '{gpu_mode}'. Must be one of: {', '.join(sorted(valid_gpu_modes))}"
110+
)
111+
112+
gpu_enabled = gpu_mode != gpuConfigOptions.NONE.value
113+
gpu_acc = gpu_mode == gpuConfigOptions.ACC.value
114+
gpu_mp = gpu_mode == gpuConfigOptions.MP.value
115+
102116
content = __get_template().render(
103117
**{**ARGS(), 'targets': targets},
104118
ARG=ARG,
@@ -107,7 +121,10 @@ def __generate_job_script(targets, case: input.MFCInputFile):
107121
MFC_ROOT_DIR=MFC_ROOT_DIR,
108122
SIMULATION=SIMULATION,
109123
qsystem=queues.get_system(),
110-
profiler=shlex.join(__profiler_prepend())
124+
profiler=shlex.join(__profiler_prepend()),
125+
gpu_enabled=gpu_enabled,
126+
gpu_acc=gpu_acc,
127+
gpu_mp=gpu_mp
111128
)
112129

113130
file_write(__job_script_filepath(), content)

toolchain/templates/bridges2.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
% if account:
1515
#SBATCH --account="${account}"
1616
% endif
17-
% if gpu:
17+
% if gpu_enabled:
1818
#SBATCH --gpu-bind=verbose,closest
1919
#SBATCH --gres=gpu:v100-16:${tasks_per_node}
2020
% endif
@@ -31,7 +31,7 @@ ${helpers.template_prologue()}
3131

3232
ok ":) Loading modules:\n"
3333
cd "${MFC_ROOT_DIR}"
34-
. ./mfc.sh load -c b -m ${'g' if gpu else 'c'}
34+
. ./mfc.sh load -c b -m ${'g' if gpu_enabled else 'c'}
3535
cd - > /dev/null
3636
echo
3737

toolchain/templates/carpenter-cray.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ${helpers.template_prologue()}
2525

2626
ok ":) Loading modules:\n"
2727
cd "${MFC_ROOT_DIR}"
28-
. ./mfc.sh load -c cc -m ${'g' if gpu else 'c'}
28+
. ./mfc.sh load -c cc -m ${'g' if gpu_enabled else 'c'}
2929
cd - > /dev/null
3030
echo
3131

toolchain/templates/carpenter.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ${helpers.template_prologue()}
2525

2626
ok ":) Loading modules:\n"
2727
cd "${MFC_ROOT_DIR}"
28-
. ./mfc.sh load -c c -m ${'g' if gpu else 'c'}
28+
. ./mfc.sh load -c c -m ${'g' if gpu_enabled else 'c'}
2929
cd - > /dev/null
3030
echo
3131

toolchain/templates/default.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ if engine == 'batch':
4848
(set -x; ${profiler} \
4949
jsrun --nrs ${tasks_per_node*nodes} \
5050
--cpu_per_rs 1 \
51-
--gpu_per_rs ${1 if gpu else 0} \
51+
--gpu_per_rs ${1 if gpu_enabled else 0} \
5252
--tasks_per_rs 1 \
5353
"${target.get_install_binpath(case)}")
5454
elif [ "$binary" == "srun" ]; then

toolchain/templates/delta.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
% if account:
1515
#SBATCH --account="${account}"
1616
% endif
17-
% if gpu:
17+
% if gpu_enabled:
1818
#SBATCH --gpus-per-node=${tasks_per_node}
1919
#SBATCH --mem=208G
2020
#SBATCH --gpu-bind=closest
@@ -32,7 +32,7 @@ ${helpers.template_prologue()}
3232

3333
ok ":) Loading modules:\n"
3434
cd "${MFC_ROOT_DIR}"
35-
. ./mfc.sh load -c d -m ${'g' if gpu else 'c'}
35+
. ./mfc.sh load -c d -m ${'g' if gpu_enabled else 'c'}
3636
cd - > /dev/null
3737
echo
3838

toolchain/templates/deltaai.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
% if account:
1515
#SBATCH --account="${account}"
1616
% endif
17-
% if gpu:
17+
% if gpu_enabled:
1818
#SBATCH --gpus-per-node=${tasks_per_node}
1919
#SBATCH --mem=208G
2020
#SBATCH --gpu-bind=closest
@@ -32,7 +32,7 @@ ${helpers.template_prologue()}
3232

3333
ok ":) Loading modules:\n"
3434
cd "${MFC_ROOT_DIR}"
35-
. ./mfc.sh load -c dai -m ${'g' if gpu else 'c'}
35+
. ./mfc.sh load -c dai -m ${'g' if gpu_enabled else 'c'}
3636
cd - > /dev/null
3737
echo
3838

toolchain/templates/frontier.mako

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#SBATCH --time=${walltime}
1111
#SBATCH --cpus-per-task=7
1212
#SBATCH -C nvme
13-
% if gpu != 'no':
13+
% if gpu_enabled:
1414
#SBATCH --gpus-per-task=1
1515
#SBATCH --gpu-bind=closest
1616
% endif
@@ -34,18 +34,18 @@ ${helpers.template_prologue()}
3434
ok ":) Loading modules:\n"
3535
cd "${MFC_ROOT_DIR}"
3636
% if engine == 'batch':
37-
. ./mfc.sh load -c f -m ${'g' if gpu != 'no' else 'c'}
37+
. ./mfc.sh load -c f -m ${'g' if gpu_enabled else 'c'}
3838
% endif
3939
cd - > /dev/null
4040
echo
4141

42-
% if gpu != 'no':
42+
% if gpu_enabled:
4343
export MPICH_GPU_SUPPORT_ENABLED=1
4444
% else:
4545
export MPICH_GPU_SUPPORT_ENABLED=0
4646
% endif
4747

48-
%if unified:
48+
% if unified:
4949
export CRAY_ACC_USE_UNIFIED_MEM=1
5050
% endif
5151

@@ -66,7 +66,7 @@ ulimit -s unlimited
6666
% if engine == 'interactive':
6767
--unbuffered --nodes ${nodes} --ntasks-per-node ${tasks_per_node} \
6868
--cpus-per-task 7 \
69-
% if gpu != 'no':
69+
% if gpu_enabled:
7070
--gpus-per-task 1 --gpu-bind closest \
7171
% endif
7272
${profiler} "${target.get_install_binpath(case)}")

toolchain/templates/hipergator.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#SBATCH --output="${name}.out"
1010
#SBATCH --time=${walltime}
1111
#SBATCH --cpus-per-task=7
12-
% if gpu:
12+
% if gpu_enabled:
1313
#SBATCH --gpus-per-task=1
1414
#SBATCH --gpu-bind=closest
1515
% endif
@@ -35,7 +35,7 @@ ${helpers.template_prologue()}
3535
ok ":) Loading modules:\n"
3636
cd "${MFC_ROOT_DIR}"
3737
% if engine == 'batch':
38-
. ./mfc.sh load -c h -m ${'g' if gpu else 'c'}
38+
. ./mfc.sh load -c h -m ${'g' if gpu_enabled else 'c'}
3939
% endif
4040
cd - > /dev/null
4141
echo

0 commit comments

Comments
 (0)