-<<<<<<< HEAD:src/main/java/com/aparapi/Kernel.java
* Alternatively, the property com.aparapi.executionMode can be set to one of JTP,GPU,ACC,CPU,SEQ
* when an application is launched.
*
* java -classpath ....;aparapi.jar -Dcom.aparapi.executionMode=GPU MyApplication
-=======
- * Alternatively, the property com.amd.aparapi.executionMode can be set to one of JTP,GPU,ACC,CPU,SEQ
- * when an application is launched.
- *
- * java -classpath ....;aparapi.jar -Dcom.amd.aparapi.executionMode=GPU MyApplication
->>>>>>> b118aad... added method to set execution mode without any fallback:com.amd.aparapi/src/java/com/amd/aparapi/Kernel.java
*
* Generally setting the execution mode is not recommended (it is best to let Aparapi decide automatically) but the option
* provides a way to compare a kernel's performance under multiple execution modes.
@@ -500,6 +493,80 @@ public boolean isOpenCL() {
}
};
+ ////////////////////
+ // !!! oren change -> add source/binary flow support to kernel
+ ////////////////////
+ public static enum FlowType
+ {
+ // flow type list
+ SOURCE(com.aparapi.internal.jni.KernelRunnerJNI.JNI_FLAG_SOURCE_FLOW),
+ BINARY(com.aparapi.internal.jni.KernelRunnerJNI.JNI_FLAG_BINARY_FLOW),
+ DEFAULT(com.aparapi.internal.jni.KernelRunnerJNI.JNI_FLAG_DEFAULT_FLOW);
+
+ // data store
+ int flowType;
+
+ FlowType(int flowType)
+ {
+ setValue(flowType);
+ }
+
+ FlowType(String flowTypeStr)
+ {
+ this.flowType = strToFlowType(flowTypeStr).getValue();
+ }
+
+ public int getValue()
+ {
+ return this.flowType;
+ }
+
+ private void setValue(int flowType)
+ {
+ this.flowType = flowType;
+ }
+
+ public static FlowType getDefaultFlowType()
+ {
+ // if set by user try get value else set to default
+ FlowType flowType = (Config.flowType==null) ? DEFAULT : strToFlowType(Config.flowType);
+ return flowType;
+ }
+
+ public static FlowType strToFlowType(final String flowTypeStr)
+ {
+ try
+ {
+ FlowType flowType = valueOf(flowTypeStr.toUpperCase());
+ return flowType;
+ }
+ catch (Exception e)
+ {
+ logger.info("!!! bad flow type => (" + flowTypeStr + ") => reverting to default platform flow!");
+ throw e;
+ }
+ }
+
+ }
+
+ public FlowType getFlowType() {
+ return kernelFlowType;
+ }
+
+
+ public void setFlowType(FlowType kernelFlowType) {
+ this.kernelFlowType = kernelFlowType;
+ }
+
+ public void setFlowType(String flowTypeStr) {
+ this.kernelFlowType = FlowType.strToFlowType(flowTypeStr);
+ }
+
+ private FlowType kernelFlowType = FlowType.getDefaultFlowType();
+
+
+ ////////////////////
+
private KernelRunner kernelRunner = null;
private boolean autoCleanUpArrays = false;
@@ -719,7 +786,8 @@ protected final int getGlobalId() {
return getGlobalId(0);
}
- @OpenCLDelegate
+
+@OpenCLDelegate
protected final int getGlobalId(int _dim) {
return kernelState.getGlobalIds()[_dim];
}
@@ -1074,7 +1142,23 @@ public Kernel clone() {
}
}
+
/**
+ * Init a kernel from an existing one. used in caching mechanisems to improve startup time (ex. SparkCL).
+ *
+ */
+ public void init(Kernel kernel) {
+
+ // create and init a copy of the kernel runner
+ kernelRunner = new KernelRunner(this);
+ if(kernel.kernelRunner!=null)
+ kernelRunner.init(kernel.kernelRunner);
+ // We need to be careful to also clone the KernelState
+ kernelState = new KernelState(kernel.kernelState); // Qualified copy constructor
+ }
+
+
+/**
* Delegates to either {@link java.lang.Math#acos(double)} (Java) or acos(float) (OpenCL).
*
* User should note the differences in precision between Java and OpenCL's implementation of arithmetic functions to determine whether the difference in precision is acceptable.
diff --git a/src/main/java/com/aparapi/ProfileInfo.java b/src/main/java/com/aparapi/ProfileInfo.java
index 00aadbff..e5217ea1 100644
--- a/src/main/java/com/aparapi/ProfileInfo.java
+++ b/src/main/java/com/aparapi/ProfileInfo.java
@@ -54,7 +54,9 @@ to national security controls as identified on the Commerce Control List (curren
public class ProfileInfo{
- private enum TYPE {
+ // !!! oren change -> we need access to type at upper levels
+ //private
+public static enum TYPE {
R,
X,
W
diff --git a/src/main/java/com/aparapi/Range.java b/src/main/java/com/aparapi/Range.java
index 5ee22725..2f950e2c 100644
--- a/src/main/java/com/aparapi/Range.java
+++ b/src/main/java/com/aparapi/Range.java
@@ -66,7 +66,11 @@ public class Range extends RangeJNI{
public static final int THREADS_PER_CORE = 16;
- public static final int MAX_OPENCL_GROUP_SIZE = 256;
+ // !!! oren change -> this value looks out dated and the mechanism probably needs revisiting !!!
+ // we already see evidence of improved performance for size==1024 on certain devices (ref: FPGA doc classification paper)
+ // for now we set it to 4X original value, but we should think about it more...
+ //public static final int MAX_OPENCL_GROUP_SIZE = 256;
+ public static final int MAX_OPENCL_GROUP_SIZE = 1024;
public static final int MAX_GROUP_SIZE = Math.max(Runtime.getRuntime().availableProcessors() * THREADS_PER_CORE,
MAX_OPENCL_GROUP_SIZE);
@@ -120,6 +124,28 @@ public static Range create(Device _device, int _globalWidth, int _localWidth) {
return (range);
}
+ /**
+ * Create a range from an existing range and a device
+ *
+ * @param _device to be associated with range
+ * @param orgRange original range to copy from
+ * @return A new Range with the requested dimensions
+ */
+ public static Range create(Device _device, Range orgRange) {
+
+ switch(orgRange.getDims())
+ {
+ case 1:
+ return create(_device,orgRange.globalSize_0,orgRange.localSize_0);
+ case 2:
+ return create2D(_device,orgRange.globalSize_0,orgRange.globalSize_1,orgRange.localSize_0,orgRange.localSize_1);
+ case 3:
+ return create3D(_device,orgRange.globalSize_0,orgRange.globalSize_1,orgRange.globalSize_2,orgRange.localSize_0,orgRange.localSize_1,orgRange.localSize_2);
+ default:
+ return null;
+ }
+ }
+
/**
* Determine the set of factors for a given value.
* @param _value The value we wish to factorize.
@@ -128,11 +154,18 @@ public static Range create(Device _device, int _globalWidth, int _localWidth) {
*/
private static int[] getFactors(int _value, int _max) {
- final int factors[] = new int[MAX_GROUP_SIZE];
+ //final int factors[] = new int[MAX_GROUP_SIZE];
int factorIdx = 0;
- for (int possibleFactor = 1; possibleFactor <= _max; possibleFactor++) {
- if ((_value % possibleFactor) == 0) {
+ // !!! oren bug fix -> based on poz findings
+ // max can not be bigger then value and if factorIdx >= MAX_GROUP_SIZE we will have an access violation
+ final int GroupSizeLimit = Math.min(Math.min(_max,_value),MAX_GROUP_SIZE);
+ final int factors[] = new int[GroupSizeLimit];
+ //for (int possibleFactor = 1; possibleFactor <= _max; possibleFactor++)
+ for (int possibleFactor = 1; possibleFactor <= GroupSizeLimit; possibleFactor++)
+ {
+ if ((_value % possibleFactor) == 0)
+ {
factors[factorIdx++] = possibleFactor;
}
}
diff --git a/src/main/java/com/aparapi/device/Device.java b/src/main/java/com/aparapi/device/Device.java
index e43e90b2..7ea85557 100644
--- a/src/main/java/com/aparapi/device/Device.java
+++ b/src/main/java/com/aparapi/device/Device.java
@@ -15,168 +15,264 @@
*/
package com.aparapi.device;
-import com.aparapi.*;
+import java.util.List;
+
import com.aparapi.internal.kernel.*;
+import com.aparapi.Range;
+import com.aparapi.device.OpenCLDevice.DeviceComparitor;
+import com.aparapi.device.OpenCLDevice.DeviceSelector;
+import com.aparapi.internal.opencl.OpenCLPlatform;
public abstract class Device{
- public static enum TYPE {
- UNKNOWN(Integer.MAX_VALUE),
- GPU(2),
- CPU(3),
- JTP(5),
- SEQ(6),
- ACC(1),
- ALT(4);
-
- /** Heuristic ranking of device types, lower is better. */
- public final int rank;
-
- TYPE(int rank) {
- this.rank = rank;
- }
- };
-
- /** @deprecated use {@link KernelManager#bestDevice()}
- * @see com.aparapi.device
- */
- @Deprecated
- public static Device best() {
- return KernelManager.instance().bestDevice();
+ public static enum TYPE {
+ UNKNOWN(Integer.MAX_VALUE),
+ GPU(2),
+ CPU(3),
+ JTP(5),
+ SEQ(6),
+ ACC(1),
+ ALT(4);
+
+ /** Heuristic ranking of device types, lower is better. */
+ public final int rank;
+
+ TYPE(int rank) {
+ this.rank = rank;
+ }
+ };
+
+ /** @deprecated use {@link KernelManager#bestDevice()}
+ * @see com.aparapi.device
+ */
+ @Deprecated
+ public static Device best() {
+ return KernelManager.instance().bestDevice();
+ }
+
+ /**
+ * @see com.aparapi.device
+ */
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public static Device bestGPU() {
+ return firstGPU();
+ }
+
+ /**
+ * @see com.aparapi.device
+ */
+ @Deprecated
+ public static Device first(final Device.TYPE _type) {
+ return KernelManager.DeprecatedMethods.firstDevice(_type);
+ }
+
+ /**
+ * @see com.aparapi.device
+ */
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public static Device firstGPU() {
+ return KernelManager.DeprecatedMethods.firstDevice(TYPE.GPU);
+ }
+
+ /**
+ * @see com.aparapi.device
+ */
+ @SuppressWarnings("deprecation")
+ @Deprecated
+ public static Device firstCPU() {
+ return KernelManager.DeprecatedMethods.firstDevice(TYPE.CPU);
+ }
+
+ /**
+ * @see com.aparapi.device
+ */
+ @Deprecated
+ public static Device bestACC() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected TYPE type = TYPE.UNKNOWN;
+
+ protected int maxWorkGroupSize;
+
+ protected int maxWorkItemDimensions;
+
+ protected int[] maxWorkItemSize = new int[] {
+ 0,
+ 0,
+ 0
+ };
+
+ public abstract String getShortDescription();
+
+ public TYPE getType() {
+ return type;
+ }
+
+ public void setType(TYPE type) {
+ this.type = type;
+ }
+
+ public int getMaxWorkItemDimensions() {
+ return maxWorkItemDimensions;
+ }
+
+ public void setMaxWorkItemDimensions(int _maxWorkItemDimensions) {
+ maxWorkItemDimensions = _maxWorkItemDimensions;
+ }
+
+ public int getMaxWorkGroupSize() {
+ return maxWorkGroupSize;
+ }
+
+ public void setMaxWorkGroupSize(int _maxWorkGroupSize) {
+ maxWorkGroupSize = _maxWorkGroupSize;
+ }
+
+ public int[] getMaxWorkItemSize() {
+ return maxWorkItemSize;
+ }
+
+ public void setMaxWorkItemSize(int[] maxWorkItemSize) {
+ this.maxWorkItemSize = maxWorkItemSize;
+ }
+
+ public Range createRange(int _globalWidth) {
+ return (Range.create(this, _globalWidth));
+ }
+
+ public Range createRange(int _globalWidth, int _localWidth) {
+ return (Range.create(this, _globalWidth, _localWidth));
+ }
+
+ public Range createRange2D(int _globalWidth, int _globalHeight) {
+ return (Range.create2D(this, _globalWidth, _globalHeight));
+ }
+
+ public Range createRange2D(int _globalWidth, int _globalHeight, int _localWidth, int _localHeight) {
+ return (Range.create2D(this, _globalWidth, _globalHeight, _localWidth, _localHeight));
+ }
+
+ public Range createRange3D(int _globalWidth, int _globalHeight, int _globalDepth) {
+ return (Range.create3D(this, _globalWidth, _globalHeight, _globalDepth));
+ }
+
+ public Range createRange3D(int _globalWidth, int _globalHeight, int _globalDepth, int _localWidth, int _localHeight,
+ int _localDepth) {
+ return (Range.create3D(this, _globalWidth, _globalHeight, _globalDepth, _localWidth, _localHeight, _localDepth));
+ }
+
+ public abstract long getDeviceId();
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Device)) {
+ return false;
+ }
+
+ Device device = (Device) o;
+
+ return getDeviceId() == device.getDeviceId();
+ }
+
+ @Override
+ public int hashCode() {
+ return Long.valueOf(getDeviceId()).hashCode();
+ }
+
+ // !!! oren change -> get device using the tuple (platform, deviceType, id)
+
+ public static Device getDevice(String platformName, Device.TYPE deviceType, int deviceId)
+ {
+ return getDevice(platformName,deviceType.name(),deviceId);
}
- /**
- * @see com.aparapi.device
- */
- @SuppressWarnings("deprecation")
- @Deprecated
- public static Device bestGPU() {
- return firstGPU();
- }
+ // get first available device
- /**
- * @see com.aparapi.device
- */
- @Deprecated
- public static Device first(final Device.TYPE _type) {
- return KernelManager.DeprecatedMethods.firstDevice(_type);
+ public static Device getDevice(String platformName, Device.TYPE deviceType)
+ {
+ return getDevice(platformName,deviceType.name(),0);
}
- /**
- * @see com.aparapi.device
- */
- @SuppressWarnings("deprecation")
- @Deprecated
- public static Device firstGPU() {
- return KernelManager.DeprecatedMethods.firstDevice(TYPE.GPU);
+ public static Device getDevice(String platformName, String deviceTypeName)
+ {
+ return getDevice(platformName,deviceTypeName,0);
}
- /**
- * @see com.aparapi.device
- */
- @SuppressWarnings("deprecation")
- @Deprecated
- public static Device firstCPU() {
- return KernelManager.DeprecatedMethods.firstDevice(TYPE.CPU);
- }
+ public static Device getDevice(String platformName, String deviceTypeName, int deviceId)
+ {
+ List platforms = (new OpenCLPlatform()).getOpenCLPlatformsFilteredBy(platformName); //getOpenCLPlatforms();
- /**
- * @see com.aparapi.device
- */
- @Deprecated
- public static Device bestACC() {
- throw new UnsupportedOperationException();
- }
+ int platformc = 0;
+ for (OpenCLPlatform platform : platforms)
+ {
+ //if(platform.getName().contains(platformName))
+ //{
- protected TYPE type = TYPE.UNKNOWN;
+ System.out.println("Platform " + platformc + "{");
- protected int maxWorkGroupSize;
+ System.out.println(" Name : \"" + platform.getName() + "\"");
- protected int maxWorkItemDimensions;
+ System.out.println(" Vendor : \"" + platform.getVendor() + "\"");
- protected int[] maxWorkItemSize = new int[] {
- 0,
- 0,
- 0
- };
+ System.out.println(" Version : \"" + platform.getVersion() + "\"");
- public abstract String getShortDescription();
+ List devices = platform.getOpenCLDevices();
- public TYPE getType() {
- return type;
- }
+ System.out.println(" Platform contains " + devices.size() + " OpenCL devices");
- public void setType(TYPE type) {
- this.type = type;
- }
+ int devicec = 0;
- public int getMaxWorkItemDimensions() {
- return maxWorkItemDimensions;
- }
+ for (OpenCLDevice device : devices)
+ {
+ if( device.getType().name().equalsIgnoreCase(deviceTypeName))
+ {
- public void setMaxWorkItemDimensions(int _maxWorkItemDimensions) {
- maxWorkItemDimensions = _maxWorkItemDimensions;
- }
+ System.out.println(" Device " + devicec + "{");
- public int getMaxWorkGroupSize() {
- return maxWorkGroupSize;
- }
+ System.out.println(" Type : " + device.getType());
- public void setMaxWorkGroupSize(int _maxWorkGroupSize) {
- maxWorkGroupSize = _maxWorkGroupSize;
- }
+ System.out.println(" GlobalMemSize : " + device.getGlobalMemSize());
- public int[] getMaxWorkItemSize() {
- return maxWorkItemSize;
- }
+ System.out.println(" LocalMemSize : " + device.getLocalMemSize());
- public void setMaxWorkItemSize(int[] maxWorkItemSize) {
- this.maxWorkItemSize = maxWorkItemSize;
- }
-
- public Range createRange(int _globalWidth) {
- return (Range.create(this, _globalWidth));
- }
-
- public Range createRange(int _globalWidth, int _localWidth) {
- return (Range.create(this, _globalWidth, _localWidth));
- }
+ System.out.println(" MaxComputeUnits : " + device.getMaxComputeUnits());
- public Range createRange2D(int _globalWidth, int _globalHeight) {
- return (Range.create2D(this, _globalWidth, _globalHeight));
- }
+ System.out.println(" MaxWorkGroupSizes : " + device.getMaxWorkGroupSize());
- public Range createRange2D(int _globalWidth, int _globalHeight, int _localWidth, int _localHeight) {
- return (Range.create2D(this, _globalWidth, _globalHeight, _localWidth, _localHeight));
- }
+ System.out.println(" MaxWorkItemDimensions : " + device.getMaxWorkItemDimensions());
- public Range createRange3D(int _globalWidth, int _globalHeight, int _globalDepth) {
- return (Range.create3D(this, _globalWidth, _globalHeight, _globalDepth));
- }
+ System.out.println(" }");
+
+ if(deviceId>0 && (devicec!=deviceId))
+ {
+ System.out.println("!!! devicec!=deviceId(" + deviceId + ") => continue search !!!");
+ continue;
+ }
+
+ // close platform bracket
+ System.out.println("}");
- public Range createRange3D(int _globalWidth, int _globalHeight, int _globalDepth, int _localWidth, int _localHeight,
- int _localDepth) {
- return (Range.create3D(this, _globalWidth, _globalHeight, _globalDepth, _localWidth, _localHeight, _localDepth));
- }
+ return device;
+ }
- public abstract long getDeviceId();
+ devicec++;
+ }
+ System.out.println("Device type/id combination not found");
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof Device)) {
- return false;
- }
+ System.out.println("}");
- Device device = (Device) o;
+ platformc++;
- return getDeviceId() == device.getDeviceId();
- }
+ }
- @Override
- public int hashCode() {
- return Long.valueOf(getDeviceId()).hashCode();
+ //}
+ // return not found !!!
+ return null;
}
}
diff --git a/src/main/java/com/aparapi/device/JavaDevice.java b/src/main/java/com/aparapi/device/JavaDevice.java
index eaeb8abe..c3046fdd 100644
--- a/src/main/java/com/aparapi/device/JavaDevice.java
+++ b/src/main/java/com/aparapi/device/JavaDevice.java
@@ -15,33 +15,33 @@
*/
package com.aparapi.device;
-public class JavaDevice extends Device {
+public class JavaDevice extends Device{
- public static final JavaDevice THREAD_POOL = new JavaDevice(TYPE.JTP, "Java Thread Pool", -3);
- public static final JavaDevice ALTERNATIVE_ALGORITHM = new JavaDevice(TYPE.ALT, "Java Alternative Algorithm", -2);
- public static final JavaDevice SEQUENTIAL = new JavaDevice(TYPE.SEQ, "Java Sequential", -1);
+ public static final JavaDevice THREAD_POOL = new JavaDevice(TYPE.JTP, "Java Thread Pool", -3);
+ public static final JavaDevice ALTERNATIVE_ALGORITHM = new JavaDevice(TYPE.ALT, "Java Alternative Algorithm", -2);
+ public static final JavaDevice SEQUENTIAL = new JavaDevice(TYPE.SEQ, "Java Sequential", -1);
- private final String name;
- private final long deviceId;
+ private final String name;
+ private final long deviceId;
- private JavaDevice(TYPE _type, String _name, long deviceId) {
- this.deviceId = deviceId;
- this.type = _type;
- this.name = _name;
- }
+ private JavaDevice(TYPE _type, String _name, long deviceId) {
+ this.deviceId = deviceId;
+ this.type = _type;
+ this.name = _name;
+ }
- @Override
- public String getShortDescription() {
- return name;
- }
+ @Override
+ public String getShortDescription() {
+ return name;
+ }
- @Override
- public long getDeviceId() {
- return deviceId;
- }
+ @Override
+ public long getDeviceId() {
+ return deviceId;
+ }
- @Override
- public String toString() {
- return getShortDescription();
- }
+ @Override
+ public String toString() {
+ return getShortDescription();
+ }
}
diff --git a/src/main/java/com/aparapi/device/OpenCLDevice.java b/src/main/java/com/aparapi/device/OpenCLDevice.java
index fbd86e40..e8968722 100644
--- a/src/main/java/com/aparapi/device/OpenCLDevice.java
+++ b/src/main/java/com/aparapi/device/OpenCLDevice.java
@@ -470,7 +470,10 @@ public static OpenCLDevice select(DeviceSelector _deviceSelector) {
OpenCLDevice device = null;
final OpenCLPlatform platform = new OpenCLPlatform(0, null, null, null);
- for (final OpenCLPlatform p : platform.getOpenCLPlatforms()) {
+ //!!! oren change 2.15.15 -> allow choosing a platform when multiple platforms are available
+ // Currently aparapi does not offer a way to choose a platform
+ //for (final OpenCLPlatform p : platform.getOpenCLPlatforms()) {
+ for (final OpenCLPlatform p : platform.getOpenCLPlatformsFilteredByConfig()) {
for (final OpenCLDevice d : p.getOpenCLDevices()) {
device = _deviceSelector.select(d);
if (device != null) {
@@ -508,7 +511,10 @@ public static OpenCLDevice select(DeviceComparitor _deviceComparitor, Device.TYP
OpenCLDevice device = null;
final OpenCLPlatform platform = new OpenCLPlatform(0, null, null, null);
- for (final OpenCLPlatform p : platform.getOpenCLPlatforms()) {
+ //!!! oren change 2.15.15 -> allow choosing a platform when multiple platforms are available
+ // Currently aparapi does not offer a way to choose a platform
+ //for (final OpenCLPlatform p : platform.getOpenCLPlatforms()) {
+ for (final OpenCLPlatform p : platform.getOpenCLPlatformsFilteredByConfig()) {
for (final OpenCLDevice d : p.getOpenCLDevices()) {
if (d.getType() != _type) continue;
if (device == null) {
diff --git a/src/main/java/com/aparapi/device/package-info.java b/src/main/java/com/aparapi/device/package-info.java
index fd8989ab..40e46a38 100644
--- a/src/main/java/com/aparapi/device/package-info.java
+++ b/src/main/java/com/aparapi/device/package-info.java
@@ -14,21 +14,6 @@
* limitations under the License.
*/
/**
- * Contains classes representing OpenCL-capable devices, and "virtual" (java) devices which execute kernels using java.
- *
- * Various methods of {@link com.aparapi.device.Device} which selected devices of a particular type have been deprecated,
- * as now the preferred mechanism for device selection is to rely on the {@link com.aparapi.internal.kernel.KernelManager} to
- * select an appropriate device. Where a particular device is required to be used for a certain kernel, for such purposes as
- * debugging or unit testing, this can be achieved by using
- * {@link com.aparapi.internal.kernel.KernelManager#setKernelManager(com.aparapi.internal.kernel.KernelManager)} prior to
- * invoking any Kernel executions, by overriding {@link com.aparapi.Kernel#isAllowDevice(com.aparapi.device.Device)}
- * to veto/approve devices from the available devices for a given Kernel class, or (not recommended) by using
- * {@link com.aparapi.internal.kernel.KernelManager#setPreferredDevices(com.aparapi.Kernel, java.util.LinkedHashSet)} to specify
- * a particular device list for a given Kernel class.
- *
- *
In order to determine the Device which will be used to execute a particular Kernel, use {@link com.aparapi.Kernel#getTargetDevice()}.
- * This can also be used immediately after execution to see on which device the kernel actually got executed (in case the execution failed
- * and fell back to another device).
*
*/
package com.aparapi.device;
\ No newline at end of file
diff --git a/src/main/java/com/aparapi/internal/jni/ConfigJNI.java b/src/main/java/com/aparapi/internal/jni/ConfigJNI.java
index 91f4ab44..3fbe3c1c 100644
--- a/src/main/java/com/aparapi/internal/jni/ConfigJNI.java
+++ b/src/main/java/com/aparapi/internal/jni/ConfigJNI.java
@@ -44,6 +44,15 @@ public abstract class ConfigJNI{
*/
@UsedByJNICode public static final boolean enableProfilingCSV = Boolean.getBoolean(propPkgName + ".enableProfilingCSV");
+ //!!! oren change 2.15.19 -> Allows the user to set profile file name format
+ /**
+ * Allows the user to set profile file name format
+ *
+ * Usage -Dcom.amd.aparapi.profilingFileNameFormatStr={format string}
+ *
+ */
+ @UsedByJNICode public static final String profilingFileNameFormatStr = System.getProperty(propPkgName + ".profilingFileNameFormatStr");
+
/**
* Allows the user to request that verbose JNI messages be dumped to stderr.
*
diff --git a/src/main/java/com/aparapi/internal/jni/KernelRunnerJNI.java b/src/main/java/com/aparapi/internal/jni/KernelRunnerJNI.java
index 2ef6a54f..4a0ed0a7 100644
--- a/src/main/java/com/aparapi/internal/jni/KernelRunnerJNI.java
+++ b/src/main/java/com/aparapi/internal/jni/KernelRunnerJNI.java
@@ -304,6 +304,19 @@ public abstract class KernelRunnerJNI{
@UsedByJNICode protected static final int JNI_FLAG_USE_ACC = 1 << 5;
+ /** !!! oren change ->
+ * These flags indicate that we want to build source/binary i.e. use source/binary flow.
+ *
+ * Be careful changing final constants starting with JNI.
+ *
+ * @see com.aparapi.internal.annotation.UsedByJNICode
+ *
+ * @author oren
+ */
+ @UsedByJNICode public static final int JNI_FLAG_SOURCE_FLOW = 1 << 0;
+ @UsedByJNICode public static final int JNI_FLAG_BINARY_FLOW = 1 << 1;
+ @UsedByJNICode public static final int JNI_FLAG_DEFAULT_FLOW = 1 << 2;
+
/*
* Native methods
*/
@@ -330,7 +343,7 @@ public abstract class KernelRunnerJNI{
* can be passed empty) andused the cached binary.
*
By passing an empty String as the _binaryKey, the entire JNI-side binary caching apparatus can be disabled.
*/
- protected native long buildProgramJNI(long _jniContextHandle, String _source, String _binaryKey);
+ protected native long buildProgramJNI(long _jniContextHandle, String _source, int _buildFlags);
protected native int setArgsJNI(long _jniContextHandle, KernelArgJNI[] _args, int argc);
diff --git a/src/main/java/com/aparapi/internal/jni/OpenCLJNI.java b/src/main/java/com/aparapi/internal/jni/OpenCLJNI.java
index 189b5358..a2168006 100644
--- a/src/main/java/com/aparapi/internal/jni/OpenCLJNI.java
+++ b/src/main/java/com/aparapi/internal/jni/OpenCLJNI.java
@@ -15,9 +15,9 @@
*/
package com.aparapi.internal.jni;
-import com.aparapi.ProfileInfo;
import java.util.List;
+import com.aparapi.ProfileInfo;
import com.aparapi.device.OpenCLDevice;
import com.aparapi.internal.opencl.OpenCLArgDescriptor;
import com.aparapi.internal.opencl.OpenCLKernel;
@@ -32,12 +32,7 @@ public abstract class OpenCLJNI{
protected native List getPlatforms();
- public OpenCLProgram createProgram(OpenCLDevice context, String openCLSource)
- {
- return this.createProgram(context, openCLSource, null);
- }
-
- protected native OpenCLProgram createProgram(OpenCLDevice context, String openCLSource, String binaryKey);
+ protected native OpenCLProgram createProgram(OpenCLDevice context, String openCLSource);
protected native OpenCLKernel createKernelJNI(OpenCLProgram program, String kernelName, OpenCLArgDescriptor[] args);
diff --git a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java
index 66d34cf6..08458478 100644
--- a/src/main/java/com/aparapi/internal/kernel/KernelRunner.java
+++ b/src/main/java/com/aparapi/internal/kernel/KernelRunner.java
@@ -170,6 +170,16 @@ public KernelRunner(Kernel _kernel) {
KernelManager.instance(); // ensures static initialization of KernelManager
}
+ public void init(KernelRunner kernelRunner) {
+ //this = super.clone();
+ jniContextHandle = kernelRunner.jniContextHandle;
+ entryPoint = kernelRunner.entryPoint;
+ argc = kernelRunner.argc;
+ args = kernelRunner.args;
+ //puts = kernelRunner.puts;
+ capabilitiesSet = kernelRunner.capabilitiesSet;
+ }
+
/**
* @see Kernel#cleanUpArrays().
*/
@@ -1356,28 +1366,11 @@ else if (Config.enableShowGeneratedOpenCL) {
// Send the string to OpenCL to compile it, or if the compiled binary is already cached on JNI side just empty string to use cached binary
long handle;
- if (BINARY_CACHING_DISABLED) {
- handle = buildProgramJNI(jniContextHandle, openCL, "");
- } else {
- synchronized (seenBinaryKeys) {
- String binaryKey = kernel.getClass().getName() + ":" + device.getDeviceId();
- if (seenBinaryKeys.contains(binaryKey)) {
- // use cached binary
- logger.log(Level.INFO, "reusing cached binary for " + binaryKey);
- handle = buildProgramJNI(jniContextHandle, "", binaryKey);
- }
- else {
- // create and cache binary
- logger.log(Level.INFO, "compiling new binary for " + binaryKey);
- handle = buildProgramJNI(jniContextHandle, openCL, binaryKey);
- seenBinaryKeys.add(binaryKey);
- }
- }
- }
- _settings.profile.onEvent(ProfilingEvent.OPENCL_COMPILED);
- if (handle == 0) {
+ int buildFlags = kernel.getFlowType().getValue();
+ if (buildProgramJNI(jniContextHandle, openCL,buildFlags) == 0) {
return fallBackToNextDevice(_settings, "OpenCL compile failed");
}
+ _settings.profile.onEvent(ProfilingEvent.OPENCL_COMPILED);
args = new KernelArg[entryPoint.getReferencedFields().size()];
int i = 0;
diff --git a/src/main/java/com/aparapi/internal/model/Entrypoint.java b/src/main/java/com/aparapi/internal/model/Entrypoint.java
index 287b406d..ce3e6451 100644
--- a/src/main/java/com/aparapi/internal/model/Entrypoint.java
+++ b/src/main/java/com/aparapi/internal/model/Entrypoint.java
@@ -174,7 +174,10 @@ public static Field getFieldFromClassHierarchy(Class> _clazz, String _name) th
try {
field = _clazz.getDeclaredField(_name);
final Class> type = field.getType();
- if (type.isPrimitive() || type.isArray()) {
+ // !!! oren test - for alternative memory types
+ //if (type.isPrimitive() || type.isArray())
+ if (type.isPrimitive() || type.isArray() || type.getName().contains("java.nio"))
+ {
return field;
}
if (field.getAnnotation(Kernel.NoCL.class) != null) {
diff --git a/src/main/java/com/aparapi/internal/opencl/OpenCLLoader.java b/src/main/java/com/aparapi/internal/opencl/OpenCLLoader.java
index 63bfa6b5..46da8bfa 100644
--- a/src/main/java/com/aparapi/internal/opencl/OpenCLLoader.java
+++ b/src/main/java/com/aparapi/internal/opencl/OpenCLLoader.java
@@ -26,47 +26,46 @@
/**
* This class is intended to be a singleton which determines if OpenCL is available upon startup of Aparapi
*/
-public class OpenCLLoader extends OpenCLJNI{
+public class OpenCLLoader extends OpenCLJNI {
- private static final Logger logger = Logger.getLogger(Config.getLoggerName());
+ private static final Logger logger = Logger.getLogger(Config.getLoggerName());
- private static boolean openCLAvailable = false;
+ private static boolean openCLAvailable = false;
- private static final OpenCLLoader instance = new OpenCLLoader();
+ private static final OpenCLLoader instance = new OpenCLLoader();
- static {
- if (Config.useAgent) {
- logger.fine("Using agent!");
- openCLAvailable = true;
- } else {
+ static {
+ if (Config.useAgent) {
+ logger.fine("Using agent!");
+ openCLAvailable = true;
+ } else {
try {
- NativeLoader.load();
- logger.info("Aparapi JNI loaded successfully.");
- openCLAvailable = true;
+ NativeLoader.load();
+ logger.info("Aparapi JNI loaded successfully.");
+ openCLAvailable = true;
+ } catch (final IOException e) {
+ logger.log(Level.SEVERE, "Check your environment. Failed to load aparapi native library "
+ + " or possibly failed to locate opencl native library (opencl.dll/opencl.so)."
+ + " Ensure that OpenCL is in your PATH (windows) or in LD_LIBRARY_PATH (linux).");
}
- catch (final IOException e) {
- logger.log(Level.SEVERE, "Check your environment. Failed to load aparapi native library "
- + " or possibly failed to locate opencl native library (opencl.dll/opencl.so)."
- + " Ensure that OpenCL is in your PATH (windows) or in LD_LIBRARY_PATH (linux).");
- }
- }
- }
+ }
+ }
- /**
- * Retrieve a singleton instance of OpenCLLoader
- *
- * @return A singleton instance of OpenCLLoader
- */
- protected static OpenCLLoader getInstance() {
- return instance;
- }
+ /**
+ * Retrieve a singleton instance of OpenCLLoader
+ *
+ * @return A singleton instance of OpenCLLoader
+ */
+ protected static OpenCLLoader getInstance() {
+ return instance;
+ }
- /**
- * Retrieve the status of whether OpenCL was successfully loaded
- *
- * @return The status of whether OpenCL was successfully loaded
- */
- public static boolean isOpenCLAvailable() {
- return openCLAvailable;
- }
+ /**
+ * Retrieve the status of whether OpenCL was successfully loaded
+ *
+ * @return The status of whether OpenCL was successfully loaded
+ */
+ public static boolean isOpenCLAvailable() {
+ return openCLAvailable;
+ }
}
diff --git a/src/main/java/com/aparapi/internal/opencl/OpenCLPlatform.java b/src/main/java/com/aparapi/internal/opencl/OpenCLPlatform.java
index ac2b5201..28f0b491 100644
--- a/src/main/java/com/aparapi/internal/opencl/OpenCLPlatform.java
+++ b/src/main/java/com/aparapi/internal/opencl/OpenCLPlatform.java
@@ -18,9 +18,12 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Iterator;
+import java.util.List;
import com.aparapi.device.OpenCLDevice;
import com.aparapi.internal.jni.OpenCLJNI;
+import com.aparapi.Config;
public class OpenCLPlatform extends OpenCLJNI{
@@ -85,6 +88,48 @@ public static List getUncachedOpenCLPlatforms(){
return platforms;
}
+ //!!! oren change 2.15.15 -> allow choosing a platform when multiple platforms are available
+ // Currently aparapi does not offer a way to choose a platform
+ public List getOpenCLPlatformsFilteredByConfig()
+ {
+ return getOpenCLPlatformsFilteredBy(Config.platformHint);
+ }
+
+ public List getOpenCLPlatformsFilteredBy(String filter)
+ {
+ if (OpenCLLoader.isOpenCLAvailable())
+ {
+ List platformList = (getPlatforms());
+ if(filter==null)
+ {
+ System.out.println("Not Filtering Platforms. Platform filter is empty!");
+ }
+ else
+ {
+ System.out.println("Filtering Platforms using: " + filter );
+ for (Iterator iterator = platformList.iterator(); iterator.hasNext(); )
+ {
+ String platformName = iterator.next().getName();
+ if (filter.equals("*") || platformName.contains(filter))
+ {
+ System.out.println("Adding Platform: " + platformName );
+ }
+ else
+ {
+ System.out.println("Discarding Platform: " + platformName);
+ iterator.remove();
+ }
+
+ }
+ }
+ return (platformList);
+ }
+ else
+ {
+ return (new ArrayList());
+ }
+ }
+
public String getName() {
return (name);
}
diff --git a/wiki-collateral/ProfilingKernelsFormEclipseProject.zip b/wiki-collateral/ProfilingKernelsFormEclipseProject.zip
new file mode 100644
index 00000000..28566548
Binary files /dev/null and b/wiki-collateral/ProfilingKernelsFormEclipseProject.zip differ