Skip to content

Commit d955854

Browse files
committed
* Adds a command (CLIJPoolSpecifyCommand) that can be used to specify how the default CLIJxPool is using CL devices (exclusion / number of contexts)
* Adds the '90' series in the default list of devices to split * Adds a set of static functions within CLIJxPool that is used by CLIJPoolSpecifyCommand * Creates SimpleIJLaunch in tests - that's an easy way to test the Command of this repo
1 parent d14fbf5 commit d955854

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package net.haesleinhuepf.clijx.parallel;
2+
3+
import ij.IJ;
4+
import net.haesleinhuepf.clij.CLIJ;
5+
import org.scijava.ItemVisibility;
6+
import org.scijava.command.Command;
7+
import org.scijava.command.DynamicCommand;
8+
import org.scijava.plugin.Parameter;
9+
import org.scijava.plugin.Plugin;
10+
11+
import java.util.ArrayList;
12+
13+
/**
14+
* Allow to specify how the default static {@link CLIJxPool} is created
15+
* One can exclude some devices from the pool, or fine tune some devices by setting
16+
* how many contexts should be created for each available CL device
17+
*
18+
* TODO: there's an issue if there are multiple identical devices, say 2x 4080 cards. I need to test a configuration like that. Maybe with BIOP Desktop.
19+
*/
20+
21+
@Plugin(type = Command.class, headless = true,
22+
menuPath = "Plugins>Specify CLIJxPool",
23+
initializer = "init", // Allows to user to know its configuration
24+
description = "Allow to specify how GPU resources are split (only applies to tasks using CLIJxPool.getInstance()) ")
25+
public class CLIJPoolSpecifyCommand extends DynamicCommand {
26+
27+
@Parameter(visibility = ItemVisibility.MESSAGE, persist = false)
28+
String info_for_user;
29+
30+
@Parameter(label = "Devices To Exclude (comma separated)")
31+
String devices_to_exclude_csv = "";
32+
33+
@Parameter(label = "Split Devices (device name then number, comma separated)", description = "For instance '3080, 8, Intel, 4'")
34+
String devices_split_csv = "";
35+
36+
@Override
37+
public void run() {
38+
try {
39+
CLIJ.getAvailableDeviceNames();
40+
} catch (Exception e) {
41+
System.out.println("Could not get CL devices information - skipping command.");
42+
return;
43+
}
44+
45+
if (CLIJxPool.isIntanceSet()) {
46+
IJ.log("A CLIJxPool instance is already set, closing it...");
47+
CLIJxPool.getInstance().shutdown();
48+
IJ.log("Previous pool closed.");
49+
}
50+
51+
if (!devices_split_csv.trim().isEmpty()) {
52+
CLIJxPool.clearDevicesSplit();
53+
String[] devices_to_split = devices_split_csv.trim().split(",");
54+
if (devices_to_split.length % 2 == 1) {
55+
System.err.println("You have an issue with the device split parameters, the number or arguments is odd.");
56+
return;
57+
}
58+
59+
// Validate first
60+
for (int iDevice = 0; iDevice<devices_to_split.length; iDevice+=2) {
61+
try {
62+
int nContexts = Integer.parseInt(devices_to_split[iDevice + 1]);
63+
if (nContexts <= 0 ) {
64+
System.err.println("Invalid contexts number, a strictly positive number is expected.");
65+
return;
66+
}
67+
} catch (Exception e) {
68+
System.err.println("Error while parsing argument "+devices_to_split[iDevice+1]+" - it should be an integer.");
69+
return;
70+
}
71+
}
72+
73+
// Do
74+
for (int iDevice = 0; iDevice<devices_to_split.length; iDevice+=2) {
75+
String deviceName = devices_to_split[iDevice].trim();
76+
int nContexts = Integer.parseInt(devices_to_split[iDevice+1]);
77+
CLIJxPool.setNumberOfInstancePerDevice(deviceName, nContexts);
78+
}
79+
}
80+
81+
if (!devices_to_exclude_csv.trim().isEmpty()) {
82+
CLIJxPool.clearExcludedDevices();
83+
String[] devices_to_exclude = devices_to_exclude_csv.trim().split(",");
84+
for (String device_to_exclude: devices_to_exclude) {
85+
CLIJxPool.excludeDevice(device_to_exclude);
86+
}
87+
}
88+
89+
IJ.log("- Creating CLIJ Pool:");
90+
CLIJxPool.getInstance();
91+
92+
IJ.log("- CLIJ Pool specifications:");
93+
IJ.log(CLIJxPool.getInstance().getDetails());
94+
}
95+
96+
protected void init() { // DO NOT DELETE! This is actually used by the initializer
97+
ArrayList<String> allDevices = null;
98+
try {
99+
allDevices = CLIJ.getAvailableDeviceNames();
100+
} catch (Exception e) {
101+
info_for_user = "Could not get CL devices information - this command will not work.";
102+
return;
103+
}
104+
info_for_user = "<html>";
105+
info_for_user += "<h2>Specify pool of CLIJ instances</h2><br>";
106+
info_for_user += "Available devices:<br>";
107+
for (String device: allDevices) {
108+
info_for_user += " - "+device+" <br>";
109+
}
110+
info_for_user+="</html>";
111+
}
112+
}
113+
114+

src/main/java/net/haesleinhuepf/clijx/parallel/CLIJxPool.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,19 @@ public class CLIJxPool {
6161
GPU_TO_INSTANCES.put("2060", 2);
6262
GPU_TO_INSTANCES.put("2070", 2);
6363
GPU_TO_INSTANCES.put("2080", 4);
64+
GPU_TO_INSTANCES.put("2090", 4);
6465

6566
GPU_TO_INSTANCES.put("3060", 2);
6667
GPU_TO_INSTANCES.put("3070", 2);
6768
GPU_TO_INSTANCES.put("3080", 4);
69+
GPU_TO_INSTANCES.put("3090", 4);
6870

6971
GPU_TO_INSTANCES.put("4060", 4);
7072
GPU_TO_INSTANCES.put("4070", 4);
7173
GPU_TO_INSTANCES.put("4080", 8);
7274
GPU_TO_INSTANCES.put("4090", 8);
7375

76+
GPU_TO_INSTANCES.put("5060", 4);
7477
GPU_TO_INSTANCES.put("5070", 4);
7578
GPU_TO_INSTANCES.put("5080", 8);
7679
GPU_TO_INSTANCES.put("5090", 8);
@@ -209,6 +212,27 @@ private static CLIJxPool createDefaultPool() {
209212
}
210213
}
211214

215+
/**
216+
* @return true if a default static pool instance has already been created, false otherwise
217+
*/
218+
public static boolean isIntanceSet() {
219+
return INSTANCE != null;
220+
}
221+
222+
/**
223+
* Resets the list of excluded devices for the default static pool
224+
*/
225+
public static void clearExcludedDevices() {
226+
EXCLUDED_GPU.clear();
227+
}
228+
229+
/**
230+
* Resets how devices are split for the default static pool
231+
*/
232+
public static void clearDevicesSplit() {
233+
GPU_TO_INSTANCES.clear();
234+
}
235+
212236
/**
213237
* @return total number of CLIJx instances (busy or not) contained in the pool, identical to {@link CLIJxPool#nInstances()}
214238
*/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.haesleinhuepf.clijx.parallel;
2+
3+
import net.imagej.ImageJ;
4+
5+
public class SimpleIJLaunch {
6+
7+
public static void main(String[] args) {
8+
ImageJ ij = new ImageJ();
9+
ij.ui().showUI();
10+
}
11+
12+
}

0 commit comments

Comments
 (0)