Top Description Inners Fields Constructors Methods
com.jogamp.opencl

public Class CLContext

extends CLObjectResource
Class Inheritance
Known Direct Subclasses
com.jogamp.opencl.gl.CLGLContext
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, java.nio.Buffer, .ByteBuffer, .DoubleBuffer, .FloatBuffer, .IntBuffer, .LongBuffer, .ShortBuffer, java.util.ArrayList, .Collection, .Collections, .HashMap, .HashSet, .List, .Map, .Set, com.jogamp.common.nio.Buffers, .PointerBuffer, com.jogamp.common.os.Platform, com.jogamp.opencl.CLDevice.Type, .CLMemory.Mem, .CLSampler.AddressingMode, .CLSampler.FilteringMode, com.jogamp.opencl.llb.CL, .CLContextBinding, .CLMemObjBinding, com.jogamp.opencl.llb.impl.CLImageFormatImpl

CLContext is responsible for managing objects such as command-queues, memory, program and kernel objects and for executing kernels on one or more devices specified in the context.

Must be released if no longer used to free native resources. release() will also free all associated CLResource like programs, samplers, command queues and memory objects.

For a code example see CLPlatform.

concurrency:
CLContext is threadsafe.

Author
Michael Bien, et al.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
protected CLDevice[]
private final CLContext.ErrorDispatcher
protected final Set<CLMemory<? extends Buffer>>
protected final CLPlatform
protected final Set<CLProgram>
protected final Map<CLDevice, List<CLCommandQueue>>
protected final Set<CLSampler>

Constructor Summary

AccessConstructor and Description
protected
CLContext(final CLPlatform platform, final long contextID, final CLContext.ErrorDispatcher dispatcher)

Method Summary

Modifier and TypeMethod and Description
public void
public static CLContext
create()

Creates a context on all available devices (CL_DEVICE_TYPE_ALL).

public static CLContext
create(final CLDevice.Type... deviceTypes)

Creates a context on the specified device types.

public static CLContext
create(final CLPlatform platform)

Creates a context on the specified platform on all available devices (CL_DEVICE_TYPE_ALL).

public static CLContext
create(CLPlatform platform, final CLDevice.Type... deviceTypes)

Creates a context on the specified platform and with the specified device types.

public static CLContext
create(final CLDevice... devices)

Creates a context on the specified devices.

public final CLBuffer<?>
createBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags.

public final CLBuffer<?>
createBuffer(final int size, final int flags)

Creates a CLBuffer with the specified flags.

