From 2e6e604e72cabb22c9e90cf09e2876991a36f943 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Tue, 29 Jul 2025 11:15:34 -0400 Subject: [PATCH 1/2] close https://github.com/Syncleus/aparapi/issues/179 Add a getter and setter to the threadPollo object so users can choose to use a shared pool to avoid thread count runaway. --- .../com/aparapi/internal/kernel/KernelRunner.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java index 25975a2a..c00d3724 100644 --- a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java +++ b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java @@ -155,7 +155,7 @@ 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 HashMap, String> openCLCache = new HashMap<>(); private static LinkedHashSet seenBinaryKeys = new LinkedHashSet<>(); @@ -781,7 +781,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() { @@ -2107,7 +2107,15 @@ public boolean isExplicit() { return (explicit); } - private static class ExecutionSettings { + public ForkJoinPool getThreadPool() { + return threadPool; + } + + public void setThreadPool(ForkJoinPool threadPool) { + this.threadPool = threadPool; + } + +private static class ExecutionSettings { final KernelPreferences preferences; final KernelProfile profile; final String entrypoint; From 3273c91c8a5c662ed45d3474097897bb2cc74968 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Tue, 29 Jul 2025 11:48:55 -0400 Subject: [PATCH 2/2] change to the default use of a common pool resource to pass testBJP on JTP --- .../aparapi/internal/kernel/KernelRunner.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java index c00d3724..875abfc0 100644 --- a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java +++ b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java @@ -157,6 +157,8 @@ public class KernelRunner extends KernelRunnerJNI{ //Allow a thread pool per KernelRunner which will also be per Kernel instance private ForkJoinPool threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), lowPriorityThreadFactory, handler, false); + private static ForkJoinPool commonPoolResource=null; + private static boolean useStaticPool = true; private static HashMap, String> openCLCache = new HashMap<>(); private static LinkedHashSet seenBinaryKeys = new LinkedHashSet<>(); @@ -2108,6 +2110,12 @@ public boolean isExplicit() { } public ForkJoinPool getThreadPool() { + if(useStaticPool) { + if(commonPoolResource==null) { + commonPoolResource=threadPool; + } + return commonPoolResource; + } return threadPool; } @@ -2115,7 +2123,15 @@ public void setThreadPool(ForkJoinPool threadPool) { this.threadPool = threadPool; } -private static class ExecutionSettings { + 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; final String entrypoint;