#!/usr/bin/env expect ############################################################################ # Purpose: Test of Slurm functionality # Test --mem-per-gpu option ############################################################################ # Copyright (C) 2018 SchedMD LLC # Written by Morris Jette # # This file is part of Slurm, a resource management program. # For details, see . # Please also read the included file: DISCLAIMER. # # Slurm is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation; either version 2 of the License, or (at your option) # any later version. # # Slurm is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along # with Slurm; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ############################################################################ source ./globals set exit_code 0 set file_in "test$test_id.input" proc run_gpu_per_job { mem_per_gpu } { global exit_code file_in number srun test_id set mem_size 0 set srun_pid [spawn $srun --gpus=1 --mem-per-gpu=$mem_per_gpu -J "test$test_id" -t1 ./$file_in] expect { -re "TRES=cpu=($number),mem=($number)M" { set mem_size $expect_out(2,string) exp_continue } timeout { log_error "srun not responding" slow_kill $srun_pid set exit_code 1 } eof { wait } } if {$mem_size != $mem_per_gpu} { log_error "srun --mem-per-gpu failure ($mem_size != $mem_per_gpu)" set exit_code 1 } } proc run_gpu_per_node { mem_per_gpu } { global exit_code file_in number srun test_id set mem_size 0 set srun_pid [spawn $srun --gpus-per-node=1 -N1 --mem-per-gpu=$mem_per_gpu -J "test$test_id" -t1 ./$file_in] expect { -re "TRES=cpu=($number),mem=($number)M" { set mem_size $expect_out(2,string) exp_continue } timeout { log_error "srun not responding" slow_kill $srun_pid set exit_code 1 } eof { wait } } if {$mem_size != $mem_per_gpu} { log_error "srun --mem-per-gpu failure ($mem_size != $mem_per_gpu)" set exit_code 1 } } proc run_gpu_per_task { mem_per_gpu gpu_cnt } { global exit_code file_in number srun test_id set mem_size 0 set srun_pid [spawn $srun --gpus-per-task=$gpu_cnt -n1 --mem-per-gpu=$mem_per_gpu -J "test$test_id" -t1 ./$file_in] expect { -re "TRES=cpu=($number),mem=($number)M" { set mem_size $expect_out(2,string) exp_continue } timeout { log_error "srun not responding" slow_kill $srun_pid set exit_code 1 } eof { wait } } set mem_target [expr $mem_per_gpu * $gpu_cnt] if {$mem_size != $mem_target} { log_error "srun --mem-per-gpu failure ($mem_size != $mem_target)" set exit_code 1 } } if {[test_cons_tres]} { log_debug "Valid configuration, using select/cons_tres" } else { skip "This test is only compatible with select/cons_tres" } if {![test_select_type_params "MEMORY"]} { skip "This test requires memory allocation management" } set gpu_cnt [get_highest_gres_count 1 "gpu"] if {$gpu_cnt < 0} { fail "Error getting GPU count" } if {$gpu_cnt < 1} { skip "This test requires 1 or more GPUs in the default partition" } set node_name [get_nodes_by_request "--gres=gpu:1 -n1 -t1"] if { [llength $node_name] != 1 } { skip "This test need to be able to submit jobs with at least --gres=gpu:1" } set node_memory [get_node_param $node_name "RealMemory"] set nb_nodes [get_node_cnt_in_part] log_debug "GPU count is $gpu_cnt" log_debug "Memory Size is $node_memory" log_debug "Node count in partition default partition is $nb_nodes" # # Build input script file # exec $bin_rm -f $file_in make_bash_script $file_in "echo HOST:\$SLURMD_NODENAME CUDA_VISIBLE_DEVICES:\$CUDA_VISIBLE_DEVICES $scontrol show job \$SLURM_JOB_ID exit 0" # # Run test job with global GPU count # Increase mem_per_gpu value 10x on each iteration # for {set inx 12} {$inx <= $node_memory} {set inx [expr $inx * 10]} { run_gpu_per_job $inx if {$exit_code != 0} { break } } # # Run test job with gpus-per-node count # Increase mem_per_gpu value 10x on each iteration # for {set inx 12} {$inx <= $node_memory} {set inx [expr $inx * 10]} { run_gpu_per_node $inx if {$exit_code != 0} { break } } # # Run test job with gpus-per-task count and one GPU # Increase mem_per_gpu value 10x on each iteration # for {set inx 12} {$inx <= $node_memory} {set inx [expr $inx * 10]} { run_gpu_per_task $inx 1 if {$exit_code != 0} { break } } # # Run test job with gpus-per-task count and two GPUs # Increase mem_per_gpu value 10x on each iteration # if {$gpu_cnt > 1} { for {set inx 13} {$inx <= [expr $node_memory / 2]} \ {set inx [expr $inx * 10]} { run_gpu_per_task $inx 2 if {$exit_code != 0} { break } } } # # Test heterogeneous GPU allocation (2 GPUs on one node, 1 GPU on another node) # if {$gpu_cnt > 1 && $nb_nodes > 1} { set mem_alloc 0 set gpu_target 3 set mem_spec 13 set node_count 0 set srun_pid [spawn $srun --gpus=$gpu_target -N2 --mem-per-gpu=$mem_spec -J "test$test_id" -t1 ./$file_in] expect { -re "NumNodes=($number)" { set node_count $expect_out(1,string) exp_continue } -re "TRES=cpu=($number),mem=($number)M" { set mem_alloc $expect_out(2,string) exp_continue } timeout { log_error "srun not responding" slow_kill $srun_pid set exit_code 1 } eof { wait } } set node_target 2 if {$node_count < $node_target} { log_error "srun --mem-per-gpu failure, bad node count ($node_count < $node_target)" set exit_code 1 } set mem_target [expr $mem_spec * $gpu_target] if {$mem_alloc != $mem_target} { log_error "srun --mem-per-gpu failure ($mem_alloc != $mem_target)" set exit_code 1 } } # # Run test with --gpus=2 and mem_per_gpu value that pushed job to 2 nodes # if {$gpu_cnt > 1 && $nb_nodes > 1} { set mem_alloc 0 set node_count 0 set mem_spec [expr $node_memory / 2 + 1] set srun_pid [spawn $srun --gpus=2 --mem-per-gpu=$mem_spec -J "test$test_id" -t1 ./$file_in] expect { -re "NumNodes=($number)" { set node_count $expect_out(1,string) exp_continue } -re "TRES=cpu=($number),mem=($number)M" { set mem_alloc $expect_out(2,string) exp_continue } timeout { log_error "srun not responding" slow_kill $srun_pid set exit_code 1 } eof { wait } } set node_target 2 if {$node_count < $node_target} { log_error "srun --mem-per-gpu failure, bad node count ($node_count < $node_target)" set exit_code 1 } set mem_target [expr $mem_spec * $node_target] if {$mem_alloc != $mem_target} { log_error "srun --mem-per-gpu failure ($mem_alloc != $mem_target)" set exit_code 1 } } if {$exit_code == 0} { exec $bin_rm -f $file_in } else { fail "Test failed due to previous errors (\$exit_code = $exit_code)" }