opencl

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package opencl provides Go wrappers for the OpenCL 2.0 runtime API. The runtime is loaded dynamically via dlopen; no build tags required.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available() bool

Available returns true if libOpenCL can be loaded on this machine. The result is cached after the first call.

func GetDeviceCount

func GetDeviceCount() (int, error)

GetDeviceCount returns the total number of OpenCL GPU devices.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context holds an OpenCL context, device, and default command queue.

func NewContext

func NewContext(deviceID int) (*Context, error)

NewContext creates an OpenCL context on the specified device. If deviceID is -1, the first available GPU device is used.

func (*Context) CLContext

func (c *Context) CLContext() unsafe.Pointer

CLContext returns the underlying cl_context for kernel compilation.

func (*Context) CLDevice

func (c *Context) CLDevice() unsafe.Pointer

CLDevice returns the underlying cl_device_id.

func (*Context) CLQueue

func (c *Context) CLQueue() unsafe.Pointer

CLQueue returns the default command queue.

func (*Context) CreateStream

func (c *Context) CreateStream() (*Stream, error)

CreateStream creates a new command queue (stream equivalent).

func (*Context) Destroy

func (c *Context) Destroy() error

Destroy releases the OpenCL context and default command queue.

func (*Context) DeviceID

func (c *Context) DeviceID() int

DeviceID returns the device ordinal.

func (*Context) Free

func (c *Context) Free(ptr unsafe.Pointer) error

Free releases a device buffer.

func (*Context) Malloc

func (c *Context) Malloc(size int) (unsafe.Pointer, error)

Malloc allocates a device buffer of the given size. Returns the cl_mem handle cast to unsafe.Pointer.

func (*Context) Memcpy

func (c *Context) Memcpy(dst, src unsafe.Pointer, count int, kind MemcpyKind) error

Memcpy copies data between host and device.

func (*Context) SetDevice

func (c *Context) SetDevice(deviceID int) error

SetDevice is a no-op for OpenCL (device is selected at context creation).

type MemcpyKind

type MemcpyKind int

MemcpyKind specifies the direction of a memory copy.

const (
	// MemcpyHostToDevice copies from host to device.
	MemcpyHostToDevice MemcpyKind = iota
	// MemcpyDeviceToHost copies from device to host.
	MemcpyDeviceToHost
	// MemcpyDeviceToDevice copies from device to device.
	MemcpyDeviceToDevice
)

type OpenCLLib

type OpenCLLib struct {
	// contains filtered or unexported fields
}

OpenCLLib holds dlopen handles and resolved function pointers for OpenCL runtime functions. All function pointers are resolved at Open() time via dlsym. Calls go through the platform-specific ccall from the cuda package (which is a general-purpose zero-CGo C function caller, not CUDA-specific).

func Lib

func Lib() *OpenCLLib

Lib returns the global OpenCLLib instance, or nil if OpenCL is not available.

func Open

func Open() (*OpenCLLib, error)

Open loads libOpenCL via dlopen and resolves all OpenCL runtime function pointers via dlsym. Returns an error if OpenCL is not available (library not found or symbols missing).

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream wraps an OpenCL command queue.

func (*Stream) Destroy

func (s *Stream) Destroy() error

Destroy releases the command queue.

func (*Stream) Ptr

func (s *Stream) Ptr() unsafe.Pointer

Ptr returns the underlying command queue handle as unsafe.Pointer.

func (*Stream) Synchronize

func (s *Stream) Synchronize() error

Synchronize waits for all commands in the command queue to complete.

Directories

Path Synopsis
Package kernels provides OpenCL kernel source and dispatch for elementwise operations.
Package kernels provides OpenCL kernel source and dispatch for elementwise operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL