diff options
author | Michael Bien <[email protected]> | 2009-10-19 19:26:15 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-10-19 19:26:15 +0200 |
commit | cb7fa23952a10795215eda50848530828b92895e (patch) | |
tree | e9e34a7cf55505fe3a381e474ddeb9d224caf545 /src/com/mbien/opencl/CLContext.java | |
parent | 9abfd00399e4ca5c351df9cdf25cd85c960b3d44 (diff) |
initial import of CLBuffer and CLKernel.
added hashCode(), equals() and toString() methods.
updated JUnit test to test new classes.
Diffstat (limited to 'src/com/mbien/opencl/CLContext.java')
-rw-r--r-- | src/com/mbien/opencl/CLContext.java | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/src/com/mbien/opencl/CLContext.java b/src/com/mbien/opencl/CLContext.java index 601a2b79..9cb649d7 100644 --- a/src/com/mbien/opencl/CLContext.java +++ b/src/com/mbien/opencl/CLContext.java @@ -22,6 +22,7 @@ public final class CLContext { private CLDevice[] devices; private final List<CLProgram> programs; + private final List<CLBuffer> buffers; static{ System.loadLibrary("gluegen-rt"); @@ -32,6 +33,7 @@ public final class CLContext { private CLContext(long contextID) { this.contextID = contextID; this.programs = new ArrayList<CLProgram>(); + this.buffers = new ArrayList<CLBuffer>(); } /** @@ -70,14 +72,32 @@ public final class CLContext { return program; } + public CLBuffer createBuffer(int flags, ByteBuffer directBuffer) { + CLBuffer buffer = new CLBuffer(this, flags, directBuffer); + buffers.add(buffer); + return buffer; + } + void programReleased(CLProgram program) { programs.remove(program); } + void bufferReleased(CLBuffer buffer) { + buffers.remove(buffer); + } + /** * Releases the context and all resources. */ public CLContext release() { + + //release all resources + while(!programs.isEmpty()) + programs.get(0).release(); + + while(!buffers.isEmpty()) + buffers.get(0).release(); + int ret = cl.clReleaseContext(contextID); checkForError(ret, "error releasing context"); return this; @@ -86,10 +106,17 @@ public final class CLContext { /** * Returns a read only view of all programs associated with this context. */ - public List<CLProgram> getPrograms() { + public List<CLProgram> getCLPrograms() { return Collections.unmodifiableList(programs); } + /** + * Returns a read only view of all buffers associated with this context. + */ + public List<CLBuffer> getCLBuffers() { + return Collections.unmodifiableList(buffers); + } + /** * Gets the device with maximal FLOPS from this context. @@ -157,7 +184,7 @@ public final class CLContext { return devices; } - CLDevice getCLDevices(long dID) { + CLDevice getCLDevice(long dID) { CLDevice[] deviceArray = getCLDevices(); for (int i = 0; i < deviceArray.length; i++) { if(dID == deviceArray[i].deviceID) @@ -198,4 +225,34 @@ public final class CLContext { } + @Override + public String toString() { + return "CLContext [id: " + contextID + + " #devices: " + getCLDevices().length + + "]"; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final CLContext other = (CLContext) obj; + if (this.contextID != other.contextID) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 23 * hash + (int) (this.contextID ^ (this.contextID >>> 32)); + return hash; + } + + } |