Skip to content
Open
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
28 changes: 26 additions & 2 deletions src/main/java/com/aparapi/internal/kernel/KernelRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,10 @@ public class KernelRunner extends KernelRunnerJNI{

final private ThreadDiedHandler handler = new ThreadDiedHandler();
//Allow a thread pool per KernelRunner which will also be per Kernel instance
private final ForkJoinPool threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
private ForkJoinPool threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
lowPriorityThreadFactory, handler, false);
private static ForkJoinPool commonPoolResource=null;
private static boolean useStaticPool = true;
private static HashMap<Class<? extends Kernel>, String> openCLCache = new HashMap<>();
private static LinkedHashSet<String> seenBinaryKeys = new LinkedHashSet<>();

Expand Down Expand Up @@ -781,7 +783,7 @@ public void set(KernelState kernelState, int globalGroupId, int threadId) {
kernelState.setLocalBarrier(localBarrier);
}

ForkJoinTask<?> fjt = threadPool.submit(
ForkJoinTask<?> fjt = getThreadPool().submit(
// () -> {
new Runnable() {
public void run() {
Expand Down Expand Up @@ -2107,6 +2109,28 @@ public boolean isExplicit() {
return (explicit);
}

public ForkJoinPool getThreadPool() {
if(useStaticPool) {
if(commonPoolResource==null) {
commonPoolResource=threadPool;
}
return commonPoolResource;
}
return threadPool;
}

public void setThreadPool(ForkJoinPool threadPool) {
this.threadPool = threadPool;
}

public static boolean isUseStaticPool() {
return useStaticPool;
}

public static void setUseStaticPool(boolean useStaticPool) {
KernelRunner.useStaticPool = useStaticPool;
}

private static class ExecutionSettings {
final KernelPreferences preferences;
final KernelProfile profile;
Expand Down