Skip to content

Commit

Permalink
define gpus_from_gres in Batch
Browse files Browse the repository at this point in the history
  • Loading branch information
lukew3 committed Apr 8, 2022
1 parent 9fcbd52 commit 625edde
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/ood_core/job/adapters/slurm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ def initialize(cluster: nil, bin: nil, conf: nil, bin_overrides: {}, submit_host
# Get a ClusterInfo object containing information about the given cluster
# @return [ClusterInfo] object containing cluster details
def get_cluster_info
def gpus_from_gres(gres)
gres.to_s.scan(/gpu:[^,]*(\d+)/).flatten.map(&:to_i).sum
end
node_cpu_info = call("sinfo", "-aho %A/%D/%C").strip.split('/')
gres_length = call("sinfo", "-o %G").lines.map(&:strip).map(&:length).max + 2
gres_lines = call("sinfo", "-ahNO ,nodehost,gres:#{gres_length},gresused:#{gres_length}")
Expand Down Expand Up @@ -362,6 +359,10 @@ def squeue_attrs_for_info_attrs(attrs)
}.fetch(a, a)
}.flatten
end

def gpus_from_gres(gres)
gres.to_s.scan(/gpu:[^,]*(\d+)/).flatten.map(&:to_i).sum
end
end

# Mapping of state codes for Slurm
Expand Down Expand Up @@ -642,10 +643,6 @@ def get_state(st)
STATE_MAP.fetch(st, :undetermined)
end

def gpus_from_gres(gres)
gres.to_s.scan(/gpu:[^,]*(\d+)/).flatten.map(&:to_i).sum
end

# Parse hash describing Slurm job status
def parse_job_info(v)
allocated_nodes = parse_nodes(v[:node_list])
Expand Down Expand Up @@ -673,7 +670,7 @@ def parse_job_info(v)
submission_time: v[:submit_time] ? Time.parse(v[:submit_time]) : nil,
dispatch_time: (v[:start_time].nil? || v[:start_time] == "N/A") ? nil : Time.parse(v[:start_time]),
native: v,
gpus: gpus_from_gres(v[:gres])
gpus: @batch.gpus_from_gres(v[:gres])
)
end

Expand Down

0 comments on commit 625edde

Please sign in to comment.