[feat] Improve the calculation of local workgroup dimensions for the GPU
scheduler while guarding for irregular sizes
*/
package uk.ac.manchester.tornado.drivers.opencl;
+import com.sun.org.apache.bcel.internal.generic.SWITCH;
import uk.ac.manchester.tornado.runtime.tasks.meta.TaskMetaData;
import java.util.ArrayList;
@@ -50,9 +51,7 @@ public class OCLGPUScheduler extends OCLKernelScheduler {
super(context);
OCLDevice device = context.getDevice();
- maxWorkItemSizes = new long[]{16,16,1};
-// maxWorkItemSizes = new long[]{256,256,256};
-// maxWorkItemSizes = device.getDeviceMaxWorkItemSizes();
+ maxWorkItemSizes = device.getDeviceMaxWorkItemSizes();
maxComputeUnits = device.getDeviceMaxComputeUnits();
maxWorkGroupSize = device.getDeviceMaxWorkGroupSize();
@@ -78,19 +77,16 @@ public class OCLGPUScheduler extends OCLKernelScheduler {
final long[] localWork = meta.getLocalWork();
System.out.println("Inside scheduler: " + Arrays.toString(localWork));
System.out.println("meta getdims: " + meta.getDims());
+
switch (meta.getDims()) {
case 3:
- /// XXX: Support 3D
- localWork[2] = calculateGroupSize(maxWorkItemSizes[2], meta.getGlobalWork()[2]);
+ localWork[2] = 1;
case 2:
- localWork[1] = calculateGroupSize(maxWorkItemSizes[1], meta.getGlobalWork()[1]);
- localWork[0] = calculateGroupSize(maxWorkItemSizes[0], meta.getGlobalWork()[0]);
+ localWork[1] = calculateGroupSize(calculateEffectiveMaxWorkItemSizes(meta)[1], meta.getGlobalWork()[1]);
+ localWork[0] = calculateGroupSize(calculateEffectiveMaxWorkItemSizes(meta)[0], meta.getGlobalWork()[0]);
break;
case 1:
- localWork[0] = calculateGroupSize(maxWorkItemSizes[0], meta.getGlobalWork()[0]);
- System.out.println("max work item sizes 0 : " + maxWorkItemSizes[0]);
- System.out.println("opecl gpu block x : " + meta.getOpenCLGpuBlockX());
- System.out.println("global work size 0 : " + meta.getGlobalWork()[0]);
+ localWork[0] = calculateGroupSize(calculateEffectiveMaxWorkItemSizes(meta)[0], meta.getGlobalWork()[0]);
break;
default:
break;
@@ -98,14 +94,38 @@ public class OCLGPUScheduler extends OCLKernelScheduler {
}
private int calculateGroupSize(long maxBlockSize, long globalWorkSize) {
+ System.out.println(" * * * * * *");
+ System.out.println("maxBlockSize initial value : " + maxBlockSize);
if (maxBlockSize == globalWorkSize) {
maxBlockSize /= 4;
}
int value = (int) Math.min(maxBlockSize, globalWorkSize);
+ System.out.println("Initial value : " + value);
while (globalWorkSize % value != 0) {
value--;
}
+ System.out.println("maxBlockSize value : " + maxBlockSize);
+ System.out.println("globalWorkSize value : " + globalWorkSize);
+ System.out.println("Dim value : " + value);
return value;
}
+
+ private long[] calculateEffectiveMaxWorkItemSizes(TaskMetaData metaData) {
+ long[] intermediateitems = new long[] { 1, 1, 1 };
+
+ switch (metaData.getDims()) {
+ case 2:
+ intermediateitems[0] = (long) Math.sqrt(maxWorkItemSizes[0]);
+ intermediateitems[1] = (long) Math.sqrt(maxWorkItemSizes[0]);
+ break;
+ case 1:
+ intermediateitems[0] = maxWorkItemSizes[0];
+ break;
+ default:
+ break;
+
+ }
+ return intermediateitems;
+ }
}
