Skip to content
Snippets Groups Projects
Commit 6549ef63 authored by Gin Tan's avatar Gin Tan
Browse files

Merge branch 'update-xconf-gen' into 'master'

updated the check for nvidia-smi method so it is now not hard-coded

See merge request hpc-team/ansible_cluster_in_a_box!206
parents a9b35f6a bf895678
No related branches found
No related tags found
1 merge request!206updated the check for nvidia-smi method so it is now not hard-coded
...@@ -11,14 +11,19 @@ from subprocess import call ...@@ -11,14 +11,19 @@ from subprocess import call
import re import re
import json import json
def check_nvidia_smi():
try:
smi = subprocess.check_output(["which","nvidia-smi"])
except subprocess.CalledProcessError:
print("nvidia-smi binary not found!")
exit(1)
def grab_card_ids(): def grab_card_ids():
# This method runs nvidia-smi to grab the card ids, then returns a list # This method runs nvidia-smi to grab the card ids, then returns a list
check_nvidia_smi()
if not os.path.isfile("/bin/nvidia-smi"): cmd = ["nvidia-smi", "--query-gpu=pci.bus_id","--format=csv,noheader"]
print("nvidia-smi binary not found!")
exit(1)
cmd = ["/bin/nvidia-smi", "--query-gpu=pci.bus_id","--format=csv,noheader"]
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
cards = [] cards = []
...@@ -27,76 +32,43 @@ def grab_card_ids(): ...@@ -27,76 +32,43 @@ def grab_card_ids():
line = line.rstrip().split(":")[2] line = line.rstrip().split(":")[2]
pcibus_num = int(re.sub('[.:]', '', line).rstrip("0"),16) pcibus_num = int(re.sub('[.:]', '', line).rstrip("0"),16)
card = "PCI:0:{}:0".format(str(pcibus_num)) card = "PCI:0:{}:0".format(str(pcibus_num))
cards.append(card) cards.append(card)
return cards return cards
def grab_card_boardname(): def grab_card_boardname():
if not os.path.isfile("/bin/nvidia-smi"): check_nvidia_smi()
print("nvidia-smi binary not found!")
exit(1)
cmd = ["/bin/nvidia-smi", "--query-gpu=name","--format=csv,noheader"] cmd = ["nvidia-smi", "--query-gpu=name","--format=csv,noheader"]
cards = [] cards = []
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines(): for line in p.stdout.readlines():
line = line.rstrip() line = line.rstrip()
cards.append(line) cards.append(line)
return cards return cards
def write_xorg_conf(cards): def write_xorg_conf(cards):
num_of_cards = len(cards) + 1 num_of_cards = len(cards) + 1
boardname = (grab_card_boardname())[0] boardname = (grab_card_boardname())[0]
gpus = [] gpus = []
for i in range(1, num_of_cards): for i in range(1, num_of_cards):
monitors = [] monitors = []
screens = [] screens = []
res = list(itertools.combinations(cards,i)) res = list(itertools.combinations(cards,i))
for j in range(i): for j in range(i):
monitors.append("Monitor"+str(j)) monitors.append("Monitor"+str(j))
screens.append("Screen"+str(j)) screens.append("Screen"+str(j))
for card in res: for card in res:
filename = "/etc/X11/xorg.conf." + str(i) + str(res.index(card)) filename = "/etc/X11/xorg.conf." + str(i) + str(res.index(card))
#gpus[filename] = filename
gpus.append({'filename':filename,'boardname':boardname,'monitors':monitors,'screens':screens,'devices':card})
gpus.append({'filename':filename,'boardname':boardname,'monitors':monitors,'screens':screens,'devices':card})
print(json.dumps(gpus)) print(json.dumps(gpus))
if __name__ == "__main__": if __name__ == "__main__":
# cards = grab_card_ids() cards = grab_card_ids()
# write_xorg_conf(cards) write_xorg_conf(cards)
cards = grab_card_ids()
write_xorg_conf(cards)
''' with open("xorgconftest.j2") as f:
template = Template(f.read())
num_of_monitors = 2
monitors = []
screens = []
busid = ["PCI:0:6:0","PCI:0:7:0","PCI:0:8:0","PCI:0:9:0"]
for i in range(num_of_monitors):
monitors.append("Monitor" + str(i))
screens.append("Screen" + str(i))
#output = template.render(monitors=monitors,devices=busid)
#print(output)
res = itertools.combinations(busid,2)
listres = list(res)
for i in listres:
output = template.render(monitors=monitors,devices=i,screens=screens)
filename = "xorg.conf." + str(listres.index(i))
print(filename)
f = open(filename,"w")
f.write(output)
f.close() '''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment