* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
+/**
+ * Some basic demonstration examples for OpenCL using zcl.
+ */
module notzed.zcl.demo {
requires notzed.zcl;
+
+ exports au.notzed.zcl.tools;
}
import java.lang.reflect.InvocationTargetException;
import java.lang.System.Logger.Level;
+/**
+ * Base class for all native objects.
+ *
+ * Handles instantiation and provides helper functions for native access.
+ *
+ * Work in progress.
+ */
public class Native {
private final MemoryAddress p;
}
/* helpers - java to native */
- public static <T extends Native> MemoryAddress toAddrV(Allocator frame, T[]array) {
- MemoryAddress list = frame.alloca(8 * array.length);
+ public static <T extends Native> MemoryAddress toAddrV(Allocator frame, T[]array, int len) {
+ MemoryAddress list = frame.alloca(8 * len);
- for (int i=0;i<array.length;i++)
+ for (int i=0;i<len;i++)
setAddr(list, i, array[i].addr());
return list;
}
+ public static <T extends Native> MemoryAddress toAddrV(Allocator frame, T[]array) {
+ return toAddrV(frame, array, array.length);
+ }
+
public static <T extends Native> MemoryAddress toAddrV(Allocator frame, String[]array) {
if (array != null) {
- MemoryAddress list = frame.alloca(8 * array.length);
+ MemoryAddress list = frame.alloca(8 * array.length);
for (int i=0;i<array.length;i++)
setAddr(list, i, toByteV(frame, array[i]));
}
public static <T extends Native> MemoryAddress toLongV(Allocator frame, long[]array) {
- MemoryAddress list = frame.alloca(8 * array.length);
+ MemoryAddress list = frame.alloca(8 * array.length);
for (int i=0;i<array.length;i++)
setLong(list, i, array[i]);
import jdk.incubator.foreign.*;
import java.nio.ByteBuffer;
-import java.lang.invoke.MethodHandle;
/**
* Interface for memory buffers.
- * <p>
*/
public class CLBuffer extends CLMemory {
- /**
- * Create an interface for a native pointer of type cl_mem that refers to a
- * buffer object.
- *
- * @param p Native pointer.
- */
public CLBuffer(MemoryAddress p) {
this(p, null);
}
- public CLBuffer(MemoryAddress p, MemorySegment seg) {
+ CLBuffer(MemoryAddress p, MemorySegment seg) {
super(p, seg);
}
import java.nio.ByteOrder;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
-//import static au.au.notzed.zcl.CL.*;
//import au.notzed.zcl.khr.GLSharing;
import java.lang.invoke.MethodHandle;
*/
public class CLCommandQueue extends CLExtendable {
- /**
- * Create an interface for a native pointer of type cl_command_queue.
- *
- * @param p Native pointer.
- */
- CLCommandQueue(MemoryAddress p) {
+ public CLCommandQueue(MemoryAddress p) {
super(p);
}
- public static CLCommandQueue create(MemoryAddress p) {
+ static CLCommandQueue create(MemoryAddress p) {
return Native.resolve(p, CLCommandQueue::new);
}
* @param host_row_pitch
* @param host_slice_pitch
* @param buffer
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @throws CLException
* @throws UnsupportedOperationException
* @since OpenCL 1.1
* @param host_row_pitch
* @param host_slice_pitch
* @param buffer
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @throws CLException
* @throws UnsupportedOperationException
* @since OpenCL 1.1
* @param pattern pattern to fill
* @param offset offset in multiples of the pattern size.
* @param size number of elements in multiples of the pattern size.
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @since OpenCL 1.2
* @throws CLException
*/
* @param pattern pattern to fill
* @param offset offset in multiples of the pattern size.
* @param size number of elements in multiples of the pattern size.
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @since OpenCL 1.2
* @throws CLException
*/
* @param pattern pattern to fill
* @param offset offset in multiples of the pattern size.
* @param size number of elements in multiples of the pattern size.
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @since OpenCL 1.2
* @throws CLException
*/
* @param pattern pattern to fill
* @param offset offset in multiples of the pattern size.
* @param size number of elements in multiples of the pattern size.
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @since OpenCL 1.2
* @throws CLException
*/
* @param pattern pattern to fill
* @param offset offset in multiples of the pattern size in floats.
* @param size number of elements in multiples of the pattern size in floats.
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @since OpenCL 1.2
* @throws CLException
*/
* @param row_pitch
* @param slice_pitch
* @param buffer the position is honoured and updated
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @throws CLException
*/
public void enqueueReadImage(CLImage image, boolean blocking,
* @param slice_pitch in number of array elements
* @param buffer
* @param buff_offset in number of array elements
- * @param waiters
- * @param events
+ * @param wait
+ * @param event
* @throws CLException
*/
public void enqueueReadImage(CLImage image, boolean blocking,
import api.Allocator;
import api.Native;
import api.Callback;
-import java.util.stream.Stream;
-
import java.lang.invoke.MethodHandle;
-
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.Charset;
-import java.util.function.Function;
-import java.util.function.IntFunction;
-
/**
* Interface for cl_context
*/
*/
final Callback<CLContextNotify> notify;
- /**
- * Creates an interface for a native pointer of type cl_context.
- *
- * @param p Native pointer.
- */
public CLContext(MemoryAddress p) {
super(p);
this.notify = null;
*
* @param flags CL_MEM_* flags.
* @param size Size in bytes.
- * @param hostp Optional host memory pointer.
+ * @param hostseg Optional host memory pointer.
* @return Newly allocated buffer.
* @throws CLRuntimeException
*/
* @param flags CL_MEM_* flags.
* @param fmt Image format.
* @param desc Image descriptor. For OpenCL 1.2, only CL_MEM_OBJECT_IMAGE2D and CL_MEM_OBJECT_IMAGE3D are allowed.
- * @param hostp
+ * @param hostseg
* @return Newly allocated image.<p>
* release() should be called when it is no longer needed.
* @throws CLRuntimeException
package au.notzed.zcl;
import java.nio.ByteBuffer;
-import java.util.function.Function;
-import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemorySegment;
import api.Native;
import api.Callback;
return Callback.NULL;
}
}
-
-
}
*/
package au.notzed.zcl;
-import api.Native;
import java.lang.invoke.MethodHandle;
-import java.util.function.Function;
import jdk.incubator.foreign.*;
import static au.notzed.zcl.CL.*;
import static au.notzed.zcl.CLLib.*;
*/
public class CLDevice extends CLExtendable {
- /**
- * Create an interface for a native pointer of type cl_device_id.
- *
- * @param p Native pointer.
- */
public CLDevice(MemoryAddress p) {
super(p);
}
}
}
- //private native static void release(long p);
-
@Override
public String toString() {
return getName();
return getInfoInt(CL_DEVICE_PARTITION_MAX_SUB_DEVICES);
}
- //public native CLDeviceProperty[] getPartitionProperties();
+ public CLDeviceProperty[] getPartitionProperties() {
+ return getInfoPropertyV(CL_DEVICE_PARTITION_PROPERTIES, clGetDeviceInfo, CLDeviceProperty.TagValue::new, CLDeviceProperty[]::new);
+ }
public long getPartitionAffinityDomain() {
return getInfoLong(CL_DEVICE_PARTITION_AFFINITY_DOMAIN);
}
- //public native CLDeviceProperty[] getPartitionType();
-
- //public static CLDevice[] newArray(int n) {
- // return new CLDevice[n];
- //}
+ public CLDeviceProperty[] getPartitionType() {
+ return getInfoPropertyV(CL_DEVICE_PARTITION_TYPE, clGetDeviceInfo, CLDeviceProperty.TagValue::new, CLDeviceProperty[]::new);
+ }
}
}
@Override
- public int toInt(int[] dst, int o) {
- dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS;
- for (int c : counts) {
- dst[o++] = c;
- }
- dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END;
+ public int toInt(MemoryAddress dst, int o) {
+ Native.setInt(dst, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS);
+ for (int c : counts)
+ Native.setInt(dst, o++, c);
+ Native.setInt(dst, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END);
return o;
}
-
+
@Override
- public int toLong(long[] dst, int o) {
- dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS;
- for (int c : counts) {
- dst[o++] = c;
- }
- dst[o++] = CL.CL_DEVICE_PARTITION_BY_COUNTS_LIST_END;
- return o;
- }
-
public int toLong(MemoryAddress dst, int o) {
Native.setLong(dst, o++, CL.CL_DEVICE_PARTITION_BY_COUNTS);
for (int c : counts)
public class CLEvent extends CLObject {
/**
- * This is used to retain a reference for any callback set
+ * Cached and used for api version check
*/
- Callback<CLEventNotify> callback;
+ final int apiVersion;
/**
- * Create an interface for a native pointer of type cl_event.
- *
- * @param p Native pointer.
+ * This is used to retain a reference for any callback set
*/
+ Callback<CLEventNotify> callback;
+
public CLEvent(MemoryAddress p) {
super(p);
+
+ apiVersion = getContext().getAPIVersion();
}
- public static CLEvent create(MemoryAddress p) {
+ static CLEvent create(MemoryAddress p) {
return Native.resolve(p, CLEvent::new);
}
}
}
+ @Override
public void release() {
Native.release(callback);
callback = null;
* @since OpenCL 1.1
*/
public void setUserEventStatus(int status) throws CLRuntimeException {
- // avoid platform lookup for costs
- //requiredAPIVersion(CLPlatform.VERSION_1_1);
+ CLPlatform.requireAPIVersion(apiVersion, CLPlatform.VERSION_1_1);
try {
int res = clSetUserEventStatus(addr(), status);
* @since OpenCL 1.1
*/
public void setEventCallback(int type, CLEventNotify notify) throws CLRuntimeException {
- //requiredAPIVersion(CLPlatform.VERSION_1_1);
+ CLPlatform.requireAPIVersion(apiVersion, CLPlatform.VERSION_1_1);
Native.release(callback);
* this API binding and provides a much cleaner, efficient, and simple interface.
* <p>
* See {@link au.notzed.zcl.CLCommandQueue} for more information on usage.
- * <p>
* <h2>Internal Details</h2>
* <p>
* Internally the CLEventList is maintained as an array of long values which hold
* The JNI code directly reads from the events list and index in order to build
* a list of wait events, and calls the internal add(long) method to append to
* the events array.
- * <p>
*/
public class CLEventList {
/**
* Creates a new event list.
*
- * @param capacity Sets the event list capacity. This
+ * @param capacity Sets the event list capacity.
*/
public CLEventList(int capacity) {
this.jevents = new CLEvent[capacity];
*/
public void reset() {
for (int i = 0; i < index; i++) {
+ jevents[i].release();
jevents[i] = null;
}
index = 0;
}
+ public void release() {
+ reset();
+ }
+
/**
* Creates an interface to the given event.
*
return index;
}
- static MemoryAddress toWaitList(Allocator frame, CLEventList list) {
- if (list != null) {
- MemoryAddress addr = frame.alloca(list.index * 8);
-
- for (int i=0;i<list.index;i++)
- Native.setAddr(addr, i, list.jevents[i].addr());
-
- return addr;
- } else {
- return MemoryAddress.NULL;
- }
- }
-
/**
* Calls clWaitForEvents with all active events in this list.
*
public void waitForEvents() throws CLException {
if (size() > 0) {
try (Allocator frame = Memory.stack()) {
- MemoryAddress events = toWaitList(frame, this);
+ MemoryAddress events = Native.toAddrV(frame, jevents, index);
int res;
res = clWaitForEvents(size(), events);
}
public void requireAPIVersion(int version) throws UnsupportedOperationException {
- if (apiVersion < version)
- throw new UnsupportedOperationException("Requires version " + ((apiVersion >> 8) & 0xff) + "." + (apiVersion & 0xff));
+ CLPlatform.requireAPIVersion(apiVersion, version);
}
public boolean haveAPIVersion(int version) {
import static au.notzed.zcl.CL.*;
import static au.notzed.zcl.CLLib.*;
import jdk.incubator.foreign.*;
-import api.Native;
-
-//import static au.au.notzed.zcl.CL.*;
import java.nio.ByteBuffer;
import java.lang.invoke.MethodHandle;
*/
public class CLImage<T> extends CLMemory {
- /**
- * Create an interface for a native pointer of type cl_mem that refers to an
- * image object.
- *
- * @param p Native pointer.
- * @param seg A segment backing the image on the host.
- */
public CLImage(MemoryAddress p) {
this(p, null);
}
import api.Native;
import api.Allocator;
import api.Memory;
-
-import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.lang.invoke.MethodHandle;
*/
public class CLKernel extends CLObject {
- /**
- * Create an interface for a native pointer of type cl_kernel.
- *
- * @param p Native pointer.
- */
+ int apiVersion;
+
CLKernel(MemoryAddress p) {
super(p);
+
+ apiVersion = getContext().getAPIVersion();
}
static CLKernel create(MemoryAddress p) {
* @since OpenCL 2.1
*/
public CLKernel cloneKernel() throws CLRuntimeException {
- if (clCloneKernel != null) {
- // ??
+ CLPlatform.requireAPIVersion(apiVersion, CLPlatform.VERSION_2_1);
+
+ try (Allocator a = Memory.stack()) {
+ MemoryAddress cres = a.alloca(8);
+ MemoryAddress ck = clCloneKernel(addr(), cres);
+ int res = getInt(cres);
+
+ if (res != 0)
+ throw new CLRuntimeException(res);
+
+ return Native.resolve(ck, CLKernel::new);
+ } catch (CLRuntimeException | Error t) {
+ throw t;
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
}
- throw new UnsupportedOperationException();
}
/**
if (res != 0)
throw new CLRuntimeException(res);
- } catch (CLRuntimeException t) {
- // oh joy
+ } catch (CLRuntimeException | Error t) {
throw t;
} catch (Throwable t) {
throw new RuntimeException(t);
throw new UnsupportedOperationException();
}
- // /**
- // * @since OpenCL 2.1
- // */
- // public long[] getLocalSizeForSubGroupCount(CLDevice device, long count) {
- // return getSubGroupInfoAnyV(device, CTYPE_SIZE_T, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, new long[]{count});
- // }
+ /**
+ * @since OpenCL 2.1
+ */
+ public long[] getLocalSizeForSubGroupCount(CLDevice device, long count) {
+ //return getSubGroupInfoAnyV(device, CTYPE_SIZE_T, CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT, new long[]{count});
+ throw new UnsupportedOperationException();
+ }
public long getMaxNumSubGroups(CLDevice device) {
throw new UnsupportedOperationException();
import java.lang.invoke.MethodHandle;
import java.nio.ByteBuffer;
-//import static au.au.notzed.zcl.CL.*;
import java.nio.ByteOrder;
-import jdk.incubator.foreign.*;
/**
* Interface for cl_mem.
- * <p>
- * <h1>Memory Transfers</h1>
+ * <h2>Memory Transfers</h2>
* <p>
* Subclasses of CLMemory define various read, write, and map operations. These
* are performed via ByteBuffer objects or primitive arrays.
import api.Native;
import api.Allocator;
import api.Memory;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
/**
- * Base class for all OpenCL types which can be represented as objects - i.e.
- * those that are defined by anonymous pointer types in cl.h.
+ * Base class for all OpenCL types which can be represented as objects.
+ * That is, those that are defined by anonymous pointer types in cl.h.
* <p>
- * Each object has a single memory pointer which is stored in the p field. A
- * long is used for all platforms for code simplicity. For most objects this is
- * the only value retained and all get methods defer to the OpenCL runtime.
- * CLObjects are not guaranteed to map unique instances to a given OpenCL object
- * although in many cases the API doesn't allow for any other behaviour. Objects
- * are considered equal if their p value is identical.
+ * Each object has a single memory pointer which is stored in the p field.
+ * For most objects this is the only value retained and all get methods defer
+ * to the OpenCL runtime. OpenCL objects with the same pointer are guarnateed
+ * to map to the same Java instance. Objects are considered equal if their p
+ * value is identical.
* <p>
* To reduce the code-size, retain(), release(), getInfo() and object-specific
- * getInfo() variants have been implemented in a polymorphic fashion. The TYPE_*
- * fields and getType() method are used to implement this mechanism. get()
- * methods which return CLObjects will normally return a new instance for each
- * call although each instance will point to the same underlying native
- * resource.
+ * getInfo() variants have been implemented in a polymorphic fashion. For
+ * getInfo(), the getInfoFunc() returns the method handle of the native
+ * function used to retrieve the information.
* <p>
- * Memory management is explicit and objects must be released when no longer
- * needed.
+ * Memory management is automatic but can also be explicit at application
+ * discretion. Use the release() methods for explicit deallocation.
*/
public abstract class CLObject extends Native {
super(p);
}
- // These are not really public - for access by extensions
- public static final int CTYPE_PLATFORM = 0;
- public static final int CTYPE_DEVICE = 1;
- public static final int CTYPE_CONTEXT = 2;
- public static final int CTYPE_COMMAND_QUEUE = 3;
- public static final int CTYPE_PIPE = 4;
- public static final int CTYPE_BUFFER = 5;
- public static final int CTYPE_IMAGE = 6;
- public static final int CTYPE_SAMPLER = 7;
- public static final int CTYPE_PROGRAM = 8;
- public static final int CTYPE_KERNEL = 9;
- public static final int CTYPE_EVENT = 10;
- public static final int CTYPE_SIZEOF = 11; // just a count
-
- /*
- These type codes are used for getInfoX() queries.
- Various values in zcl-jni.c must be synchronised with this manually.
- */
- public static final int CTYPE_SIZE_T = 16;
- public static final int CTYPE_BYTE = 17;
- public static final int CTYPE_SHORT = 18;
- public static final int CTYPE_INT = 19;
- public static final int CTYPE_LONG = 20;
- public static final int CTYPE_FLOAT = 21;
- public static final int CTYPE_DOUBLE = 22;
- // Range of primitives
- protected static final int CTYPE_PRIMITIVE = 16;
- protected static final int CTYPE_PRIMITIVE_SIZEOF = 23 - 16;
- //protected static final int CTYPE_ARRAY = 128;
-
-
- /* Info types */
- final static int TYPE_PLATFORM = 0;
- final static int TYPE_DEVICE = 1;
- final static int TYPE_CONTEXT = 2;
- final static int TYPE_COMMAND_QUEUE = 3;
- final static int TYPE_MEM_OBJECT = 4;
- final static int TYPE_IMAGE = 5;
- final static int TYPE_PIPE = 6;
- final static int TYPE_SAMPLER = 7;
- final static int TYPE_PROGRAM = 8;
- final static int TYPE_PROGRAM_BUILD = 9;
- final static int TYPE_KERNEL = 10;
- final static int TYPE_KERNEL_ARG = 11;
- final static int TYPE_KERNEL_WORK_GROUP = 12;
- final static int TYPE_EVENT = 13;
- final static int TYPE_EVENT_PROFILING = 14;
- final static int TYPE_KERNEL_SUB_GROUP = 15;
-
// new 5-param version
// this one is static so it can be accessed at creation time
protected static MemoryAddress getInfo(MemoryAddress self, int id, MethodHandle getInfo, Allocator frame, long size) throws CLRuntimeException {
}
}
-
protected int getInfoInt(int id, MethodHandle getInfo) {
try (Allocator a = Memory.stack()) {
return getInt(getInfo(addr(), id, getInfo, a, 4));
}
}
-
- // check the rest
-
-
// indexed version
protected MemoryAddress getInfo(int index, int id, MethodHandle getInfo, Allocator a, long size) throws CLRuntimeException {
try {
}
}
-
protected String getInfoString(int index, int id, MethodHandle getInfo) {
try (Allocator a = Memory.stack()) {
MemorySegment valp = getInfoAny(index, id, getInfo, a);
*/
public class CLPipe<T> extends CLMemory {
- /**
- * Create an interface for a native pointer of type cl_mem that refers to a
- * pipe object.
- *
- * @param p Native pointer.
- */
public CLPipe(MemoryAddress p) {
this(p, null);
}
import static au.notzed.zcl.CL.*;
import static au.notzed.zcl.CLLib.*;
-//import au.notzed.zcl.khr.GLSharing;
import java.util.function.ToDoubleFunction;
import jdk.incubator.foreign.*;
import api.Native;
import api.Memory;
import api.Allocator;
-
-// hack test
import java.lang.invoke.*;
-import jdk.incubator.foreign.unsafe.ForeignUnsafe;
/**
* Interface for cl_platform_id
final int apiVersion;
- /**
- * Create an interface for a native pointer of type cl_platform_id.
- *
- * @param p Native pointer.
- */
public CLPlatform(MemoryAddress p) {
super(p);
return clGetPlatformInfo;
}
+ public static void requireAPIVersion(int apiVersion, int required) throws UnsupportedOperationException {
+ if (apiVersion < required)
+ throw new UnsupportedOperationException("Requires version " + ((apiVersion >> 8) & 0xff) + "." + (apiVersion & 0xff));
+ }
+
/**
* Calls clGetPlatformIDs.
*
int res;
res = (int)clGetPlatformIDs.invokeExact(0, MemoryAddress.NULL, lenp);
-
+ if (res != 0)
+ throw new CLRuntimeException(res);
+
len = Native.getInt(lenp);
list = frame.alloca(8 * len);
res = (int)clGetPlatformIDs.invokeExact(len, list, lenp);
return toObjectV(list, new CLPlatform[len], CLPlatform::new);
+ } catch (RuntimeException | Error t) {
+ throw t;
} catch (Throwable t) {
throw new RuntimeException(t);
}
res = (int)clGetDeviceIDs.invokeExact(addr(), type, len, list, lenp);
return toObjectV(list, new CLDevice[len], CLDevice::new);
+ } catch (RuntimeException | Error t) {
+ throw t;
} catch (Throwable t) {
throw new RuntimeException();
}
*
* @throws CLRuntimeException
*/
- //public native void unloadPlatformCompiler() throws CLRuntimeException;
+ public void unloadPlatformCompiler() throws CLRuntimeException {
+ try {
+ int res = clUnloadCompiler();
+ if (res != 0)
+ throw new CLRuntimeException(res);
+ } catch (RuntimeException | Error t) {
+ throw t;
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
+ }
+ /**
+ * Get the platform api versiom.
+ *
+ * This may be compared to the version constants
+ * {@link #VERSION_1_0}, {@link #VERSION_1_1}, and so on.
+ *
+ * @return platform api version.
+ */
+ public int getAPIVersion() {
+ return apiVersion;
+ }
+
/**
* get CL_PLATFORM_PROFILE.
*
*/
public class CLProgram extends CLObject {
- /**
- * Create an interface for a native pointer of type cl_program.
- *
- * @param p Native pointer.
- */
CLProgram(MemoryAddress p) {
super(p);
}
*
* @param dst destination
* @param o offset
- * @return updated o (o + getSize())
+ * @return updated o = (o + getSize())
*/
- int toInt(int dst[], int o);
+ int toInt(MemoryAddress dst, int o);
/**
- * Encode this property as a long array.
+ * Encode this property as a long poke.
*
* @param dst destination
* @param o offset
- * @return updated o (o + getSize())
+ * @return updated o = (o + getSize()))
*/
- int toLong(long dst[], int o);
-
- int toLong(MemoryAddress addr, int i);
+ int toLong(MemoryAddress dst, int o);
/**
* A simple tag/value property type.
}
@Override
- public int toInt(int[] dst, int o) {
- dst[o++] = (int) tag;
- dst[o++] = (int) value;
+ public int toInt(MemoryAddress dst, int o) {
+ Native.setInt(dst, o++, (int)tag);
+ Native.setInt(dst, o++, (int)value);
return o;
}
@Override
- public int toLong(long[] dst, int o) {
- dst[o++] = tag;
- dst[o++] = value;
- return o;
- }
-
public int toLong(MemoryAddress dst, int o) {
Native.setLong(dst, o++, tag);
Native.setLong(dst, o++, value);
return size + 1;
}
- /**
- * Convert to 32-bit intptr_t array. A terminating 0 is included.
- *
- * @param props
- * @return
- */
- /*
- public static int[] toInt(Object[] props) {
- int[] dst = new int[getSize(props)];
- int o = 0;
-
- //System.out.printf("CLProperty toInt(props=%d) size=%d\n", props.length, dst.length);
-
- for (Object p : props) {
- o = ((CLProperty) p).toInt(dst, o);
- }
- dst[o] = 0;
-
- return dst;
- }
- */
- /**
- * Convert to 64-bit intptr_t array. A terminating 0L is included.
- *
- * @param props
- * @return
- */
- /*
- public static long[] toLong(Object[] props) {
- long[] dst = new long[getSize(props)];
- int o = 0;
-
- //System.out.printf("CLProperty toLong(props=%d) size=%d\n", props.length, dst.length);
-
- for (Object p : props) {
- o = ((CLProperty) p).toLong(dst, o);
- }
- dst[o] = 0;
-
- return dst;
- }
- */
- /*
- public static <T extends CLProperty> Pointer<Long> toLong(T[] properties) {
- if (properties != null && properties.length > 0) {
- Pointer<Long> props = Pointer.alloc(getSize(properties), 8, Long.class);
- int o = 0;
-
- for (CLProperty p : properties)
- o = p.toLong(props, o);
- props.set(o, 0L);
-
- return props;
- } else {
- return Pointer.NULL;
- }
- }*/
-
- public static <T extends CLProperty> MemoryAddress toNative(Allocator frame, T[] properties) {
+ static <T extends CLProperty> MemoryAddress toNative(Allocator frame, T[] properties) {
if (properties != null && properties.length > 0) {
MemoryAddress addr = frame.alloca(getSize(properties) * 8);
int i = 0;
}
}
- public static <T extends CLProperty> T[] fromNative(MemorySegment seg, BiFunction<Long,Long,T> create, IntFunction<T[]> createArray) {
+ static <T extends CLProperty> T[] fromNative(MemorySegment seg, BiFunction<Long,Long,T> create, IntFunction<T[]> createArray) {
MemoryAddress add = seg.baseAddress();
ArrayList<T> list = new ArrayList<>();
long tag;
import static au.notzed.zcl.CL.*;
import static au.notzed.zcl.CLLib.*;
import jdk.incubator.foreign.*;
-import api.Native;
import java.lang.invoke.MethodHandle;
/**
*/
public class CLSampler extends CLObject {
- /**
- * Create an interface for a native pointer of type cl_sampler.
- *
- * @param p Native pointer.
- */
public CLSampler(MemoryAddress p) {
super(p);
}
return new CLSamplerProperty.TagValue(CL_SAMPLER_FILTER_MODE, mode);
}
-
public CLContext getContext() {
return getInfoAny(CL_SAMPLER_CONTEXT, clGetSamplerInfo, CLContext::new);
}
import au.notzed.zcl.CLCommandQueue;
import au.notzed.zcl.CLContext;
import au.notzed.zcl.CLContextProperty;
-import au.notzed.zcl.CLDevice;
import au.notzed.zcl.CLEventList;
import au.notzed.zcl.CLExtension;
import au.notzed.zcl.CLImage;
import au.notzed.zcl.CLMemory;
-import au.notzed.zcl.CLObject;
import au.notzed.zcl.CLRuntimeException;
import jdk.incubator.foreign.MemoryAddress;
int ctype,
int param_name) throws CLRuntimeException;
+ /*
public CLDevice getCurrendDeviceForGLConextKHR(CLContextProperty[] properties) throws CLRuntimeException {
return getGLContextInfoKHRAny(properties, CLObject.CTYPE_DEVICE, CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR);
}
public CLDevice[] getDevicesForGLConextKHR(CLContextProperty[] properties) throws CLRuntimeException {
return getGLContextInfoKHRAnyV(properties, CLObject.CTYPE_DEVICE, CL_DEVICES_FOR_GL_CONTEXT_KHR);
- }
+ }*/
}
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
/**
- * Provides a Java binding for OpenCL 2.0 and earlier.
+ * Provides a Java binding for OpenCL 2.1 and earlier.
*/
package au.notzed.zcl;
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
+/**
+ * Implements a java-friendly binding to OpenCL.
+ */
module notzed.zcl {
requires jdk.incubator.foreign;
notzed.zcl_JAVA_GENERATED = \
$(notzed.zcl_generated)
-$(info $(notzed.zcl_genjavadir))
-$(info $(addprefix $(notzed.zcl_genjavadir),$(notzed.zcl_generated)): $(generate_api) $(opencl_pm))
-
$(notzed.zcl_genjavadir)/au/notzed/zcl/CL.java: src/notzed.zcl/include/CL/cl.h $(export_defines)
@install -d $(@D)
perl $(export_defines) $< > $@ || rm -f $@
END
}
- print $dst "public class $class{name} {\n";
+ print $dst "class $class{name} {\n";
print $dst "\tstatic final String[] libraries = {";
print $dst join(",", map { "\"$_\"" } @libs);
}
print $dst "\@FunctionalInterface\n";
- print $dst "public interface $name {\n";
+ print $dst "interface $name {\n";
print $dst "\tpublic $result fn(";
for $pi (@params) {