Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple Nvidia GPUs #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions package/contents/code/model-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,34 @@ function getCelsiaFromUdisksStdout(stdout) {
function toCelsia(kelvin) {
return kelvin - 273.15
}

var NVIDIA_PREFIX = 'nvidia-smi -i {ID}'
var NVIDIA_DEVICES_CMD = 'nvidia-smi -L | grep -o -E "GPU .{0,1}" | sed -n -e "s/^.*GPU //p"'
var NVIDIA_TEMPERATURE_CMD_PATTERN = 'nvidia-smi -i {ID} --query-gpu=temperature.gpu --format=csv,noheader'

function parseGpuID(gpu_ids) {
var deviceIds = gpu_ids.split('\n')
var resultObjects = []

if (deviceIds) {
deviceIds.forEach(function (id) {
if (id) {
resultObjects.push({
cmd: NVIDIA_TEMPERATURE_CMD_PATTERN.replace('{ID}', id),
name: id
})
}
})
}

return resultObjects
}


function getNvidiaTemperatureCmd(gpu_id) {
return NVIDIA_TEMPERATURE_CMD_PATTERN.replace('{ID}', gpu_id)
}

function getNvidiaTemperaturePrefix(gpu_id) {
return NVIDIA_PREFIX.replace('{ID}', gpu_id)
}
24 changes: 16 additions & 8 deletions package/contents/ui/config/ConfigTemperatures.qml
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ Item {
}

}

PlasmaCore.DataSource {
id: systemmonitorDS
engine: 'systemmonitor'
Expand Down Expand Up @@ -542,6 +542,8 @@ Item {
text: cmd,
val: cmd
})
print('New udisksDS cmd=' + cmd);

})

}
Expand All @@ -553,24 +555,30 @@ Item {
id: nvidiaDS
engine: 'executable'

connectedSources: [ 'nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader' ]
connectedSources: [ ModelUtils.NVIDIA_DEVICES_CMD ]

property bool prepared: false

onNewData: {
nvidiaDS.connectedSources.length = 0
connectedSources.length = 0

if (data['exit code'] > 0) {
print('New data incomming. Source: ' + sourceName + ', ERROR: ' + data.stderr);
prepared = true
return
}

comboboxModel.append({
text: 'nvidia-smi',
val: 'nvidia-smi'
print('New data incomming. Source: ' + sourceName + ', data: ' + data.stdout);

var idsToCheck = ModelUtils.parseGpuID(data.stdout)
idsToCheck.forEach(function (id) {
var cmd = ModelUtils.NVIDIA_TEMPERATURE_CMD_PATTERN.replace('{ID}', id.name)
comboboxModel.append({
text: "nvidia-gpu-{ID}".replace('{ID}', id.name),
val: cmd,
})
print('New gpu cmd=' + cmd);
})

prepared = true
}

interval: 500
Expand Down
27 changes: 19 additions & 8 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Item {
if (nvidiaDS.connectedSources === undefined) {
nvidiaDS.connectedSources = []
}

if (atiDS.connectedSources === undefined) {
atiDS.connectedSources = []
}
Expand All @@ -215,6 +215,7 @@ Item {
udisksDS.connectedSources.length = 0
udisksDS.cmdSourceBySourceName = {}
nvidiaDS.connectedSources.length = 0
nvidiaDS.cmdSourceBySourceName = {}
atiDS.connectedSources.length = 0

ModelUtils.initModels(resources, temperatureModel)
Expand Down Expand Up @@ -261,13 +262,19 @@ Item {

addToSourcesOfDatasource(udisksDS, cmdSource)

} else if (source.indexOf('nvidia-') === 0 && nvidiaDS.connectedSources.length === 0) {
}

else if (source.indexOf('nvidia-smi -i ') === 0) {
var gpu_id = source.substring('nvidia-smi -i '.length)
var cmdSource = ModelUtils.getNvidiaTemperaturePrefix(gpu_id)
nvidiaDS.cmdSourceBySourceName[cmdSource] = source

dbgprint('adding source to nvidiaDS')
dbgprint('adding source to nvidiaDS: ' + cmdSource)

addToSourcesOfDatasource(nvidiaDS, nvidiaDS.nvidiaSource)
addToSourcesOfDatasource(nvidiaDS, cmdSource)

} else if (source.indexOf('aticonfig') === 0 && atiDS.connectedSources.length === 0) {
}
else if (source.indexOf('aticonfig') === 0 && atiDS.connectedSources.length === 0) {

dbgprint('adding source to atiDS')

Expand Down Expand Up @@ -357,22 +364,26 @@ Item {
PlasmaCore.DataSource {
id: nvidiaDS
engine: 'executable'
property var cmdSourceBySourceName

property string nvidiaSource: 'nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader'
//property string nvidiaSource: 'nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader'

onNewData: {

dbgprint('nvidia new data - valid: ' + valid + ', stdout: ' + data.stdout)

var temperature = 0
if (data['exit code'] > 0) {
dbgprint('new data error: ' + data.stderr)
} else {
temperature = parseFloat(data.stdout)
}

ModelUtils.updateTemperatureModel(temperatureModel, 'nvidia-smi', temperature)
ModelUtils.updateTemperatureModel(temperatureModel, cmdSourceBySourceName[sourceName], temperature)
}
interval: updateInterval
}

PlasmaCore.DataSource {
id: atiDS
engine: 'executable'
Expand Down