/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateContext.html">clCreateContext</a>.<br> * Creates an OpenCL context formed of the provided devices.<br> * It is generally not a good idea to create a context with more than one device, * because much data is shared between all the devices in the same context. * @param devices devices that are to form the new context * @return new OpenCL context */ public CLContext createContext(Map<ContextProperties, Object> contextProperties, CLDevice... devices) { int nDevs = devices.length; if (nDevs == 0) { throw new IllegalArgumentException("Cannot create a context with no associated device !"); } Pointer<SizeT> ids = allocateSizeTs(nDevs); for (int i = 0; i < nDevs; i++) { ids.setSizeTAtIndex(i, devices[i].getEntity()); } ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pErr = ptrs.pErr; long[] props = getContextProps(contextProperties); Pointer<SizeT> propsRef = props == null ? null : pointerToSizeTs(props); //System.out.println("ERROR CALLBACK " + Long.toHexString(errCb.getPeer())); long context = CL.clCreateContext(getPeer(propsRef), nDevs, getPeer(ids), 0, 0, getPeer(pErr)); error(pErr.getInt()); ; return new CLContext(this, ids, context); }
/** * Calls <a href="http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clCreateContext.html">clCreateContext</a>.<br> * Creates an OpenCL context formed of the provided devices.<br> * It is generally not a good idea to create a context with more than one device, * because much data is shared between all the devices in the same context. * @param devices devices that are to form the new context * @return new OpenCL context */ public CLContext createContext(Map<ContextProperties, Object> contextProperties, CLDevice... devices) { int nDevs = devices.length; if (nDevs == 0) { throw new IllegalArgumentException("Cannot create a context with no associated device !"); } Pointer<SizeT> ids = allocateSizeTs(nDevs); for (int i = 0; i < nDevs; i++) { ids.setSizeTAtIndex(i, devices[i].getEntity()); } ReusablePointers ptrs = ReusablePointers.get(); Pointer<Integer> pErr = ptrs.pErr; long[] props = getContextProps(contextProperties); Pointer<SizeT> propsRef = props == null ? null : pointerToSizeTs(props); //System.out.println("ERROR CALLBACK " + Long.toHexString(errCb.getPeer())); long context = CL.clCreateContext(getPeer(propsRef), nDevs, getPeer(ids), 0, 0, getPeer(pErr)); error(pErr.getInt()); ; return new CLContext(this, ids, context); }
@Deprecated public CLDevice guessCurrentGLDevice() { long[] props = platform.getContextProps(CLPlatform.getGLContextProperties(getPlatform())); Pointer<SizeT> propsRef = pointerToSizeTs(props); Pointer<SizeT> pCount = allocateSizeT(); Pointer<Pointer<?>> mem = allocatePointer(); if (Platform.isMacOSX()) error(CL.clGetGLContextInfoAPPLE( getEntity(), getPeer(OpenGLContextUtils.CGLGetCurrentContext()), CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, Pointer.SIZE, getPeer(mem), getPeer(pCount))); else error(CL.clGetGLContextInfoKHR( getPeer(propsRef), CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, Pointer.SIZE, getPeer(mem), getPeer(pCount) )); if (pCount.getSizeT() != Pointer.SIZE) throw new RuntimeException("Not a device : len = " + pCount.get().intValue()); Pointer p = mem.getPointer(); if (p.equals(Pointer.NULL)) return null; return new CLDevice(null, getPeer(p)); }
@Deprecated public CLDevice guessCurrentGLDevice() { long[] props = platform.getContextProps(CLPlatform.getGLContextProperties(getPlatform())); Pointer<SizeT> propsRef = pointerToSizeTs(props); Pointer<SizeT> pCount = allocateSizeT(); Pointer<Pointer<?>> mem = allocatePointer(); if (Platform.isMacOSX()) error(CL.clGetGLContextInfoAPPLE( getEntity(), getPeer(OpenGLContextUtils.CGLGetCurrentContext()), CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, Pointer.SIZE, getPeer(mem), getPeer(pCount))); else error(CL.clGetGLContextInfoKHR( getPeer(propsRef), CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR, Pointer.SIZE, getPeer(mem), getPeer(pCount) )); if (pCount.getSizeT() != Pointer.SIZE) throw new RuntimeException("Not a device : len = " + pCount.get().intValue()); Pointer p = mem.getPointer(); if (p.equals(Pointer.NULL)) return null; return new CLDevice(null, getPeer(p)); }