diff options
author | Michael Bien <[email protected]> | 2009-10-23 00:21:58 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-10-23 00:21:58 +0200 |
commit | 054e5005d1429ba6ea4f9283eee2988ff54d1abb (patch) | |
tree | 163f7124f6dba109de965f3382f8b2613cf2068c /src/com/mbien/opencl/CLBuffer.java | |
parent | 503845224a820c0b9ce9204aa6215519f6b93c36 (diff) |
utility methods and refactoring.
Diffstat (limited to 'src/com/mbien/opencl/CLBuffer.java')
-rw-r--r-- | src/com/mbien/opencl/CLBuffer.java | 127 |
1 files changed, 63 insertions, 64 deletions
diff --git a/src/com/mbien/opencl/CLBuffer.java b/src/com/mbien/opencl/CLBuffer.java index 185389c3..7c195ba7 100644 --- a/src/com/mbien/opencl/CLBuffer.java +++ b/src/com/mbien/opencl/CLBuffer.java @@ -9,7 +9,65 @@ import static com.mbien.opencl.CLException.*; */ public class CLBuffer { - public enum MEM { + public final ByteBuffer buffer; + public final long ID; + + private final CLContext context; + private final CL cl; + + CLBuffer(CLContext context, ByteBuffer directBuffer, int flags) { + + if(!directBuffer.isDirect()) + throw new IllegalArgumentException("buffer is not a direct buffer"); + + this.buffer = directBuffer; + this.context = context; + this.cl = context.cl; + + int[] intArray = new int[1]; + + this.ID = cl.clCreateBuffer(context.ID, flags, directBuffer.capacity(), null, intArray, 0); + + checkForError(intArray[0], "can not create cl buffer"); + + } + + public void release() { + int ret = cl.clReleaseMemObject(ID); + context.onBufferReleased(this); + checkForError(ret, "can not release mem object"); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final CLBuffer other = (CLBuffer) obj; + if (this.buffer != other.buffer && (this.buffer == null || !this.buffer.equals(other.buffer))) { + return false; + } + if (this.context.ID != other.context.ID) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 29 * hash + (this.buffer != null ? this.buffer.hashCode() : 0); + hash = 29 * hash + (int) (this.context.ID ^ (this.context.ID >>> 32)); + return hash; + } + + /** + * Memory settings for configuring CLBuffers. + */ + public enum Mem { /** * This flag specifies that the memory object will be read and @@ -56,11 +114,11 @@ public class CLBuffer { */ public final int CL_FLAG; - private MEM(int CL_TYPE) { - this.CL_FLAG = CL_TYPE; + private Mem(int CL_FLAG) { + this.CL_FLAG = CL_FLAG; } - public static MEM valueOf(int bufferFlag) { + public static Mem valueOf(int bufferFlag) { switch(bufferFlag) { case(CL.CL_MEM_READ_WRITE): return READ_WRITE; @@ -76,7 +134,7 @@ public class CLBuffer { return null; } - static int flagsToInt(MEM[] flags) { + static int flagsToInt(Mem[] flags) { int clFlags = 0; if(flags != null) { for (int i = 0; i < flags.length; i++) { @@ -90,63 +148,4 @@ public class CLBuffer { } - - public final ByteBuffer buffer; - public final long ID; - - private final CLContext context; - private final CL cl; - - CLBuffer(CLContext context, ByteBuffer directBuffer, int flags) { - - if(!directBuffer.isDirect()) - throw new IllegalArgumentException("buffer is not a direct buffer"); - - this.buffer = directBuffer; - this.context = context; - this.cl = context.cl; - - int[] intArray = new int[1]; - - this.ID = cl.clCreateBuffer(context.ID, flags, directBuffer.capacity(), null, intArray, 0); - - checkForError(intArray[0], "can not create cl buffer"); - - } - - public void release() { - int ret = cl.clReleaseMemObject(ID); - context.onBufferReleased(this); - checkForError(ret, "can not release mem object"); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final CLBuffer other = (CLBuffer) obj; - if (this.buffer != other.buffer && (this.buffer == null || !this.buffer.equals(other.buffer))) { - return false; - } - if (this.context.ID != other.context.ID) { - return false; - } - return true; - } - - @Override - public int hashCode() { - int hash = 3; - hash = 29 * hash + (this.buffer != null ? this.buffer.hashCode() : 0); - hash = 29 * hash + (int) (this.context.ID ^ (this.context.ID >>> 32)); - return hash; - } - - - - } |