Documentation ¶
Overview ¶
A wrapper package that attempts to map the OpenCL 1.1 C API to idiomatic Go.
Index ¶
- Constants
- Variables
- func UnloadCompiler() error
- func WaitForEvents(events ...*Event) error
- type BlockingCall
- type Buffer
- type BuildStatus
- type ChannelOrder
- type ChannelType
- type CommandExecutionStatus
- type CommandQueue
- func (cq *CommandQueue) EnqueueBarrier() error
- func (cq *CommandQueue) EnqueueCopyBuffer(src, dst *Buffer, srcOffset, dstOffset, size int64, waitList []*Event, ...) error
- func (cq *CommandQueue) EnqueueCopyBufferRect(src, dst *Buffer, r *Rect, waitList []*Event, e *Event) error
- func (cq *CommandQueue) EnqueueCopyBufferToImage(src *Buffer, dst *Image, offset int, r *Rect, waitList []*Event, e *Event) error
- func (cq *CommandQueue) EnqueueCopyImage(src, dst *Image, r *Rect, waitList []*Event, e *Event) error
- func (cq *CommandQueue) EnqueueCopyImageToBuffer(src *Image, dst *Buffer, r *Rect, offset int, waitList []*Event, e *Event) error
- func (cq *CommandQueue) EnqueueMapBuffer(b *Buffer, bc BlockingCall, flags MapFlags, offset, size int64, ...) (*MappedBuffer, error)
- func (cq *CommandQueue) EnqueueMapImage(i *Image, bc BlockingCall, flags MapFlags, r *Rect, waitList []*Event, ...) (*MappedImage, error)
- func (cq *CommandQueue) EnqueueMarker(e *Event) error
- func (cq *CommandQueue) EnqueueNDRangeKernel(k *Kernel, globalOffset, globalSize, localSize []int, waitList []*Event, ...) error
- func (cq *CommandQueue) EnqueueTask(k *Kernel, waitList []*Event, e *Event) error
- func (cq *CommandQueue) EnqueueUnmapBuffer(mb *MappedBuffer, waitList []*Event, e *Event) error
- func (cq *CommandQueue) EnqueueUnmapImage(mi *MappedImage, waitList []*Event, e *Event) error
- func (cq *CommandQueue) EnqueueWaitForEvents(waitList []*Event) error
- func (cq *CommandQueue) Finish() error
- func (cq *CommandQueue) Flush() error
- func (cq *CommandQueue) ReferenceCount() (int, error)
- func (cq *CommandQueue) Release() error
- func (cq *CommandQueue) Retain() error
- type CommandQueueProperties
- type CommandType
- type Context
- func (c *Context) CreateCommandQueue(d *Device, cqp CommandQueueProperties) (*CommandQueue, error)
- func (c *Context) CreateDeviceBuffer(size int64, mf MemFlags) (*Buffer, error)
- func (c *Context) CreateDeviceImage(mf MemFlags, format ImageFormat, width, height, depth int) (*Image, error)
- func (c *Context) CreateHostBuffer(size int64, mf MemFlags) (*Buffer, error)
- func (c *Context) CreateHostImage(mf MemFlags, format ImageFormat, width, height, depth int) (*Image, error)
- func (c *Context) CreateProgramWithBinary(d []*Device, binaries [][]byte, status []error) (*Program, error)
- func (c *Context) CreateProgramWithSource(sources ...[]byte) (*Program, error)
- func (c *Context) CreateUserEvent() (*Event, error)
- func (c *Context) GetSupportedImageFormats(mf MemFlags, mot MemObjectType) ([]ImageFormat, error)
- func (c *Context) ReferenceCount() (int, error)
- func (c *Context) Release() error
- func (c *Context) Retain() error
- type ContextCallback
- type ContextProperties
- type Device
- type DeviceType
- type Event
- func (e *Event) GetProfilingInfo() error
- func (e *Event) ReferenceCount() (int, error)
- func (e *Event) Release() error
- func (e *Event) Retain() error
- func (e *Event) SetCallback(callback EventCallback, userData interface{}) error
- func (e *Event) SetComplete() error
- func (e *Event) SetError(err int) error
- func (e *Event) Status() (ces CommandExecutionStatus, eventErr, getStatusErr error)
- func (e *Event) Wait() error
- type EventCallback
- type ExecCapabilities
- type FPConfig
- type GlobalMemCacheType
- type Image
- type ImageFormat
- type Kernel
- type KernelWorkGroupInfo
- type LocalMemTypeInfo
- type LocalSpaceArg
- type MapFlags
- type MappedBuffer
- func (mb *MappedBuffer) Bytes() []byte
- func (mb *MappedBuffer) Float32s() []float32
- func (mb *MappedBuffer) Read(b []byte) (int, error)
- func (mb *MappedBuffer) ReadAt(b []byte, offset int64) (int, error)
- func (mb *MappedBuffer) Seek(offset int64, whence int) (int64, error)
- func (mb *MappedBuffer) Write(b []byte) (int, error)
- func (mb *MappedBuffer) WriteAt(b []byte, offset int64) (int, error)
- func (mb *MappedBuffer) WriteTo(w io.Writer) (int64, error)
- type MappedImage
- type MemFlags
- type MemObjectType
- type Object
- type Platform
- type Profile
- type Program
- func (p *Program) Build(d []*Device, options string, pc ProgramCallback, userData interface{}) error
- func (p *Program) BuildLog(d *Device) (string, error)
- func (p *Program) BuildStatus(d *Device) (BuildStatus, error)
- func (p *Program) CreateKernel(name string) (*Kernel, error)
- func (p *Program) CreateKernelsInProgram() ([]*Kernel, error)
- func (p *Program) GetProgramBinaries() ([]ProgramBinary, error)
- func (p *Program) ReferenceCount() (int, error)
- func (p *Program) Release() error
- func (p *Program) Retain() error
- type ProgramBinary
- type ProgramCallback
- type Rect
- type RectLayout
- type VectorWidths
- type Version
Constants ¶
const ( GLContext = ContextProperties(clw.GLContext) EGLDisplay = ContextProperties(clw.EGLDisplay) GLXDisplay = ContextProperties(clw.GLXDisplay) )
const ( QueueOutOfOrderExecution = CommandQueueProperties(clw.QueueOutOfOrderExecModeEnable) QueueProfilingEnable = CommandQueueProperties(clw.QueueProfilingEnable) )
Bit field.
const ( DeviceTypeDefault = DeviceType(clw.DeviceTypeDefault) DeviceTypeCpu = DeviceType(clw.DeviceTypeCpu) DeviceTypeGpu = DeviceType(clw.DeviceTypeGpu) DeviceTypeAccelerator = DeviceType(clw.DeviceTypeAccelerator) DeviceTypeAll = DeviceType(clw.DeviceTypeAll) )
Bit field.
const ( FPDenorm = FPConfig(clw.FPDenorm) FPFma = FPConfig(clw.FPFma) FPInfNan = FPConfig(clw.FPInfNan) FPRoundToInf = FPConfig(clw.FPRoundToInf) FPRoundToNearest = FPConfig(clw.FPRoundToNearest) FPRoundToZero = FPConfig(clw.FPRoundToZero) FPSoftFloat = FPConfig(clw.FPSoftFloat) )
Bit field.
const ( None = GlobalMemCacheType(clw.None) ReadOnlyCache = GlobalMemCacheType(clw.ReadOnlyCache) ReadWriteCache = GlobalMemCacheType(clw.ReadWriteCache) )
const ( Global = LocalMemTypeInfo(clw.Global) Local = LocalMemTypeInfo(clw.Local) )
const ( ExecKernel = ExecCapabilities(clw.ExecKernel) ExecNativeKernel = ExecCapabilities(clw.ExecNativeKernel) )
Bit field.
const ( CommandNDRangeKernel = CommandType(clw.CommandNdrangeKernel) CommandTask = CommandType(clw.CommandTask) CommandNativeKernel = CommandType(clw.CommandNativeKernel) CommandReadBuffer = CommandType(clw.CommandReadBuffer) CommandWriteBuffer = CommandType(clw.CommandWriteBuffer) CommandCopyBuffer = CommandType(clw.CommandCopyBuffer) CommandReadImage = CommandType(clw.CommandReadImage) CommandWriteImage = CommandType(clw.CommandWriteImage) CommandCopyImage = CommandType(clw.CommandCopyImage) CommandCopyImageToBuffer = CommandType(clw.CommandCopyImageToBuffer) CommandCopyBufferToImage = CommandType(clw.CommandCopyBufferToImage) CommandMapBuffer = CommandType(clw.CommandMapBuffer) CommandMapImage = CommandType(clw.CommandMapImage) CommandUnmapMemoryObject = CommandType(clw.CommandUnmapMemoryObject) CommandMarker = CommandType(clw.CommandMarker) CommandAcquireGlObjects = CommandType(clw.CommandAcquireGlObjects) CommandReleaseGlObjects = CommandType(clw.CommandReleaseGlObjects) CommandReadBufferRectangle = CommandType(clw.CommandReadBufferRectangle) CommandWriteBufferRectangle = CommandType(clw.CommandWriteBufferRectangle) CommandCopyBufferRectangle = CommandType(clw.CommandCopyBufferRectangle) CommandUser = CommandType(clw.CommandUser) )
const ( Queued = CommandExecutionStatus(clw.Queued) Submitted = CommandExecutionStatus(clw.Submitted) Running = CommandExecutionStatus(clw.Running) Complete = CommandExecutionStatus(clw.Complete) )
const ( R = ChannelOrder(clw.R) A = ChannelOrder(clw.A) RG = ChannelOrder(clw.RG) RA = ChannelOrder(clw.RA) RGB = ChannelOrder(clw.RGB) RGBA = ChannelOrder(clw.RGBA) BGRA = ChannelOrder(clw.BGRA) ARGB = ChannelOrder(clw.ARGB) Intensity = ChannelOrder(clw.Intensity) Luminance = ChannelOrder(clw.Luminance) Rx = ChannelOrder(clw.Rx) RGx = ChannelOrder(clw.RGx) RGBx = ChannelOrder(clw.RGBx) )
const ( SnormInt8 = ChannelType(clw.SnormInt8) SnormInt16 = ChannelType(clw.SnormInt16) UnormInt8 = ChannelType(clw.UnormInt8) UnormInt16 = ChannelType(clw.UnormInt16) UnormShort565 = ChannelType(clw.UnormShort565) UnormShort555 = ChannelType(clw.UnormShort555) UnormInt101010 = ChannelType(clw.UnormInt101010) SignedInt8 = ChannelType(clw.SignedInt8) SignedInt16 = ChannelType(clw.SignedInt16) SignedInt32 = ChannelType(clw.SignedInt32) UnsignedInt8 = ChannelType(clw.UnsignedInt8) UnsignedInt16 = ChannelType(clw.UnsignedInt16) UnsignedInt32 = ChannelType(clw.UnsignedInt32) HalfFloat = ChannelType(clw.HalfFloat) Float32 = ChannelType(clw.Float32) )
const ( MemObjectBuffer = MemObjectType(clw.MemObjectBuffer) MemObjectImage2D = MemObjectType(clw.MemObjectImage2D) MemObjectImage3D = MemObjectType(clw.MemObjectImage3D) )
const ( MemReadWrite = MemFlags(clw.MemReadWrite) MemWriteOnly = MemFlags(clw.MemWriteOnly) MemReadOnly = MemFlags(clw.MemReadOnly) )
Bit field.
Bit field.
const ( Blocking = BlockingCall(clw.True) NonBlocking = BlockingCall(clw.False) )
const ( BuildSuccess = BuildStatus(clw.BuildSuccess) BuildNone = BuildStatus(clw.BuildNone) BuildError = BuildStatus(clw.BuildError) BuildInProgress = BuildStatus(clw.BuildInProgress) )
const (
ContextPlatform = ContextProperties(clw.ContextPlatform)
)
Variables ¶
var ( DeviceNotFound = clw.DeviceNotFound DeviceNotAvailable = clw.DeviceNotAvailable CompilerNotAvailable = clw.CompilerNotAvailable MemObjectAllocationFailure = clw.MemObjectAllocationFailure OutOfResources = clw.OutOfResources OutOfHostMemory = clw.OutOfHostMemory ProfilingInfoNotAvailable = clw.ProfilingInfoNotAvailable MemCopyOverlap = clw.MemCopyOverlap ImageFormatMismatch = clw.ImageFormatMismatch ImageFormatNotSupported = clw.ImageFormatNotSupported BuildProgramFailure = clw.BuildProgramFailure MapFailure = clw.MapFailure MisalignedSubBufferOffset = clw.MisalignedSubBufferOffset ExecStatusErrorForEventsInWaitList = clw.ExecStatusErrorForEventsInWaitList )
var ( InvalidValue = clw.InvalidValue InvalidDeviceType = clw.InvalidDeviceType InvalidPlatform = clw.InvalidPlatform InvalidDevice = clw.InvalidDevice InvalidContext = clw.InvalidContext InvalidQueueProperties = clw.InvalidQueueProperties InvalidCommandQueue = clw.InvalidCommandQueue InvalidHostPtr = clw.InvalidHostPtr InvalidMemObject = clw.InvalidMemObject InvalidImageFormatDescriptor = clw.InvalidImageFormatDescriptor InvalidImageSize = clw.InvalidImageSize InvalidSampler = clw.InvalidSampler InvalidBinary = clw.InvalidBinary InvalidBuildOptions = clw.InvalidBuildOptions InvalidProgram = clw.InvalidProgram InvalidProgramExecutable = clw.InvalidProgramExecutable InvalidKernelName = clw.InvalidKernelName InvalidKernelDefinition = clw.InvalidKernelDefinition InvalidKernel = clw.InvalidKernel InvalidArgIndex = clw.InvalidArgIndex InvalidArgValue = clw.InvalidArgValue InvalidArgSize = clw.InvalidArgSize InvalidKernelArgs = clw.InvalidKernelArgs InvalidWorkDimension = clw.InvalidWorkDimension InvalidWorkGroupSize = clw.InvalidWorkGroupSize InvalidWorkItemSize = clw.InvalidWorkItemSize InvalidGlobalOffset = clw.InvalidGlobalOffset InvalidEventWaitList = clw.InvalidEventWaitList InvalidEvent = clw.InvalidEvent InvalidOperation = clw.InvalidOperation InvalidGlObject = clw.InvalidGlObject InvalidBufferSize = clw.InvalidBufferSize InvalidMipLevel = clw.InvalidMipLevel InvalidGlobalWorkSize = clw.InvalidGlobalWorkSize InvalidProperty = clw.InvalidProperty )
var EntireImage = (*Rect)(nil)
EntireImage is a convenience value to ease reading of the code.
var ErrBufferFull = errors.New("cl: buffer full")
ErrBufferFull is returned when trying to write past the end of a buffer.
var ErrNotAddressable = errors.New("cl: not addressable")
ErrNotAddressable is returned when attempting to read from or write to a value that is not addressable (see reflect.Value.CanAddr).
var ErrUnsupportedImageFormat = errors.New("cl: unsupported image format")
ErrUnsupportedImageFormat is returned when trying to use one of the convenience image methods and there is a mismatch or incompatibility between the Go image and the OpenCL image.
Functions ¶
func UnloadCompiler ¶
func UnloadCompiler() error
Allows the implementation to release the resources allocated by the OpenCL compiler.
This is a hint from the application and does not guarantee that the compiler will not be used in the future or that the compiler will actually be unloaded by the implementation. Calls to clBuildProgram after clUnloadCompiler will reload the compiler, if necessary, to build the appropriate program executable.
func WaitForEvents ¶
Waits on the host thread for commands identified by event objects to complete.
Waits on the host thread for commands identified by event objects in event_list to complete. A command is considered complete if its execution status is "complete" or abnormally terminated (an error occured).
If the cl_khr_gl_event extension is enabled, event objects can also be used to reflect the status of an OpenGL sync object. The sync object in turn refers to a fence command executing in an OpenGL command stream. This provides another method of coordinating sharing of buffers and images between OpenGL and OpenCL.
Types ¶
type BlockingCall ¶
type Buffer ¶
type Buffer struct { // The context the buffer was created on. Context *Context // The size of the buffer in bytes. Size int64 // Usage information for the buffer from the device's point of view. Flags MemFlags // The host backed memory for the buffer, if applicable. Host interface{} // The parent buffer, if applicable. Buffer *Buffer // The offset in bytes within the parent buffer, if applicable. Origin int64 // contains filtered or unexported fields }
A buffer object stores a one-dimensional collection of elements (though there are "rectangle" operations). Elements of a buffer object can be a scalar data type (such as an int, float), vector data type, or a user-defined structure.
func (*Buffer) CreateSubBuffer ¶
Creates a buffer object from an existing object with the passed offset and size in bytes.
If the size and offset are the same as another sub buffer the implementation may return the same sub buffer and increment the reference count.
func (*Buffer) ReferenceCount ¶
Return the buffer's reference count.
The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
type BuildStatus ¶
type BuildStatus clw.BuildStatus
func (BuildStatus) String ¶
func (bs BuildStatus) String() string
type ChannelOrder ¶
type ChannelOrder clw.ChannelOrder
func (ChannelOrder) String ¶
func (co ChannelOrder) String() string
type ChannelType ¶
type ChannelType clw.ChannelType
func (ChannelType) String ¶
func (ct ChannelType) String() string
type CommandExecutionStatus ¶
type CommandExecutionStatus int
func (CommandExecutionStatus) String ¶
func (ces CommandExecutionStatus) String() string
type CommandQueue ¶
type CommandQueue struct { // The context the command queue was created on. Context *Context // The device the command queue was created for. Device *Device // Bit-field list of properties for the command queue. Properties CommandQueueProperties // contains filtered or unexported fields }
The OpenCL functions that are submitted to a command-queue are enqueued in the order the calls are made but can be configured to execute in-order or out-of-order. The properties argument in CreateCommandQueue can be used to specify the execution order. In addition, a wait for events or a barrier command can be enqueued to the command-queue. The wait for events command ensures that previously enqueued commands identified by the list of events to wait for have finished before the next batch of commands is executed. The barrier command ensures that all previously enqueued commands in a command- queue have finished execution before the next batch of commands is executed. Similarly, commands to read, write, copy or map memory objects that are enqueued after EnqueueNDRangeKernel, EnqueueTask or EnqueueNativeKernel commands are not guaranteed to wait for kernels scheduled for execution to have completed (if the out of order property is set). To ensure correct ordering of commands, the event object returned by EnqueueNDRangeKernel, EnqueueTask or EnqueueNativeKernel can be used to enqueue a wait for event or a barrier command can be enqueued that must complete before reads or writes to the memory object(s) occur.
func (*CommandQueue) EnqueueBarrier ¶
func (cq *CommandQueue) EnqueueBarrier() error
A synchronization point that enqueues a barrier operation.
EnqueueBarrier is a synchronization point that ensures that all queued commands in command_queue have finished execution before the next batch of commands can begin execution.
func (*CommandQueue) EnqueueCopyBuffer ¶
func (cq *CommandQueue) EnqueueCopyBuffer(src, dst *Buffer, srcOffset, dstOffset, size int64, waitList []*Event, e *Event) error
Enqueues a command to copy from one buffer object to another.
Source offset, destination offset, and size are in bytes.
func (*CommandQueue) EnqueueCopyBufferRect ¶
func (cq *CommandQueue) EnqueueCopyBufferRect(src, dst *Buffer, r *Rect, waitList []*Event, e *Event) error
Enqueues a command to copy a rectangular region from the buffer object to another buffer object.
See Rect definition for how source and destination are defined.
func (*CommandQueue) EnqueueCopyBufferToImage ¶
func (cq *CommandQueue) EnqueueCopyBufferToImage(src *Buffer, dst *Image, offset int, r *Rect, waitList []*Event, e *Event) error
Only the destination and region are used from the rectangle.
func (*CommandQueue) EnqueueCopyImage ¶
func (cq *CommandQueue) EnqueueCopyImage(src, dst *Image, r *Rect, waitList []*Event, e *Event) error
Enqueues a command to copy image objects.
func (*CommandQueue) EnqueueCopyImageToBuffer ¶
func (cq *CommandQueue) EnqueueCopyImageToBuffer(src *Image, dst *Buffer, r *Rect, offset int, waitList []*Event, e *Event) error
Only the source and region are used from the rectangle.
func (*CommandQueue) EnqueueMapBuffer ¶
func (cq *CommandQueue) EnqueueMapBuffer(b *Buffer, bc BlockingCall, flags MapFlags, offset, size int64, waitList []*Event, e *Event) (*MappedBuffer, error)
Enqueues a command to map a region of the buffer object given by buffer into the host address space.
func (*CommandQueue) EnqueueMapImage ¶
func (cq *CommandQueue) EnqueueMapImage(i *Image, bc BlockingCall, flags MapFlags, r *Rect, waitList []*Event, e *Event) (*MappedImage, error)
Enqueues a command to map a region of an image object into the host address space. Uses the Src and Region component of the rectangle.
func (*CommandQueue) EnqueueMarker ¶
func (cq *CommandQueue) EnqueueMarker(e *Event) error
Enqueues a marker command.
Enqueues a marker command to the command queue. The marker command is not completed until all commands enqueued before it have completed. The marker command returns an event which can be waited on.
func (*CommandQueue) EnqueueNDRangeKernel ¶
func (cq *CommandQueue) EnqueueNDRangeKernel(k *Kernel, globalOffset, globalSize, localSize []int, waitList []*Event, e *Event) error
Enqueues a command to execute a kernel on a device.
GlobalOffset is optional, if it omitted it is assumed to be all zeros. The dimensions of globalOffset, globalSize, and localSize must match and be less than or equal to the max work item dimensions.
func (*CommandQueue) EnqueueTask ¶
func (cq *CommandQueue) EnqueueTask(k *Kernel, waitList []*Event, e *Event) error
Enqueues a command to execute a kernel on a device.
The kernel is executed using a single work-item.
func (*CommandQueue) EnqueueUnmapBuffer ¶
func (cq *CommandQueue) EnqueueUnmapBuffer(mb *MappedBuffer, waitList []*Event, e *Event) error
Enqueues a command to unmap a previously mapped buffer object.
func (*CommandQueue) EnqueueUnmapImage ¶
func (cq *CommandQueue) EnqueueUnmapImage(mi *MappedImage, waitList []*Event, e *Event) error
Enqueues a command to unmap a previously mapped image object.
func (*CommandQueue) EnqueueWaitForEvents ¶
func (cq *CommandQueue) EnqueueWaitForEvents(waitList []*Event) error
Enqueues a wait for a specific event or a list of events to complete before any future commands queued in the command-queue are executed.
The context associated with events in event_list and command_queue must be the same.
func (*CommandQueue) Finish ¶
func (cq *CommandQueue) Finish() error
Blocks until all previously queued OpenCL commands in a command-queue are issued to the associated device and have completed.
Blocks until all previously queued OpenCL commands in command_queue are issued to the associated device and have completed. Finish does not return until all queued commands in command_queue have been processed and completed. Finish is also a synchronization point.
func (*CommandQueue) Flush ¶
func (cq *CommandQueue) Flush() error
Issues all previously queued OpenCL commands in a command-queue to the device associated with the command-queue.
Flush only guarantees that all queued commands to command_queue get issued to the appropriate device. There is no guarantee that they will be complete after clFlush returns. Any blocking commands queued in a command-queue perform an implicit flush of the command-queue. To use event objects that refer to commands enqueued in a command-queue as event objects to wait on by commands enqueued in a different command-queue, the application must call a Flush or any blocking commands that perform an implicit flush of the command- queue where the commands that refer to these event objects are enqueued.
func (*CommandQueue) ReferenceCount ¶
func (cq *CommandQueue) ReferenceCount() (int, error)
Return the command queue's reference count.
The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
func (*CommandQueue) Release ¶
func (cq *CommandQueue) Release() error
Decrements the command_queue reference count.
func (*CommandQueue) Retain ¶
func (cq *CommandQueue) Retain() error
Increments the command_queue reference count.
type CommandQueueProperties ¶
type CommandQueueProperties uint
func (CommandQueueProperties) String ¶
func (cqp CommandQueueProperties) String() string
type CommandType ¶
type CommandType int
func (CommandType) String ¶
func (ct CommandType) String() string
type Context ¶
type Context struct { // The devices in the context. Devices []*Device // The properties used to create the context. Properties []ContextProperties // contains filtered or unexported fields }
An OpenCL context is created with one or more devices. Contexts are used by the OpenCL runtime 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.
func CreateContext ¶
func CreateContext(d []*Device, cp []ContextProperties, cc ContextCallback, userData interface{}) (*Context, error)
Creates an OpenCL context.
An OpenCL context is created with one or more devices. Contexts are used by the OpenCL runtime 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.
WARNING: The callback and user data will be referenced for the lifetime of
the program. Thus any variables captured if callback is a closure or any variables referenced by user data will not be garbage collected.
func CreateContextFromType ¶
func CreateContextFromType(cp []ContextProperties, dt DeviceType, cc ContextCallback, userData interface{}) (*Context, error)
Create an OpenCL context from a device type that identifies the specific device(s) to use.
WARNING: The callback and user data will be referenced for the lifetime of
the program. Thus any variables captured if callback is a closure or any variables referenced by user data will not be garbage collected.
func (*Context) CreateCommandQueue ¶
func (c *Context) CreateCommandQueue(d *Device, cqp CommandQueueProperties) (*CommandQueue, error)
Create a command-queue on a specific device.
func (*Context) CreateDeviceBuffer ¶
Creates a buffer object on the device.
Creates an uninitialized buffer on the device. The size is in bytes.
func (*Context) CreateDeviceImage ¶
func (c *Context) CreateDeviceImage(mf MemFlags, format ImageFormat, width, height, depth int) (*Image, error)
Creates an image object on the device.
Creates an uninitialized buffer on the device.
func (*Context) CreateHostBuffer ¶
Creates a buffer object that is host accessible.
Creates an uninitialized buffer in pinned memory. The size is in bytes. This memory is not pageable and allows for DMA copies (which are faster).
func (*Context) CreateHostImage ¶
func (c *Context) CreateHostImage(mf MemFlags, format ImageFormat, width, height, depth int) (*Image, error)
Creates a image object that is host accessible.
Creates an uninitialized buffer on the host. This memory is not pageable and allows for DMA copies (which are faster).
func (*Context) CreateProgramWithBinary ¶
func (c *Context) CreateProgramWithBinary(d []*Device, binaries [][]byte, status []error) (*Program, error)
Creates a program object for a context for the specified devices with the passed binaries.
Length of devices, binaries, and status must match (though status can be nil). The status will contain an error, or not, for each device.
func (*Context) CreateProgramWithSource ¶
Create a program object for a context with the specified source.
The devices associated with the program are initially all the context devices.
func (*Context) CreateUserEvent ¶
Creates a user event object.
User events allow applications to enqueue commands that wait on a user event to finish before the command is executed by the device. The execution status of the user event object created is set to Submitted.
Enqueued commands that specify user events must ensure that the status of the user events be set before any OpenCL APIs that release OpenCL objects except for event objects are called.
func (*Context) GetSupportedImageFormats ¶
func (c *Context) GetSupportedImageFormats(mf MemFlags, mot MemObjectType) ([]ImageFormat, error)
Get the list of image formats supported by an OpenCL implementation.
func (*Context) ReferenceCount ¶
The context reference count.
The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
func (*Context) Release ¶
Decrement the context reference count.
After the context reference count becomes zero and all the objects attached to context (such as memory objects, command-queues) are released, the context is deleted.
func (*Context) Retain ¶
Increment the context reference count.
CreateContext and CreateContextFromType perform an implicit retain. This is very helpful for 3rd party libraries, which typically get a context passed to them by the application. However, it is possible that the application may delete the context without informing the library. Allowing functions to attach to (i.e. retain) and release a context solves the problem of a context being used by a library no longer being valid.
type ContextCallback ¶
type ContextProperties ¶
type ContextProperties clw.ContextProperties
type Device ¶
type Device struct { // The platform from which the device was created. Platform *Platform // A device type can be a CPU, a host processor that runs the OpenCL // implementation. A GPU, a device can also be used to accelerate a 3D API // such as OpenGL or DirectX. A dedicated OpenCL accelerator (for example // the IBM CELL Blade), these devices communicate with the host processor // using a peripheral interconnect such as PCIe. Type DeviceType // True if the device is available. Available bool // False if the implementation does not have a compiler available to compile // the program source. Can only be false on an embedded platform. CompilerAvailable bool // Either binary.BigEndian or binary.LittleEndian. ByteOrder binary.ByteOrder // True if the device implements error correction for all accesses to // compute device memory (global and constant). ErrorCorrectionSupport bool // True if if images are supported. ImageSupport bool // True if the device and the host have a unified memory subsystem. UnifiedHostMemory bool // The default compute device address space size in bits. Currently // supported values are 32 or 64 bits. AddressBits int // Size of global memory cache line in bytes. GlobalMemCachelineSize int // Maximum configured clock frequency of the device in MHz. MaxClockFrequency int // The number of parallel compute cores on the OpenCL device. The minimum // value is 1. MaxComputeUnits int // Max number of arguments declared with the __constant qualifier in a // kernel. The minimum value is 8. MaxConstantArgs int // Max number of simultaneous image objects that can be read by a kernel. // The minimum value is 128 if ImageSupport is true. MaxReadImageArgs int // Maximum number of samplers that can be used in a kernel. The minimum // value is 16 if ImageSupport is true. MaxSamplers int // Maximum dimensions that specify the global and local work-item IDs used // by the data parallel execution model. (Refer to EnqueueNDRangeKernel). // The minimum value is 3. MaxWorkItemDimensions int // Max number of simultaneous image objects that can be written to by a // kernel. The minimum value is 8 if ImageSupport is true. MaxWriteImageArgs int // Describes the alignment in bits of the base address of any allocated // memory object. MemBaseAddrAlign int // The smallest alignment in bytes which can be used for any data type. MinDataTypeAlignSize int // Preferred native vector width size for built-in scalar types that can be // put into vectors. The vector width is defined as the number of scalar // elements that can be stored in the vector. PreferredVectorWidths VectorWidths // Returns the native ISA vector width. The vector width is defined as the // number of scalar elements that can be stored in the vector. NativeVectorWidths VectorWidths // Extensions supported by the device. Extensions []string // Device name string. Name string // Either FulleProfile, if the device supports the OpenCL specification // (functionality defined as part of the core specification and does not // require any extensions to be supported). Or EmbedddedProfile, if the // device supports the OpenCL embedded profile. Profile Profile // Vendor name string. Vendor string // A unique device vendor identifier. An example of a unique device // identifier could be the PCIe ID. VendorID int // The OpenCL version supported by the device. Version Version // The highest OpenCL C version supported by the compiler for this device. OpenCLCVersion Version // OpenCL software driver version. DriverVersion Version // Size of global memory cache in bytes. GlobalMemCacheSize int64 // Size of global device memory in bytes. GlobalMemSize int64 // Size of local memory arena in bytes. The minimum value is 32 KB. LocalMemSize int64 // Max size in bytes of a constant buffer allocation. The minimum value is // 64 KB. MaxConstantBufferSize int64 // Max size of memory object allocation in bytes. The minimum value is // max(1/4th of GlobalMemSize, 128*1024*1024). MaxMemAllocSize int64 // Max height of 2D image in pixels. The minimum value is 8192 if // ImageSupport is true. Image2DMaxHeight int // Max width of 2D image in pixels. The minimum value is 8192 if // ImageSupport is true. Image2DMaxWidth int // Max depth of 3D image in pixels. The minimum value is 2048 if // ImageSupport is true. Image3DMaxDepth int // Max height of 3D image in pixels. The minimum value is 2048 if // ImageSupport is true. Image3DMaxHeight int // Max width of 3D image in pixels. The minimum value is 2048 if // ImageSupport is true. Image3DMaxWidth int // Max size in bytes of the arguments that can be passed to a kernel. The // minimum value is 1024. For this minimum value, only a maximum of 128 // arguments can be passed to a kernel. MaxParameterSize int // Maximum number of work-items in a work-group executing a kernel using the // data parallel execution model. (Refer to EnqueueNDRangeKernel). The // minimum value is 1. MaxWorkGroupSize int // Describes the resolution of device timer. This is measured in nanoseconds. ProfilingTimerResolution int // Maximum number of work-items that can be specified in each dimension of // the work-group to EnqueueNDRangeKernel. Returns n entries, where n is the // value returned by the query for MaxWorkItemDimensions. The minimum value // is (1, 1, 1). MaxWorkItemSizes []int // Describes single precision floating-point capability of the device. The // mandated minimum capability is round to nearest and infinity and NaN // supported. Basic operations can be implemented in software (soft floats). SingleFpConfig FPConfig // Describes optional double precision floating-point capability of the // device. The mandated minimum capability is fused multiply-add, round the // nearest, round to zero, round to infinity, infinity and NaN support, and // denormalized numbers. DoubleFpConfig FPConfig // Describes the execution capabilities of the device. This is a bit-field // that describes one or more of the following values: ExecKernel - The // OpenCL device can execute OpenCL kernels. ExecNativeKernel - The OpenCL // device can execute native kernels. The mandated minimum capability is // ExecKernel. ExecCapabilities ExecCapabilities // Describes the command-queue properties supported by the device. This is a // bit-field that describes one or more of the following values: // QueueOutOfOrderExecution. QueueProfilingEnable. These // properties are described in the table for CreateCommandQueue. The // mandated minimum capability is QueueProfilingEnable. CommandQueueProperties CommandQueueProperties // Type of global memory cache supported. Valid values are: None, // ReadOnlyCache, and ReadWriteCache. GlobalMemCacheType GlobalMemCacheType // Type of local memory supported. This can be set to Local implying // dedicated local memory storage such as SRAM, or Global. LocalMemTypeInfo LocalMemTypeInfo // contains filtered or unexported fields }
Device configuration information, also used to create Contexts.
func (*Device) HasExtension ¶
Check if the device supports the extension.
type DeviceType ¶
type DeviceType uint
func (DeviceType) String ¶
func (dt DeviceType) String() string
type Event ¶
type Event struct { // The context the event was created on. Context *Context // The command type the event represents. CommandType CommandType // The command queue the event was created on. CommandQueue *CommandQueue Queued int64 // Profiling information. Submit int64 // Profiling information. Start int64 // Profiling information. End int64 // Profiling information. // contains filtered or unexported fields }
Event objects can be used to refer to a kernel execution command, read, write, map and copy commands on memory objects, EnqueueMarker, or user events.
An event object can be used to track the execution status of a command. The API calls that enqueue commands to a command-queue create a new event object that is returned in the event argument.
func (*Event) GetProfilingInfo ¶
Gets profiling information for the command associated with event if profiling is enabled.
The 64-bit values can be used to measure the time in nano-seconds consumed by OpenCL commands.
OpenCL devices are required to correctly track time across changes in device frequency and power states. The Device.ProfilingTimerResolution specifies the resolution of the timer i.e. the number of nanoseconds elapsed before the timer is incremented.
Event objects can be used to capture profiling information that measure execution time of a command. Profiling of OpenCL commands can be enabled either by using a command-queue created with QueueProfilingEnable flag set in properties argument to CreateCommandQueue.
func (*Event) ReferenceCount ¶
The event reference count.
The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
func (*Event) Release ¶
Decrements the event reference count.
The event object is deleted once the reference count becomes zero, the specific command identified by this event has completed (or terminated) and there are no commands in the command-queues of a context that require a wait for this event to complete.
func (*Event) Retain ¶
Increments the event reference count.
The OpenCL commands that return an event perform an implicit retain.
func (*Event) SetCallback ¶
func (e *Event) SetCallback(callback EventCallback, userData interface{}) error
Registers a user callback function for a specific command execution status.
The registered callback function will be called when the execution status of command associated with event changes to Complete or is abnormally terminated due to an error.
Each call to SetCallback registers the specified user callback function on a callback stack associated with event. The order in which the registered user callback functions are called is undefined.
All callbacks registered for an event object must be called. All enqueued callbacks shall be called before the event object is destroyed. Callbacks must return promptly. The behavior of calling expensive system routines, OpenCL API calls to create contexts or command-queues, or blocking OpenCL operations, in a callback is undefined.
func (*Event) SetComplete ¶
Sets the execution status of a user event object to Complete.
func (*Event) SetError ¶
Sets the execution status of a user event object to an error state. All enqueued commands that wait on this user event will be terminated. Err must be negative.
func (*Event) Status ¶
func (e *Event) Status() (ces CommandExecutionStatus, eventErr, getStatusErr error)
Return the execution status of the command identified by event.
Statuses are: Queued (command has been enqueued in the command-queue), Submitted (enqueued command has been submitted by the host to the device associated with the command-queue), Running (device is currently executing this command), Complete (the command has completed).
An eventErr is an error that cause the event to abnormally terminate. A getStatusErr is an error that occurred while trying to retrieve the event's status.
type EventCallback ¶
Differs from clw.EventCallbackFunc because the command execution status is either Complete (success) or an error.
type ExecCapabilities ¶
type ExecCapabilities uint
func (ExecCapabilities) String ¶
func (ec ExecCapabilities) String() string
type GlobalMemCacheType ¶
type GlobalMemCacheType int
func (GlobalMemCacheType) String ¶
func (gmct GlobalMemCacheType) String() string
type Image ¶
type Image struct { // The context the buffer was created on. Context *Context // The image format, the channel order and data type. Format ImageFormat // Size of each element of the image memory object ElementSize int // The width in pixels. Width int // The height in pixels. Height int // The depth in pixels. One for a 2D image. Depth int // Scan line width in bytes. Only valid if Host is not nil. If Host is not // nil then valid values are 0 (which is the same as Width * ElementSize) or // a value greater than or equal to Width * ElementSize. RowPitch int // The size in bytes of each 2D image in bytes. Only valid if Host is not // nil. valid values are 0 (which is the same as RowPitch * Height) or a // value greater than or equal to RowPitch * Height. SlicePitch int // Usage information for the buffer from the device's point of view. Flags MemFlags // The host backed memory for the buffer, if applicable. Host interface{} // contains filtered or unexported fields }
A 2D or 3D image (Depth is 1 and SlicePitch is 0 for 2D images).
TODO If Depth is 1 and SlicePitch is 0 it is ambiguous whether it is a 2D or 3D image.
func (*Image) ReferenceCount ¶
Return the image's reference count.
The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
type ImageFormat ¶
type ImageFormat struct { ChannelOrder ChannelOrder ChannelType ChannelType }
type Kernel ¶
type Kernel struct { // The number of arguments to kernel. Arguments int // The kernel function name. FunctionName string // The context associated with the kernel. Context *Context // The program associated with the kernel. Program *Program // Information about the kernel object that may be specific to a device. WorkGroupInfo []KernelWorkGroupInfo // contains filtered or unexported fields }
A kernel is a function declared in a program.
func (*Kernel) ReferenceCount ¶
Return the kernel reference count.
The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
func (*Kernel) Release ¶
Decrements the kernel reference count.
The kernel object is deleted once the number of instances that are retained to kernel become zero and the kernel object is no longer needed by any enqueued commands that use kernel.
func (*Kernel) Retain ¶
Increments the kernel object reference count.
CreateKernel or CreateKernelsInProgram do an implicit retain.
func (*Kernel) SetArg ¶
Set the argument value for a specific argument of a kernel.
All OpenCL API calls are thread-safe except SetArg (and SetArguments), which is safe to call from any host thread, and is re-entrant so long as concurrent calls operate on different cl_kernel objects.
A kernel object does not update the reference count for objects such as memory, sampler objects specified as argument values by clSetKernelArg. Users may not rely on a kernel object to retain objects specified as argument values to the kernel.
func (*Kernel) SetArguments ¶
Set all argument values of a kernel.
This is a convenience wrapper around SetArg, consult it for more info.
type KernelWorkGroupInfo ¶
type KernelWorkGroupInfo struct { // The device associated with the kernel. Device *Device // The maximum work group size that can be used by the kernel to execute on // the device. WorkGroupSize int // The work group size specified in the function qualifiers or all zeros. CompileWorkGroupSize [3]int // The amount of local memory used by the kernel. LocalMemSize int // The preferred multiple of work group size for launch. This is a // performance hint. PreferredWorkGroupSizeMultiple int // The minimum amount of private memory, in bytes, used by each work item in // the kernel. PrivateMemSize int }
Information about the kernel object specific to a device.
type LocalMemTypeInfo ¶
type LocalMemTypeInfo int
func (LocalMemTypeInfo) String ¶
func (lmti LocalMemTypeInfo) String() string
type LocalSpaceArg ¶
type LocalSpaceArg int
Type passed to SetArguments to allocate the set amount of local memory.
type MappedBuffer ¶
type MappedBuffer struct { Buffer *Buffer // contains filtered or unexported fields }
MappedBuffer is a mapping of an OpenCL buffer into the host address space. It implements a number of IO interfaces and can be converted to slices of the numeric types.
func (*MappedBuffer) Bytes ¶
func (mb *MappedBuffer) Bytes() []byte
Returns a slice of bytes backed by the mapped buffer.
func (*MappedBuffer) Float32s ¶
func (mb *MappedBuffer) Float32s() []float32
Returns a slice of float32s backed by the mapped buffer.
func (*MappedBuffer) Read ¶
func (mb *MappedBuffer) Read(b []byte) (int, error)
Read reads the next len(b) bytes from the buffer or until the buffer is drained. The return value is the number of bytes read. If the buffer has no data to return the error is io.EOF (unless len(b) is zero); otherwise it is nil.
func (*MappedBuffer) ReadAt ¶
func (mb *MappedBuffer) ReadAt(b []byte, offset int64) (int, error)
ReadAt reads len(b) bytes into b starting at offset off in the underlying input source. It returns the number of bytes read (0 <= n <= len(b)) and any error encountered. When ReadAt returns n < len(b), it returns io.EOF.
func (*MappedBuffer) Seek ¶
func (mb *MappedBuffer) Seek(offset int64, whence int) (int64, error)
Seek sets the offset for the next Read or Write to offset, interpreted according to whence: 0 means relative to the origin, 1 means relative to the current offset, and 2 means relative to the end. Seek returns the new offset and an error, if any.
Seeking to a negative offset is an error. Seeking to any positive offset is legal, but an offset larger than the buffer's size will result in io.EOF for reads and ErrBufferFull for writes.
func (*MappedBuffer) Write ¶
func (mb *MappedBuffer) Write(b []byte) (int, error)
Write writes the next len(b) bytes from the buffer or as much as possible until the buffer is full. The return value is the number of bytes written. If the buffer has no room to write all the data, err is ErrBufferFull (unless len(b) is zero); otherwise it is nil.
func (*MappedBuffer) WriteAt ¶
func (mb *MappedBuffer) WriteAt(b []byte, offset int64) (int, error)
WriteAt writes len(b) bytes from b to the buffer at offset. It returns the number of bytes written from b (0 <= n <= len(b)). WriteAt returns ErrBufferFull if it wrote less than len(b).
func (*MappedBuffer) WriteTo ¶
func (mb *MappedBuffer) WriteTo(w io.Writer) (int64, error)
WriteTo writes data to w until the buffer is drained or an error occurs. The return value is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned.
type MappedImage ¶
type MappedImage struct { Image *Image // contains filtered or unexported fields }
A mapped image. Has convenience functions for common data types.
func (*MappedImage) GoImage ¶
func (mi *MappedImage) GoImage() (image.Image, error)
Returns an image if there is a mapping from the CL image to a Go image.
func (*MappedImage) RGBA ¶
func (mi *MappedImage) RGBA() *image.RGBA
Return an RGBA image with its pixels backed by the mapped buffer.
type MemObjectType ¶
type MemObjectType clw.MemObjectType
type Platform ¶
type Platform struct { // The profile name supported by the implementation, either the full profile // or a subset of each OpenCL version (embedded profile). Profile Profile // A Platform's version. Version Version // Platform's name. Name string // Vendor's name. Vendor string // Extensions supported by all devices associated with the platform. Extensions []string // Devices available on the platform. Devices []*Device // contains filtered or unexported fields }
Platforms implement specific features and allow applications to query devices.
func GetPlatforms ¶
Obtain the list of platforms and their information.
func (*Platform) HasExtension ¶
Check if the platform supports the extension.
func (*Platform) ToContextProperty ¶
func (p *Platform) ToContextProperty() ContextProperties
Returns the platform as a ContextProperties suitable for adding to a property list during context creation.
type Program ¶
type Program struct { // The context the program is associated with. Context *Context // The devices associated with the program. Devices []*Device // The build options specified during Build. Options string // contains filtered or unexported fields }
A program object created from either source or a binary.
func (*Program) Build ¶
func (p *Program) Build(d []*Device, options string, pc ProgramCallback, userData interface{}) error
Builds (compiles and links) a program executable from the program source or binary.
The build options are categorized as pre-processor options, options for math intrinsics, options that control optimization and miscellaneous options. This specification defines a standard set of options that must be supported by an OpenCL compiler when building program executables online or offline. These may be extended by a set of vendor- or platform-specific options.
The callback is optional. If it is supplied Build will return immediately, if it isn't then Build will block until the program has been build (successfully or unsuccessfully).
func (*Program) BuildStatus ¶
func (p *Program) BuildStatus(d *Device) (BuildStatus, error)
Returns build status for the device in the program object.
func (*Program) CreateKernel ¶
Creates a kernel object.
A kernel is a function declared in a program. A kernel is identified by the __kernel qualifier applied to any function in a program. A kernel object encapsulates the specific __kernel function declared in a program and the argument values to be used when executing this __kernel function.
func (*Program) CreateKernelsInProgram ¶
Creates kernel objects for all kernel functions in a program object.
Creates kernel objects for all kernel functions in program. Kernel objects are not created for any __kernel functions in program that do not have the same function definition across all devices for which a program executable has been successfully built.
func (*Program) GetProgramBinaries ¶
func (p *Program) GetProgramBinaries() ([]ProgramBinary, error)
Returns the binaries for each device associated with the program.
The binaries can be the source of CreateProgramWithBinary or the result of Build from either source or binaries. The returned bits can be an implementation specific intermediate representation, device specific bits, or both.
func (*Program) ReferenceCount ¶
The program reference count.
The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
type ProgramBinary ¶
type ProgramBinary struct { // The program from which the binary was compiled. Program *Program // The device for which the binary was compiled. Device *Device // The binary. Can be an implementation specific intermediate // representation, device specific bits, or both. Binary []byte }
A program binary for a device.
type ProgramCallback ¶
type ProgramCallback func(p *Program, userData interface{})
type Rect ¶
type Rect struct { // The source offset in bytes. The offset in bytes is Src.Origin[2] * // Src.SlicePitch + Src.Origin[1] * Src.RowPitch + Src.Origin[0]. Src RectLayout // The destination offset in bytes. The offset in bytes is Dst.Origin[2] * // Dst.SlicePitch + Dst.Origin[1] * Dst.RowPitch + Dst.Origin[0]. Dst RectLayout // The (width, height, depth) in bytes of the region being copied. For a 2D // rectangle the depth value given by Region[2] must be 1. Region [3]int64 }
A source and destination rectangular region.
type RectLayout ¶
RectLayout defines a rectangle layout in bytes. For a 2D rectangle SlicePitch and Origin[2] must be zero. The offset of pixel X,Y,Z in bytes is (Z-Origin[2])*SlicePitch + (Y-Origin[1])*RowPitch + (X-Origin[0]).