2014-11-20 13:21:19 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2013-2014 Laurent CLOUET
|
|
|
|
|
* Author Laurent CLOUET <laurent.clouet@nopnop.net>
|
|
|
|
|
*
|
2020-05-28 13:28:42 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
2014-11-20 13:21:19 +00:00
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; version 2
|
|
|
|
|
* of the License.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.sheepit.client.hardware.gpu;
|
|
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2018-08-24 19:46:03 +02:00
|
|
|
import com.sheepit.client.Configuration;
|
2022-07-17 09:48:49 +00:00
|
|
|
import com.sheepit.client.hardware.gpu.hip.HIP;
|
2018-08-24 19:46:03 +02:00
|
|
|
import com.sheepit.client.hardware.gpu.nvidia.Nvidia;
|
2014-11-20 13:21:19 +00:00
|
|
|
import com.sheepit.client.os.OS;
|
2018-08-24 19:46:03 +02:00
|
|
|
import com.sheepit.client.os.Windows;
|
2014-11-20 13:21:19 +00:00
|
|
|
|
|
|
|
|
public class GPU {
|
|
|
|
|
public static List<GPUDevice> devices = null;
|
|
|
|
|
|
|
|
|
|
public static boolean generate() {
|
2016-10-12 01:40:59 +02:00
|
|
|
devices = new LinkedList<GPUDevice>();
|
2018-08-24 19:46:03 +02:00
|
|
|
List<GPUDevice> gpus = new Nvidia().getGpus();
|
|
|
|
|
if (gpus != null) {
|
|
|
|
|
devices.addAll(gpus);
|
2014-11-20 13:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-24 17:49:27 +00:00
|
|
|
public static List<String> listModels() {
|
2014-11-20 13:21:19 +00:00
|
|
|
if (devices == null) {
|
|
|
|
|
generate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> devs = new LinkedList<String>();
|
|
|
|
|
for (GPUDevice dev : devices) {
|
|
|
|
|
devs.add(dev.getModel());
|
|
|
|
|
}
|
|
|
|
|
return devs;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-24 19:46:03 +02:00
|
|
|
public static List<GPUDevice> listDevices(Configuration config) {
|
2015-01-24 17:49:27 +00:00
|
|
|
if (devices == null) {
|
2019-08-07 22:17:59 +02:00
|
|
|
if (config.isDetectGPUs()) {
|
2018-08-24 19:46:03 +02:00
|
|
|
generate();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
devices = new LinkedList<GPUDevice>();
|
|
|
|
|
}
|
2015-01-24 17:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-28 14:44:04 +00:00
|
|
|
public static boolean hasHIPDevices() {
|
|
|
|
|
OS os = OS.getOS();
|
|
|
|
|
if (os instanceof Windows) { // for now we only allow AMD on Windows
|
|
|
|
|
return HIP.hasHIPDevices();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 17:55:00 +02:00
|
|
|
public static GPUDevice getGPUDevice(String deviceId) {
|
|
|
|
|
if (deviceId == null) {
|
2014-11-20 13:21:19 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (devices == null) {
|
|
|
|
|
generate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (devices == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (GPUDevice dev : devices) {
|
2019-07-09 17:55:00 +02:00
|
|
|
if (deviceId.equals(dev.getId()) || deviceId.equals(dev.getOldId())) {
|
2014-11-20 13:21:19 +00:00
|
|
|
return dev;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|