forked from FlavorSoft/CryptoTune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvidiaUtil.py
57 lines (51 loc) · 2.21 KB
/
nvidiaUtil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from subprocess import Popen, PIPE
import xmljson
import lxml.etree
class NVTool:
def __init__(self, log, gpuId):
self.log = log
self.gpuId = gpuId
def NVidiaSettings(self, name, value):
command = None
if name == "fan":
command = "nvidia-settings -a [gpu:%i]/GPUFanControlState=1 -a [fan:0]/GPUTargetFanSpeed=%i" % (self.gpuId, value)
if name == "memOC":
command = "nvidia-settings -a [gpu:%i]/GPUMemoryTransferRateOffset[3]=%i" % (self.gpuId, value)
if name == "coreUC":
command = "nvidia-settings -a [gpu:%i]/GPUGraphicsClockOffset[2]=%i" % (self.gpuId, value)
if command == None:
self.log.Error("invalid value for change in nvidia-settings")
return False
process = Popen(command.split(" "), stdout=PIPE)
output = process.communicate()
exit_code = process.wait()
if exit_code == 0:
return True
else:
self.log.Warning("could not change nvidia-settings")
self.log.Warning("Code: %i:\n%s" %(exit_code, output))
return False
def NSMI(self, command):
process = Popen(command.split(" "), stdout=PIPE)
(output, err) = process.communicate()
exit_code = process.wait()
if exit_code == 0 or exit_code == 6:
xml = lxml.etree.fromstring(output)
jsonObj = xmljson.badgerfish.data(xml)
return jsonObj
else:
self.log.Debug("Error on executing command \"%s\"" % command)
self.log.Debug("Code: %i:\n%s" %(exit_code, err))
return None
def NSMISet(self, name, value):
command = "nvidia-smi -i %i -%s %s" % (self.gpuId, name, value)
self.log.Debug("GPU%i: SMI Command: %s" % (self.gpuId, command))
process = Popen(command.split(" "), stdout=PIPE)
(output, err) = process.communicate()
exit_code = process.wait()
if exit_code == 0:
return True
else:
self.log.Warning("GPU%i: could not execute nvidia-smi command: \"%s\"" % (self.gpuId, command))
self.log.Warning("GPU%i: Code %i - %s" %(self.gpuId, exit_code, err))
return False