Skip to content

Commit

Permalink
Added deviceConfig validation check
Browse files Browse the repository at this point in the history
  • Loading branch information
olepoeschl committed May 24, 2023
1 parent d2a63a9 commit f58380b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/de/nqueensfaf/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,22 @@ public void validate() {
if(cpuThreadcount <= 0 || cpuThreadcount > Runtime.getRuntime().availableProcessors())
cpuThreadcount = getDefaultConfig().getCPUThreadcount();

if(gpuDeviceConfigs == null)
if(gpuDeviceConfigs == null || gpuDeviceConfigs.length == 0)
gpuDeviceConfigs = getDefaultConfig().getGPUDeviceConfigs();
// check for invalid values and remove each invalid value that is found from the array
ArrayList<DeviceConfig> gpuDeviceConfigsTmp = new ArrayList<DeviceConfig>();
for(DeviceConfig deviceConfig : gpuDeviceConfigs) {
if((deviceConfig.getIndex() < 0) || deviceConfig.getWorkgroupSize() <= 0 || deviceConfig.getPresetQueens() < 4)
continue;
if(gpuDeviceConfigsTmp.stream().anyMatch(dvcCfg -> deviceConfig.getIndex() == dvcCfg.getIndex())) // check for duplicates
continue;
gpuDeviceConfigsTmp.add(deviceConfig);
}
gpuDeviceConfigs = new DeviceConfig[gpuDeviceConfigsTmp.size()];
for(int i = 0; i < gpuDeviceConfigsTmp.size(); i++) {
gpuDeviceConfigs[i] = gpuDeviceConfigsTmp.get(i);
else {
// check for invalid values and remove each invalid value that is found
ArrayList<DeviceConfig> gpuDeviceConfigsTmp = new ArrayList<DeviceConfig>();
for(var deviceConfig : gpuDeviceConfigs) {
if(gpuDeviceConfigsTmp.stream().anyMatch(dvcCfg -> deviceConfig.getIndex() == dvcCfg.getIndex())) // check for duplicates
continue;
if(deviceConfig.isValid())
gpuDeviceConfigsTmp.add(deviceConfig);
}
gpuDeviceConfigs = new DeviceConfig[gpuDeviceConfigsTmp.size()];
for(int i = 0; i < gpuDeviceConfigsTmp.size(); i++) {
gpuDeviceConfigs[i] = gpuDeviceConfigsTmp.get(i);
}
}
if(gpuDeviceConfigs.length == 0)
gpuDeviceConfigs = getDefaultConfig().getGPUDeviceConfigs();

if(gpuPresetQueens < 4)
gpuPresetQueens = getDefaultConfig().getGPUPresetQueens();
Expand Down
4 changes: 4 additions & 0 deletions src/de/nqueensfaf/config/DeviceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public DeviceConfig(int index, int workgroupSize, int presetQueens, int weight)
this.weight = weight;
}

public boolean isValid() {
return index >= 0 && workgroupSize > 0 && presetQueens >= 4;
}

public int getIndex() {
return index;
}
Expand Down

0 comments on commit f58380b

Please sign in to comment.