Bugfix: if two gpus have the same name/model, the actual gpu used was the first in the list

This commit is contained in:
Laurent Clouet
2015-01-24 17:49:27 +00:00
parent 93d34bc571
commit dce52320c9
2 changed files with 35 additions and 12 deletions

View File

@@ -96,7 +96,7 @@ public class GPU {
return true; return true;
} }
public static List<String> listDevices() { public static List<String> listModels() {
if (devices == null) { if (devices == null) {
generate(); generate();
} }
@@ -111,6 +111,17 @@ public class GPU {
return devs; return devs;
} }
public static List<GPUDevice> listDevices() {
if (devices == null) {
generate();
}
if (devices == null) {
return null;
}
return devices;
}
public static GPUDevice getGPUDevice(String device_model) { public static GPUDevice getGPUDevice(String device_model) {
if (device_model == null) { if (device_model == null) {
return null; return null;

View File

@@ -30,12 +30,12 @@ public class Settings implements Activity {
private File cacheDir; private File cacheDir;
private JFileChooser cacheDirChooser; private JFileChooser cacheDirChooser;
private JCheckBox useCPU; private JCheckBox useCPU;
private List<JCheckBox> useGPUs; private List<JCheckBoxGPU> useGPUs;
public Settings(GuiSwing parent_) { public Settings(GuiSwing parent_) {
parent = parent_; parent = parent_;
cacheDir = null; cacheDir = null;
useGPUs = new LinkedList<JCheckBox>(); useGPUs = new LinkedList<JCheckBoxGPU>();
} }
@Override @Override
@@ -128,11 +128,12 @@ public class Settings implements Activity {
useCPU.setBounds(start_label_right, n, size, size_height_label); useCPU.setBounds(start_label_right, n, size, size_height_label);
parent.getContentPane().add(useCPU); parent.getContentPane().add(useCPU);
List<String> gpus = GPU.listDevices(); List<GPUDevice> gpus = GPU.listDevices();
if (gpus != null) { if (gpus != null) {
for (String model : gpus) { for (GPUDevice gpu : gpus) {
n += 20; n += 20;
JCheckBox gpuCheckBox = new JCheckBox(model); JCheckBoxGPU gpuCheckBox = new JCheckBoxGPU(gpu);
gpuCheckBox.setSelected(gpuChecked); gpuCheckBox.setSelected(gpuChecked);
gpuCheckBox.setBounds(start_label_right, n, 200, size_height_label); gpuCheckBox.setBounds(start_label_right, n, 200, size_height_label);
gpuCheckBox.addActionListener(new GpuChangeAction()); gpuCheckBox.addActionListener(new GpuChangeAction());
@@ -198,10 +199,10 @@ public class Settings implements Activity {
} }
} }
String selected_gpu = null; GPUDevice selected_gpu = null;
for (JCheckBox box : useGPUs) { for (JCheckBoxGPU box : useGPUs) {
if (box.isSelected()) { if (box.isSelected()) {
selected_gpu = box.getText(); // model selected_gpu = box.getGPUDevice();
} }
} }
@@ -217,13 +218,24 @@ public class Settings implements Activity {
} }
config.setComputeMethod(method); config.setComputeMethod(method);
GPUDevice gpu = GPU.getGPUDevice(selected_gpu); if (selected_gpu != null) {
if (gpu != null) { config.setUseGPU(selected_gpu);
config.setUseGPU(gpu);
} }
parent.setCredentials(login.getText(), new String(password.getPassword())); parent.setCredentials(login.getText(), new String(password.getPassword()));
} }
} }
class JCheckBoxGPU extends JCheckBox {
private GPUDevice gpu;
public JCheckBoxGPU(GPUDevice gpu) {
super(gpu.getModel());
this.gpu = gpu;
}
public GPUDevice getGPUDevice() {
return gpu;
}
}
} }