Package com.jogamp.opencl
Class CLContext
- java.lang.Object
-
- com.jogamp.opencl.CLObject
-
- com.jogamp.opencl.CLContext
-
- All Implemented Interfaces:
AutoCloseable
,CLResource
,AutoCloseable
- Direct Known Subclasses:
CLGLContext
public class CLContext extends CLObject
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 associatedCLResource
like programs, samplers, command queues and memory objects.For a code example see
concurrency:CLPlatform
.
CLContext is threadsafe.- Author:
- Michael Bien, et al.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
CLContext.ErrorDispatcher
-
Constructor Summary
Constructors Modifier Constructor Description protected
CLContext(CLPlatform platform, long contextID, CLContext.ErrorDispatcher dispatcher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCLErrorHandler(CLErrorHandler handler)
void
close()
Deprecated.This method is not intended to be called from client code.static CLContext
create()
Creates a context on all available devices (CL_DEVICE_TYPE_ALL).static CLContext
create(CLDevice.Type... deviceTypes)
Creates a context on the specified device types.static CLContext
create(CLDevice... devices)
Creates a context on the specified devices.static CLContext
create(CLPlatform platform)
Creates a context on the specified platform on all available devices (CL_DEVICE_TYPE_ALL).static CLContext
create(CLPlatform platform, CLDevice.Type... deviceTypes)
Creates a context on the specified platform and with the specified device types.CLBuffer<?>
createBuffer(int size, int flags)
Creates a CLBuffer with the specified flags.CLBuffer<?>
createBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags.<B extends Buffer>
CLBuffer<B>createBuffer(B directBuffer, int flags)
Creates a CLBuffer with the specified flags.<B extends Buffer>
CLBuffer<B>createBuffer(B directBuffer, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags.CLBuffer<ByteBuffer>
createByteBuffer(int size, int flags)
Creates a CLBuffer with the specified flags and buffer size in bytes.CLBuffer<ByteBuffer>
createByteBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and buffer size in bytes.protected static long
createContext(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, CLDevice... devices)
protected static long
createContextFromType(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, long deviceType)
CLBuffer<DoubleBuffer>
createDoubleBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count.protected static CLContext.ErrorDispatcher
createErrorHandler()
CLBuffer<FloatBuffer>
createFloatBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count.CLImage2d<?>
createImage2d(int width, int height, int rowPitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.CLImage2d<?>
createImage2d(int width, int height, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.<B extends Buffer>
CLImage2d<B>createImage2d(B directBuffer, int width, int height, int rowPitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.<B extends Buffer>
CLImage2d<B>createImage2d(B directBuffer, int width, int height, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.CLImage3d<?>
createImage3d(int width, int height, int depth, int rowPitch, int slicePitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.CLImage3d<?>
createImage3d(int width, int height, int depth, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.<B extends Buffer>
CLImage3d<B>createImage3d(B directBuffer, int width, int height, int depth, int rowPitch, int slicePitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.<B extends Buffer>
CLImage3d<B>createImage3d(B directBuffer, int width, int height, int depth, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.CLBuffer<IntBuffer>
createIntBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count.CLBuffer<LongBuffer>
createLongBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count.CLProgram
createProgram(InputStream source)
Creates a program and reads the source from stream, the returned program is not build yet.CLProgram
createProgram(String src)
Creates a program from the given sources, the returned program is not build yet.CLProgram
createProgram(Map<CLDevice,byte[]> binaries)
Creates a program from the given binaries, the program is not build yet.CLSampler
createSampler(CLSampler.AddressingMode addrMode, CLSampler.FilteringMode filtMode, boolean normalizedCoords)
CLBuffer<ShortBuffer>
createShortBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count.boolean
equals(Object obj)
CL
getCL()
Return the low level OpenCL interface.CLContext
getContext()
Returns the context for this OpenCL object.CLDevice[]
getDevices()
Returns all devices associated with this CLContext.CLDevice
getMaxFlopsDevice()
Returns the device with maximal FLOPS from this context.CLDevice
getMaxFlopsDevice(CLDevice.Type type)
Returns the device with maximal FLOPS of the specified device type from this context.long
getMaxMemBaseAddrAlign()
Returns the maximumCLDevice.getMemBaseAddrAlign()
of all devices.List<CLMemory<? extends Buffer>>
getMemoryObjects()
Returns a read only shapshot of all allocated memory objects associated with this context.CLPlatform
getPlatform()
Returns the CLPlatform this context is running on.List<CLProgram>
getPrograms()
Returns a read only shapshot of all programs associated with this context.List<CLSampler>
getSamplers()
Returns a read only shapshot of all samplers associated with this context.CLImageFormat[]
getSupportedImage2dFormats(CLMemory.Mem... flags)
Returns all supported 2d image formats with the (optional) memory allocation flags.CLImageFormat[]
getSupportedImage3dFormats(CLMemory.Mem... flags)
Returns all supported 3d image formats with the (optional) memory allocation flags.int
hashCode()
boolean
isReleased()
Returns true ifCLResource.release()
has been called.protected void
overrideContext(CLDevice device)
void
release()
Releases this context and all resources.void
removeCLErrorHandler(CLErrorHandler handler)
protected static long
toDeviceBitmap(CLDevice.Type[] deviceTypes)
String
toString()
-
-
-
Field Detail
-
devices
protected CLDevice[] devices
-
queuesMap
protected final Map<CLDevice,List<CLCommandQueue>> queuesMap
-
platform
protected final CLPlatform platform
-
-
Constructor Detail
-
CLContext
protected CLContext(CLPlatform platform, long contextID, CLContext.ErrorDispatcher dispatcher)
-
-
Method Detail
-
create
public static CLContext create()
Creates a context on all available devices (CL_DEVICE_TYPE_ALL). The platform to be used is implementation dependent.
-
create
public static CLContext create(CLDevice.Type... deviceTypes)
Creates a context on the specified device types. The platform to be used is implementation dependent.
-
create
public static CLContext create(CLPlatform platform)
Creates a context on the specified platform on all available devices (CL_DEVICE_TYPE_ALL).
-
create
public static CLContext create(CLPlatform platform, CLDevice.Type... deviceTypes)
Creates a context on the specified platform and with the specified device types.
-
create
public static CLContext create(CLDevice... devices)
Creates a context on the specified devices.
-
createContextFromType
protected static long createContextFromType(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, long deviceType)
-
createContext
protected static long createContext(CLPlatform platform, CLErrorHandler handler, PointerBuffer properties, CLDevice... devices)
-
createProgram
public CLProgram createProgram(String src)
Creates a program from the given sources, the returned program is not build yet.
-
createProgram
public CLProgram createProgram(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.- Throws:
IOException
- when a IOException occurred while reading or closing the stream.
-
createProgram
public CLProgram createProgram(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
-
createShortBuffer
public final CLBuffer<ShortBuffer> createShortBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.
-
createIntBuffer
public final CLBuffer<IntBuffer> createIntBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.
-
createLongBuffer
public final CLBuffer<LongBuffer> createLongBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.
-
createFloatBuffer
public final CLBuffer<FloatBuffer> createFloatBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.
-
createDoubleBuffer
public final CLBuffer<DoubleBuffer> createDoubleBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and element count. No flags creates a MEM.READ_WRITE buffer.
-
createByteBuffer
public final CLBuffer<ByteBuffer> createByteBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags and buffer size in bytes. No flags creates a MEM.READ_WRITE buffer.
-
createByteBuffer
public final CLBuffer<ByteBuffer> createByteBuffer(int size, int flags)
Creates a CLBuffer with the specified flags and buffer size in bytes.
-
createBuffer
public final CLBuffer<?> createBuffer(int size, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer.
-
createBuffer
public final CLBuffer<?> createBuffer(int size, int flags)
Creates a CLBuffer with the specified flags.
-
createBuffer
public final <B extends Buffer> CLBuffer<B> createBuffer(B directBuffer, CLMemory.Mem... flags)
Creates a CLBuffer with the specified flags. No flags creates a MEM.READ_WRITE buffer.
-
createBuffer
public final <B extends Buffer> CLBuffer<B> createBuffer(B directBuffer, int flags)
Creates a CLBuffer with the specified flags.
-
createImage2d
public final CLImage2d<?> createImage2d(int width, int height, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.
-
createImage2d
public final CLImage2d<?> createImage2d(int width, int height, int rowPitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.
-
createImage2d
public final <B extends Buffer> CLImage2d<B> createImage2d(B directBuffer, int width, int height, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.
-
createImage2d
public final <B extends Buffer> CLImage2d<B> createImage2d(B directBuffer, int width, int height, int rowPitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage2d with the specified format, dimension and flags.
-
createImage3d
public final CLImage3d<?> createImage3d(int width, int height, int depth, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.
-
createImage3d
public final CLImage3d<?> createImage3d(int width, int height, int depth, int rowPitch, int slicePitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.
-
createImage3d
public final <B extends Buffer> CLImage3d<B> createImage3d(B directBuffer, int width, int height, int depth, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.
-
createImage3d
public final <B extends Buffer> CLImage3d<B> createImage3d(B directBuffer, int width, int height, int depth, int rowPitch, int slicePitch, CLImageFormat format, CLMemory.Mem... flags)
Creates a CLImage3d with the specified format, dimension and flags.
-
createSampler
public CLSampler createSampler(CLSampler.AddressingMode addrMode, CLSampler.FilteringMode filtMode, boolean normalizedCoords)
-
addCLErrorHandler
public void addCLErrorHandler(CLErrorHandler handler)
-
removeCLErrorHandler
public void removeCLErrorHandler(CLErrorHandler handler)
-
release
public void release()
Releases this context and all resources.- Specified by:
release
in interfaceCLResource
-
overrideContext
protected void overrideContext(CLDevice device)
-
getSupportedImage2dFormats
public CLImageFormat[] getSupportedImage2dFormats(CLMemory.Mem... flags)
Returns all supported 2d image formats with the (optional) memory allocation flags.
-
getSupportedImage3dFormats
public CLImageFormat[] getSupportedImage3dFormats(CLMemory.Mem... flags)
Returns all supported 3d image formats with the (optional) memory allocation flags.
-
getPlatform
public CLPlatform getPlatform()
Returns the CLPlatform this context is running on.- Overrides:
getPlatform
in classCLObject
-
getContext
public CLContext getContext()
Description copied from class:CLObject
Returns the context for this OpenCL object.- Overrides:
getContext
in classCLObject
-
getPrograms
public List<CLProgram> getPrograms()
Returns a read only shapshot of all programs associated with this context.
-
getMemoryObjects
public List<CLMemory<? extends Buffer>> getMemoryObjects()
Returns a read only shapshot of all allocated memory objects associated with this context.
-
getSamplers
public List<CLSampler> getSamplers()
Returns a read only shapshot of all samplers associated with this context.
-
getMaxFlopsDevice
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.
-
getMaxFlopsDevice
public CLDevice getMaxFlopsDevice(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.
-
getMaxMemBaseAddrAlign
public long getMaxMemBaseAddrAlign()
Returns the maximumCLDevice.getMemBaseAddrAlign()
of all devices.
-
getDevices
public CLDevice[] getDevices()
Returns all devices associated with this CLContext.
-
getCL
public CL getCL()
Return the low level OpenCL interface.
-
toDeviceBitmap
protected static long toDeviceBitmap(CLDevice.Type[] deviceTypes)
-
createErrorHandler
protected static CLContext.ErrorDispatcher createErrorHandler()
-
close
@Deprecated public final void close()
Deprecated.This method is not intended to be called from client code.Implementation detail, satisfyingAutoCloseable
. Might be remove as soon we have extension methods, but shall validate with Java 1.5 specs.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceAutoCloseable
- See Also:
AutoCloseable
-
isReleased
public boolean isReleased()
Description copied from interface:CLResource
Returns true ifCLResource.release()
has been called.- Specified by:
isReleased
in interfaceCLResource
-
-