Skip to content

Commit

Permalink
move gpus_from_gres to slurm before batch
Browse files Browse the repository at this point in the history
  • Loading branch information
lukew3 committed Apr 8, 2022
1 parent 8b43fb2 commit 7eca11b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/ood_core/job/adapters/slurm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class Slurm < Adapter
using Refinements::HashExtensions
using Refinements::ArrayExtensions

# Get integer representing the number of gpus used by a node or job,
# calculated from gres string
# @return [Integer] the number of gpus in gres
def gpus_from_gres(gres)
gres.to_s.scan(/gpu:[^,]*(\d+)/).flatten.map(&:to_i).sum
end

# Object used for simplified communication with a Slurm batch server
# @api private
class Batch
Expand Down Expand Up @@ -359,10 +366,6 @@ 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 @@ -670,7 +673,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: @batch.gpus_from_gres(v[:gres])
gpus: gpus_from_gres(v[:gres])
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/job/adapters/slurm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ def job_info(opts = {})
]
gres_cases.each do |gc|
it "does not return the correct number of gpus when gres=\"#{gc[0]}\"" do
gpus = adapter.send(:gpus_from_gres, gc[0])
gpus = adapter.gpus_from_gres(gc[0]);
expect(gpus).to be(gc[1]);
end
end
Expand Down

0 comments on commit 7eca11b

Please sign in to comment.