void requireMinVersionValue(String feature, double minValue) { requireMinVersionValue(feature, minValue, Double.NaN); } private Set<String> featuresCheckedForVersion = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
void requireMinVersionValue(String feature, double minValue) { requireMinVersionValue(feature, minValue, Double.NaN); } private Set<String> featuresCheckedForVersion = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
/** * Whether the device and the host have a unified memory subsystem. * @since OpenCL 1.1 */ @InfoName("CL_DEVICE_HOST_UNIFIED_MEMORY") public boolean isHostUnifiedMemory() { platform.requireMinVersionValue("CL_DEVICE_HOST_UNIFIED_MEMORY", 1.1); return infos.getBool(getEntity(), CL_DEVICE_HOST_UNIFIED_MEMORY); }
/** * Allows the implementation to release the resources allocated by the OpenCL compiler for this platform. */ public void unloadPlatformCompiler() { if (getVersionValue() < 1.2) { requireMinVersionValue("clUnloadCompiler", 1.1, 1.2); error(CL.clUnloadCompiler()); } else { requireMinVersionValue("clUnloadPlatformCompiler", 1.2); error(CL.clUnloadPlatformCompiler(getEntity())); } }
/** * Whether the device and the host have a unified memory subsystem. * @since OpenCL 1.1 */ @InfoName("CL_DEVICE_HOST_UNIFIED_MEMORY") public boolean isHostUnifiedMemory() { platform.requireMinVersionValue("CL_DEVICE_HOST_UNIFIED_MEMORY", 1.1); return infos.getBool(getEntity(), CL_DEVICE_HOST_UNIFIED_MEMORY); }
/** * Allows the implementation to release the resources allocated by the OpenCL compiler for this platform. */ public void unloadPlatformCompiler() { if (getVersionValue() < 1.2) { requireMinVersionValue("clUnloadCompiler", 1.1, 1.2); error(CL.clUnloadCompiler()); } else { requireMinVersionValue("clUnloadPlatformCompiler", 1.2); error(CL.clUnloadPlatformCompiler(getEntity())); } }
/** * Returns the preferred multiple of work- group size for launch. <br> * This is a performance hint. <br> * Specifying a work- group size that is not a multiple of the value returned by this query as the value of the local work size argument to clEnqueueNDRangeKernel will not fail to enqueue the kernel for execution unless the work-group size specified is larger than the device maximum. * @since OpenCL 1.1 */ public Map<CLDevice, Long> getPreferredWorkGroupSizeMultiple() { program.getContext().getPlatform().requireMinVersionValue("CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE", 1.1); CLDevice[] devices = program.getDevices(); Map<CLDevice, Long> ret = new HashMap<CLDevice, Long>(devices.length); for (CLDevice device : devices) ret.put(device, getKernelInfos().getIntOrLong(device.getEntity(), CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE)); return ret; }
/** * Returns the preferred multiple of work- group size for launch. <br> * This is a performance hint. <br> * Specifying a work- group size that is not a multiple of the value returned by this query as the value of the local work size argument to clEnqueueNDRangeKernel will not fail to enqueue the kernel for execution unless the work-group size specified is larger than the device maximum. * @since OpenCL 1.1 */ public Map<CLDevice, Long> getPreferredWorkGroupSizeMultiple() { program.getContext().getPlatform().requireMinVersionValue("CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE", 1.1); CLDevice[] devices = program.getDevices(); Map<CLDevice, Long> ret = new HashMap<CLDevice, Long>(devices.length); for (CLDevice device : devices) ret.put(device, getKernelInfos().getIntOrLong(device.getEntity(), CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE)); return ret; }
@SuppressWarnings("deprecation") public void setProperty(CLDevice.QueueProperties property, boolean enabled) { context.getPlatform().requireMinVersionValue("clSetCommandQueueProperty", 1.0, 1.1); error(CL.clSetCommandQueueProperty(getEntity(), property.value(), enabled ? CL_TRUE : CL_FALSE, 0)); }
@SuppressWarnings("deprecation") public void setProperty(CLDevice.QueueProperties property, boolean enabled) { context.getPlatform().requireMinVersionValue("clSetCommandQueueProperty", 1.0, 1.1); error(CL.clSetCommandQueueProperty(getEntity(), property.value(), enabled ? CL_TRUE : CL_FALSE, 0)); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clSetEventCallback.html">clSetEventCallback</a>.<br> * Registers a user callback function for a specific command execution status. <br> * The registered callback function will be called when the execution status of command associated with event changes to the execution status specified by command_exec_status. * @param commandExecStatus specifies the command execution status for which the callback is registered. The command execution callback values for which a callback can be registered are: CL_COMPLETE. There is no guarantee that the callback functions registered for various execution status values for an event will be called in the exact order that the execution status of a command changes. * @param callback * @throws UnsupportedOperationException in OpenCL 1.0 * @since OpenCL 1.1 */ public void setCallback(int commandExecStatus, final EventCallback callback) { queue.getContext().getPlatform().requireMinVersionValue("clSetEventCallback", 1.1); error(CL.clSetEventCallback(getEntity(), commandExecStatus, eventCallbackPeer, JNI.newGlobalRef(callback))); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clSetEventCallback.html">clSetEventCallback</a>.<br> * Registers a user callback function for a specific command execution status. <br> * The registered callback function will be called when the execution status of command associated with event changes to the execution status specified by command_exec_status. * @param commandExecStatus specifies the command execution status for which the callback is registered. The command execution callback values for which a callback can be registered are: CL_COMPLETE. There is no guarantee that the callback functions registered for various execution status values for an event will be called in the exact order that the execution status of a command changes. * @param callback * @throws UnsupportedOperationException in OpenCL 1.0 * @since OpenCL 1.1 */ public void setCallback(int commandExecStatus, final EventCallback callback) { queue.getContext().getPlatform().requireMinVersionValue("clSetEventCallback", 1.1); error(CL.clSetEventCallback(getEntity(), commandExecStatus, eventCallbackPeer, JNI.newGlobalRef(callback))); }
/** * Creates a user event object. <br> * User events allow applications to enqueue commands that wait on a user event to finish before the command is executed by the device. * @since OpenCL 1.1 */ public CLUserEvent createUserEvent() { platform.requireMinVersionValue("clCreateUserEvent", 1.1); ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pErr = ptrs.pErr; long evt = CL.clCreateUserEvent(getEntity(), getPeer(pErr)); error(pErr.getInt()); return (CLUserEvent)CLEvent.createEvent(null, evt, true); }
/** * Creates a user event object. <br> * User events allow applications to enqueue commands that wait on a user event to finish before the command is executed by the device. * @since OpenCL 1.1 */ public CLUserEvent createUserEvent() { platform.requireMinVersionValue("clCreateUserEvent", 1.1); ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pErr = ptrs.pErr; long evt = CL.clCreateUserEvent(getEntity(), getPeer(pErr)); error(pErr.getInt()); return (CLUserEvent)CLEvent.createEvent(null, evt, true); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueWaitForEvents.html">clEnqueueWaitForEvents</a>.<br> * Enqueues a wait for a specific event or a list of events to complete before any future commands queued in the this queue are executed. */ public void enqueueWaitForEvents(CLEvent... eventsToWaitFor) { context.getPlatform().requireMinVersionValue("clEnqueueWaitForEvents", 1.1, 1.2); ReusablePointers ptrs = ReusablePointers.get(); int[] eventsInCount = ptrs.int1Array; Pointer<cl_event> eventsIn = CLAbstractEntity.copyNonNullEntities(eventsToWaitFor, eventsInCount, ptrs.events_in); if (eventsIn == null) return; error(CL.clEnqueueWaitForEvents(getEntity(), eventsInCount[0], getPeer(eventsIn) )); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clEnqueueWaitForEvents.html">clEnqueueWaitForEvents</a>.<br> * Enqueues a wait for a specific event or a list of events to complete before any future commands queued in the this queue are executed. */ public void enqueueWaitForEvents(CLEvent... eventsToWaitFor) { context.getPlatform().requireMinVersionValue("clEnqueueWaitForEvents", 1.1, 1.2); ReusablePointers ptrs = ReusablePointers.get(); int[] eventsInCount = ptrs.int1Array; Pointer<cl_event> eventsIn = CLAbstractEntity.copyNonNullEntities(eventsToWaitFor, eventsInCount, ptrs.events_in); if (eventsIn == null) return; error(CL.clEnqueueWaitForEvents(getEntity(), eventsInCount[0], getPeer(eventsIn) )); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubBuffer.html">clCreateSubBuffer</a>.<br> * Can be used to create a new buffer object (referred to as a sub-buffer object) from an existing buffer object. * @param usage is used to specify allocation and usage information about the image memory object being created and is described in table 5.3 of the OpenCL spec. * @param offset * @param length length in bytes * @since OpenCL 1.1 * @return sub-buffer that is a "window" of this buffer starting at the provided offset, with the provided length */ public CLBuffer<T> createSubBuffer(Usage usage, long offset, long length) { context.getPlatform().requireMinVersionValue("clCreateSubBuffer", 1.1); int s = getElementSize(); cl_buffer_region region = new cl_buffer_region().origin(s * offset).size(s * length); ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pErr = ptrs.pErr; long mem = CL.clCreateSubBuffer(getEntity(), usage.getIntFlags(), CL_BUFFER_CREATE_TYPE_REGION, getPeer(getPointer(region)), getPeer(pErr)); error(pErr.getInt()); return mem == 0 ? null : new CLBuffer<T>(context, length * s, mem, null, io); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubBuffer.html">clCreateSubBuffer</a>.<br> * Can be used to create a new buffer object (referred to as a sub-buffer object) from an existing buffer object. * @param usage is used to specify allocation and usage information about the image memory object being created and is described in table 5.3 of the OpenCL spec. * @param offset * @param length length in bytes * @since OpenCL 1.1 * @return sub-buffer that is a "window" of this buffer starting at the provided offset, with the provided length */ public CLBuffer<T> createSubBuffer(Usage usage, long offset, long length) { context.getPlatform().requireMinVersionValue("clCreateSubBuffer", 1.1); int s = getElementSize(); cl_buffer_region region = new cl_buffer_region().origin(s * offset).size(s * length); ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pErr = ptrs.pErr; long mem = CL.clCreateSubBuffer(getEntity(), usage.getIntFlags(), CL_BUFFER_CREATE_TYPE_REGION, getPeer(getPointer(region)), getPeer(pErr)); error(pErr.getInt()); return mem == 0 ? null : new CLBuffer<T>(context, length * s, mem, null, io); }
/** * Creates an array of sub-devices that each reference a non-intersecting set of compute units within this device. * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubDevices.html">clCreateSubDevices</a>.<br> * @param eventsToWaitFor Events that need to complete before this particular command can be executed. Special value {@link CLEvent#FIRE_AND_FORGET} can be used to avoid returning a CLEvent. * @return Event object that identifies this command and can be used to query or queue a wait for the command to complete, or null if eventsToWaitFor contains {@link CLEvent#FIRE_AND_FORGET}. */ CLDevice[] createSubDevices(Pointer<SizeT> pProperties) { platform.requireMinVersionValue("clCreateSubDevices", 1.2); ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pNum = ptrs.int1; error(CL.clCreateSubDevices(getEntity(), getPeer(pProperties), 0, 0, getPeer(pNum))); int num = pNum.getInt(); Pointer<SizeT> pDevices = allocateSizeTs(num); error(CL.clCreateSubDevices(getEntity(), getPeer(pProperties), num, getPeer(pDevices), 0)); CLDevice[] devices = new CLDevice[(int) num]; for (int i = 0; i < num; i++) { devices[i] = new CLDevice(platform, this, pDevices.getSizeTAtIndex(i), true); } pDevices.release(); return devices; }
/** * Creates an array of sub-devices that each reference a non-intersecting set of compute units within this device. * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateSubDevices.html">clCreateSubDevices</a>.<br> * @param eventsToWaitFor Events that need to complete before this particular command can be executed. Special value {@link CLEvent#FIRE_AND_FORGET} can be used to avoid returning a CLEvent. * @return Event object that identifies this command and can be used to query or queue a wait for the command to complete, or null if eventsToWaitFor contains {@link CLEvent#FIRE_AND_FORGET}. */ CLDevice[] createSubDevices(Pointer<SizeT> pProperties) { platform.requireMinVersionValue("clCreateSubDevices", 1.2); ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pNum = ptrs.int1; error(CL.clCreateSubDevices(getEntity(), getPeer(pProperties), 0, 0, getPeer(pNum))); int num = pNum.getInt(); Pointer<SizeT> pDevices = allocateSizeTs(num); error(CL.clCreateSubDevices(getEntity(), getPeer(pProperties), num, getPeer(pDevices), 0)); CLDevice[] devices = new CLDevice[(int) num]; for (int i = 0; i < num; i++) { devices[i] = new CLDevice(platform, this, pDevices.getSizeTAtIndex(i), true); } pDevices.release(); return devices; }