Skip to content

Commit

Permalink
add gpu awareness to queue_info (#825)
Browse files Browse the repository at this point in the history
* add gpu awareness to queue_info

* strengthen this regex
  • Loading branch information
johrstrom authored Mar 29, 2024
1 parent cb4e7e8 commit c397b50
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/ood_core/job/adapters/slurm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def queues

[].tap do |ret_arr|
info_raw.each_line do |line|
ret_arr << str_to_acct_info(line)
ret_arr << str_to_queue_info(line)
end
end
end
Expand Down Expand Up @@ -357,7 +357,7 @@ def nodes
end

private
def str_to_acct_info(line)
def str_to_queue_info(line)
hsh = line.split(' ').map do |token|
m = token.match(/^(?<key>\w+)=(?<value>.+)$/)
[m[:key], m[:value]]
Expand All @@ -373,6 +373,7 @@ def str_to_acct_info(line)


hsh[:deny_accounts] = hsh[:DenyAccounts].nil? ? [] : hsh[:DenyAccounts].to_s.split(',')
hsh[:tres] = hsh[:TRES].nil? ? {} : hsh[:TRES].to_s.split(',').map { |str| str.split('=') }.to_h

OodCore::Job::QueueInfo.new(**hsh)
end
Expand Down
8 changes: 8 additions & 0 deletions lib/ood_core/job/queue_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class OodCore::Job::QueueInfo
# The accounts that are not allowed to use this queue.
attr_reader :deny_accounts

# An Hash of Trackable Resources and their values.
attr_reader :tres

def initialize(**opts)
@name = opts.fetch(:name, 'unknown')
@qos = opts.fetch(:qos, [])
@tres = opts.fetch(:tres, {})

allow_accounts = opts.fetch(:allow_accounts, nil)
@allow_accounts = if allow_accounts.nil?
Expand All @@ -42,4 +46,8 @@ def to_h
[name, send(name)]
end.to_h
end

def gpu?
tres.keys.any? { |name| name.to_s.match?(%r{^gres/gpu($|:)}i) }
end
end
5 changes: 5 additions & 0 deletions spec/job/adapters/slurm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1333,11 +1333,16 @@ def job_info(opts = {})
expect(systems_queue.allow_accounts).to eq(['root', 'pzs0708', 'pzs0710', 'pzs0722'])
expect(systems_queue.deny_accounts).to eq([])
expect(systems_queue.qos).to eq([])
expect(systems_queue.gpu?).to eq(true)

quick_queue = queues.select { |q| q.name == 'quick' }.first
expect(quick_queue.allow_accounts).to eq(nil)
expect(quick_queue.deny_accounts).to eq(quick_deny_accounts)
expect(quick_queue.qos).to eq(['quick'])
expect(quick_queue.gpu?).to eq(false)

gpu_queue = queues.select { |q| q.name == 'gpuserial' }.first
expect(gpu_queue.gpu?).to eq(true)
end
end

Expand Down

0 comments on commit c397b50

Please sign in to comment.