public final <B extends Buffer> CLBuffer<B>
createBuffer(final B directBuffer, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags.

public final <B extends Buffer> CLBuffer<B>
createBuffer(final B directBuffer, final int flags)

Creates a CLBuffer with the specified flags.

public final CLBuffer<ByteBuffer>
createByteBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and buffer size in bytes.

public final CLBuffer<ByteBuffer>
createByteBuffer(final int size, final int flags)

Creates a CLBuffer with the specified flags and buffer size in bytes.

pack-priv CLCommandQueue
createCommandQueue(final CLDevice device, final long properties)

protected static long
createContext(final CLPlatform platform, final CLErrorHandler handler, final PointerBuffer properties, final CLDevice... devices)

protected static long
createContextFromType(final CLPlatform platform, final CLErrorHandler handler, final PointerBuffer properties, final long deviceType)

public final CLBuffer<DoubleBuffer>
createDoubleBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count.

protected static CLContext.ErrorDispatcher
public final CLBuffer<FloatBuffer>
createFloatBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count.

public final CLImage2d<?>
createImage2d(final int width, final int height, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

public final CLImage2d<?>
createImage2d(final int width, final int height, final int rowPitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

public final <B extends Buffer> CLImage2d<B>
createImage2d(final B directBuffer, final int width, final int height, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

public final <B extends Buffer> CLImage2d<B>
createImage2d(final B directBuffer, final int width, final int height, final int rowPitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

public final CLImage3d<?>
createImage3d(final int width, final int height, final int depth, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

public final CLImage3d<?>
createImage3d(final int width, final int height, final int depth, final int rowPitch, final int slicePitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

public final <B extends Buffer> CLImage3d<B>
createImage3d(final B directBuffer, final int width, final int height, final int depth, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

public final <B extends Buffer> CLImage3d<B>
createImage3d(final B directBuffer, final int width, final int height, final int depth, final int rowPitch, final int slicePitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

public final CLBuffer<IntBuffer>
createIntBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count.

public final CLBuffer<LongBuffer>
createLongBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count.

public CLProgram
createProgram(final String src)

Creates a program from the given sources, the returned program is not build yet.

public CLProgram
createProgram(final InputStream source)

Creates a program and reads the source from stream, the returned program is not build yet.

public CLProgram
createProgram(final Map<CLDevice, byte[]> binaries)

Creates a program from the given binaries, the program is not build yet.

public CLSampler
createSampler(final CLSampler.AddressingMode addrMode, final CLSampler.FilteringMode filtMode, final boolean normalizedCoords)

public final CLBuffer<ShortBuffer>
createShortBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count.

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public CL
getCL()

Return the low level OpenCL interface.

public CLContext
getContext()

Overrides com.jogamp.opencl.CLObject.getContext.

Returns the context for this OpenCL object.
pack-priv CLDevice
getDevice(final long dID)

public CLDevice[]
getDevices()

Returns all devices associated with this CLContext.

public CLDevice
getMaxFlopsDevice()

Returns the device with maximal FLOPS from this context.

public CLDevice
getMaxFlopsDevice(final CLDevice.Type type)

Returns the device with maximal FLOPS of the specified device type from this context.

public long
getMaxMemBaseAddrAlign()

Returns the maximum CLDevice#getMemBaseAddrAlign() of all devices.

public List<CLMemory<? extends Buffer>>
getMemoryObjects()

Returns a read only shapshot of all allocated memory objects associated with this context.

public CLPlatform
getPlatform()

Overrides com.jogamp.opencl.CLObject.getPlatform.

Returns the CLPlatform this context is running on.
public List<CLProgram>
getPrograms()

Returns a read only shapshot of all programs associated with this context.

public List<CLSampler>
getSamplers()

Returns a read only shapshot of all samplers associated with this context.

public CLImageFormat[]
getSupportedImage2dFormats(final CLMemory.Mem... flags)

Returns all supported 2d image formats with the (optional) memory allocation flags.

public CLImageFormat[]
getSupportedImage3dFormats(final CLMemory.Mem... flags)

Returns all supported 3d image formats with the (optional) memory allocation flags.

private CLImageFormat[]
getSupportedImageFormats(final int flags, final int type)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
private synchronized void
pack-priv void
onCommandQueueReleased(final CLDevice device, final CLCommandQueue queue)

pack-priv void
onMemoryReleased(final CLMemory<?> buffer)

pack-priv void
pack-priv void
protected void
overrideContext(final CLDevice device)

private void
release(final Collection<? extends CLResource> resources)

public synchronized void
release()

Overrides com.jogamp.opencl.CLObjectResource.release.

Implements com.jogamp.opencl.CLResource.release.

Releases this context and all resources.
public void
private static PointerBuffer
protected static long
toDeviceBitmap(final CLDevice.Type[] deviceTypes)

public String
toString()

Overrides com.jogamp.opencl.CLObject.toString.

Returns a string representation of the object.
Inherited from com.jogamp.opencl.CLObjectResource:
closeisReleased

Field Detail

devicesback to summary
protected CLDevice[] devices
errorHandlerback to summary
private final CLContext.ErrorDispatcher errorHandler
memoryObjectsback to summary
protected final Set<CLMemory<? extends Buffer>> memoryObjects
platformback to summary
protected final CLPlatform platform
programsback to summary
protected final Set<CLProgram> programs
queuesMapback to summary
protected final Map<CLDevice, List<CLCommandQueue>> queuesMap
samplersback to summary
protected final Set<CLSampler> samplers

Constructor Detail

CLContextback to summary
protected CLContext(final CLPlatform platform, final long contextID, final CLContext.ErrorDispatcher dispatcher)

Method Detail

addCLErrorHandlerback to summary
public void addCLErrorHandler(final CLErrorHandler handler)
createback to summary
public static CLContext create()

Creates a context on all available devices (CL_DEVICE_TYPE_ALL). The platform to be used is implementation dependent.

createback to summary
public static CLContext create(final CLDevice.Type... deviceTypes)

Creates a context on the specified device types. The platform to be used is implementation dependent.

createback to summary
public static CLContext create(final CLPlatform platform)

Creates a context on the specified platform on all available devices (CL_DEVICE_TYPE_ALL).

createback to summary
public static CLContext create(CLPlatform platform, final CLDevice.Type... deviceTypes)

Creates a context on the specified platform and with the specified device types.

createback to summary
public static CLContext create(final CLDevice... devices)

Creates a context on the specified devices.

createBufferback to summary
public final CLBuffer<?> createBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer.

createBufferback to summary
public final CLBuffer<?> createBuffer(final int size, final int flags)

Creates a CLBuffer with the specified flags.

createBufferback to summary
public final <B extends Buffer> CLBuffer<B> createBuffer(final B directBuffer, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer.

createBufferback to summary
public final <B extends Buffer> CLBuffer<B> createBuffer(final B directBuffer, final int flags)

Creates a CLBuffer with the specified flags.

createByteBufferback to summary
public final CLBuffer<ByteBuffer> createByteBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and buffer size in bytes. No flags creates a MEM.READ_WRITE buffer.

createByteBufferback to summary
public final CLBuffer<ByteBuffer> createByteBuffer(final int size, final int flags)

Creates a CLBuffer with the specified flags and buffer size in bytes.

createCommandQueueback to summary
pack-priv CLCommandQueue createCommandQueue(final CLDevice device, final long properties)
createContextback to summary
protected static long createContext(final CLPlatform platform, final CLErrorHandler handler, final PointerBuffer properties, final CLDevice... devices)
createContextFromTypeback to summary
protected static long createContextFromType(final CLPlatform platform, final CLErrorHandler handler, final PointerBuffer properties, final long deviceType)
createDoubleBufferback to summary
public final CLBuffer<DoubleBuffer> createDoubleBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.

createErrorHandlerback to summary
protected static CLContext.ErrorDispatcher createErrorHandler()
createFloatBufferback to summary
public final CLBuffer<FloatBuffer> createFloatBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.

createImage2dback to summary
public final CLImage2d<?> createImage2d(final int width, final int height, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

createImage2dback to summary
public final CLImage2d<?> createImage2d(final int width, final int height, final int rowPitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

createImage2dback to summary
public final <B extends Buffer> CLImage2d<B> createImage2d(final B directBuffer, final int width, final int height, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

createImage2dback to summary
public final <B extends Buffer> CLImage2d<B> createImage2d(final B directBuffer, final int width, final int height, final int rowPitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage2d with the specified format, dimension and flags.

createImage3dback to summary
public final CLImage3d<?> createImage3d(final int width, final int height, final int depth, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

createImage3dback to summary
public final CLImage3d<?> createImage3d(final int width, final int height, final int depth, final int rowPitch, final int slicePitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

createImage3dback to summary
public final <B extends Buffer> CLImage3d<B> createImage3d(final B directBuffer, final int width, final int height, final int depth, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

createImage3dback to summary
public final <B extends Buffer> CLImage3d<B> createImage3d(final B directBuffer, final int width, final int height, final int depth, final int rowPitch, final int slicePitch, final CLImageFormat format, final CLMemory.Mem... flags)

Creates a CLImage3d with the specified format, dimension and flags.

createIntBufferback to summary
public final CLBuffer<IntBuffer> createIntBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.

createLongBufferback to summary
public final CLBuffer<LongBuffer> createLongBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.

createProgramback to summary
public CLProgram createProgram(final String src)

Creates a program from the given sources, the returned program is not build yet.

createProgramback to summary
public CLProgram createProgram(final InputStream source) throws IOException

Creates a program and reads the source from stream, the returned program is not build yet. The InputStream is automatically closed after the sources have been read.

Exceptions
IOException:
when a IOException occurred while reading or closing the stream.
createProgramback to summary
public CLProgram createProgram(final Map<CLDevice, byte[]> binaries)

Creates a program from the given binaries, the program is not build yet.
Creating a program will fail if:

  • the submitted binaries are invalid or can not be loaded from the OpenCL driver
  • the binaries do not fit to the CLDevices associated with this context
  • binaries are missing for one or more CLDevices
createSamplerback to summary
public CLSampler createSampler(final CLSampler.AddressingMode addrMode, final CLSampler.FilteringMode filtMode, final boolean normalizedCoords)
createShortBufferback to summary
public final CLBuffer<ShortBuffer> createShortBuffer(final int size, final CLMemory.Mem... flags)

Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.

equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getCLback to summary
public CL getCL()

Return the low level OpenCL interface.

getContextback to summary
public CLContext getContext()

Overrides com.jogamp.opencl.CLObject.getContext.

Doc from com.jogamp.opencl.CLObject.getContext.

Returns the context for this OpenCL object.

Annotations
@Override
getDeviceback to summary
pack-priv CLDevice getDevice(final long dID)
getDevicesback to summary
public CLDevice[] getDevices()

Returns all devices associated with this CLContext.

getMaxFlopsDeviceback to summary
public CLDevice getMaxFlopsDevice()

Returns the device with maximal FLOPS from this context. The device speed is estimated by calculating the product of MAX_COMPUTE_UNITS and MAX_CLOCK_FREQUENCY.

See Also
getMaxFlopsDevice(com.jogamp.opencl.CLDevice.Type)
getMaxFlopsDeviceback to summary
public CLDevice getMaxFlopsDevice(final CLDevice.Type type)

Returns the device with maximal FLOPS of the specified device type from this context. The device speed is estimated by calculating the product of MAX_COMPUTE_UNITS and MAX_CLOCK_FREQUENCY.

getMaxMemBaseAddrAlignback to summary
public long getMaxMemBaseAddrAlign()

Returns the maximum CLDevice#getMemBaseAddrAlign() of all devices.

getMemoryObjectsback to summary
public List<CLMemory<? extends Buffer>> getMemoryObjects()

Returns a read only shapshot of all allocated memory objects associated with this context.

getPlatformback to summary
public CLPlatform getPlatform()

Overrides com.jogamp.opencl.CLObject.getPlatform.

Returns the CLPlatform this context is running on.

Annotations
@Override
getProgramsback to summary
public List<CLProgram> getPrograms()

Returns a read only shapshot of all programs associated with this context.

getSamplersback to summary
public List<CLSampler> getSamplers()

Returns a read only shapshot of all samplers associated with this context.

getSupportedImage2dFormatsback to summary
public CLImageFormat[] getSupportedImage2dFormats(final CLMemory.Mem... flags)

Returns all supported 2d image formats with the (optional) memory allocation flags.

getSupportedImage3dFormatsback to summary
public CLImageFormat[] getSupportedImage3dFormats(final CLMemory.Mem... flags)

Returns all supported 3d image formats with the (optional) memory allocation flags.

getSupportedImageFormatsback to summary
private CLImageFormat[] getSupportedImageFormats(final int flags, final int type)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
initDevicesback to summary
private synchronized void initDevices(final CLContextBinding cl)
onCommandQueueReleasedback to summary
pack-priv void onCommandQueueReleased(final CLDevice device, final CLCommandQueue queue)
onMemoryReleasedback to summary
pack-priv void onMemoryReleased(final CLMemory<?> buffer)
onProgramReleasedback to summary
pack-priv void onProgramReleased(final CLProgram program)
onSamplerReleasedback to summary
pack-priv void onSamplerReleased(final CLSampler sampler)
overrideContextback to summary
protected void overrideContext(final CLDevice device)
releaseback to summary
private void release(final Collection<? extends CLResource> resources)
releaseback to summary
public synchronized void release()

Overrides com.jogamp.opencl.CLObjectResource.release.

Implements com.jogamp.opencl.CLResource.release.

Releases this context and all resources.

Annotations
@Override
removeCLErrorHandlerback to summary
public void removeCLErrorHandler(final CLErrorHandler handler)
setupContextPropertiesback to summary
private static PointerBuffer setupContextProperties(final CLPlatform platform)
toDeviceBitmapback to summary
protected static long toDeviceBitmap(final CLDevice.Type[] deviceTypes)
toStringback to summary
public String toString()

Overrides com.jogamp.opencl.CLObject.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
com.jogamp.opencl back to summary

protected Class CLContext.ErrorDispatcher

extends Object
implements CLErrorHandler
Class Inheritance
All Implemented Interfaces
com.jogamp.opencl.CLErrorHandler

Field Summary

Modifier and TypeField and Description
private CLErrorHandler[]

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private synchronized void
addHandler(final CLErrorHandler handler)

public synchronized void
onError(final String errinfo, final ByteBuffer private_info, final long cb)

Implements com.jogamp.opencl.CLErrorHandler.onError.

private synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clientHandlersback to summary
private CLErrorHandler[] clientHandlers

Constructor Detail

ErrorDispatcherback to summary
protected ErrorDispatcher()

Method Detail

addHandlerback to summary
private synchronized void addHandler(final CLErrorHandler handler)
onErrorback to summary
public synchronized void onError(final String errinfo, final ByteBuffer private_info, final long cb)

Implements com.jogamp.opencl.CLErrorHandler.onError.

Annotations
@Override
removeHandlerback to summary
private synchronized void removeHandler(final CLErrorHandler handler)