Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HPCasCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hpc-team
HPCasCode
Commits
bf895678
Commit
bf895678
authored
6 years ago
by
Jafar Lie
Browse files
Options
Downloads
Patches
Plain Diff
updated the check for nvidia-smi method so it is now not hard-coded
parent
52d24c8e
No related branches found
No related tags found
1 merge request
!206
updated the check for nvidia-smi method so it is now not hard-coded
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
roles/gpu/files/scripts/nvidia-xconf-gen.py
+37
-65
37 additions, 65 deletions
roles/gpu/files/scripts/nvidia-xconf-gen.py
with
37 additions
and
65 deletions
roles/gpu/files/scripts/nvidia-xconf-gen.py
+
37
−
65
View file @
bf895678
...
...
@@ -11,14 +11,19 @@ from subprocess import call
import
re
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
():
# 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
"
):
print
(
"
nvidia-smi binary not found!
"
)
exit
(
1
)
cmd
=
[
"
/bin/nvidia-smi
"
,
"
--query-gpu=pci.bus_id
"
,
"
--format=csv,noheader
"
]
cmd
=
[
"
nvidia-smi
"
,
"
--query-gpu=pci.bus_id
"
,
"
--format=csv,noheader
"
]
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
cards
=
[]
...
...
@@ -27,76 +32,43 @@ def grab_card_ids():
line
=
line
.
rstrip
().
split
(
"
:
"
)[
2
]
pcibus_num
=
int
(
re
.
sub
(
'
[.:]
'
,
''
,
line
).
rstrip
(
"
0
"
),
16
)
card
=
"
PCI:0:{}:0
"
.
format
(
str
(
pcibus_num
))
cards
.
append
(
card
)
cards
.
append
(
card
)
return
cards
def
grab_card_boardname
():
if
not
os
.
path
.
isfile
(
"
/bin/nvidia-smi
"
):
print
(
"
nvidia-smi binary not found!
"
)
exit
(
1
)
check_nvidia_smi
()
cmd
=
[
"
/bin/
nvidia-smi
"
,
"
--query-gpu=name
"
,
"
--format=csv,noheader
"
]
cards
=
[]
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
for
line
in
p
.
stdout
.
readlines
():
line
=
line
.
rstrip
()
cards
.
append
(
line
)
return
cards
cmd
=
[
"
nvidia-smi
"
,
"
--query-gpu=name
"
,
"
--format=csv,noheader
"
]
cards
=
[]
p
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
for
line
in
p
.
stdout
.
readlines
():
line
=
line
.
rstrip
()
cards
.
append
(
line
)
return
cards
def
write_xorg_conf
(
cards
):
num_of_cards
=
len
(
cards
)
+
1
boardname
=
(
grab_card_boardname
())[
0
]
gpus
=
[]
num_of_cards
=
len
(
cards
)
+
1
boardname
=
(
grab_card_boardname
())[
0
]
gpus
=
[]
for
i
in
range
(
1
,
num_of_cards
):
monitors
=
[]
screens
=
[]
res
=
list
(
itertools
.
combinations
(
cards
,
i
))
for
i
in
range
(
1
,
num_of_cards
):
monitors
=
[]
screens
=
[]
res
=
list
(
itertools
.
combinations
(
cards
,
i
))
for
j
in
range
(
i
):
monitors
.
append
(
"
Monitor
"
+
str
(
j
))
screens
.
append
(
"
Screen
"
+
str
(
j
))
for
j
in
range
(
i
):
monitors
.
append
(
"
Monitor
"
+
str
(
j
))
screens
.
append
(
"
Screen
"
+
str
(
j
))
for
card
in
res
:
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
})
for
card
in
res
:
filename
=
"
/etc/X11/xorg.conf.
"
+
str
(
i
)
+
str
(
res
.
index
(
card
))
gpus
.
append
({
'
filename
'
:
filename
,
'
boardname
'
:
boardname
,
'
monitors
'
:
monitors
,
'
screens
'
:
screens
,
'
devices
'
:
card
})
print
(
json
.
dumps
(
gpus
))
print
(
json
.
dumps
(
gpus
))
if
__name__
==
"
__main__
"
:
# cards = grab_card_ids()
# 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()
'''
cards
=
grab_card_ids
()
write_xorg_conf
(
cards
)
This diff is collapsed.
Click to expand it.
Jafar Lie
@jlie0003
mentioned in commit
86cd0a2d
·
4 years ago
mentioned in commit
86cd0a2d
mentioned in commit 86cd0a2dfef70a9ddf8c1aa36e627a54420e4fa9
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment