device

package
v0.0.0-...-e791307 Latest Latest
Warning

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

Go to latest
Published: May 18, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CpuDevice   DeviceType = 1 << iota
	GpuDevice              = 1 << iota
	OtherDevice            = 1 << iota
	AllDevices             = 0xFF
)

Supported device types.

Variables

This section is empty.

Functions

func ErrorName

func ErrorName(errCode cl.ErrorCode) string

Return a textual description of an opencl error code.

func NewSharedContext

func NewSharedContext(devices []*Device) (*cl.Context, error)

Create a shared opencl context for the given device list.

Types

type Buffer

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

func (*Buffer) Allocate

func (b *Buffer) Allocate(size int, flags cl.MemFlags) error

Allocate a buffer with the given size and flags.

func (*Buffer) AllocateAndWriteData

func (b *Buffer) AllocateAndWriteData(data interface{}, flags cl.MemFlags) error

Allocate a buffer with the given flags that is large enough to hold the given data and have opencl copy the data from the host pointer. The behavior of this method is undefined if a non-slice argument is passed or the argument does not use contiguous memory.

func (*Buffer) AllocateToFitData

func (b *Buffer) AllocateToFitData(data interface{}, flags cl.MemFlags) error

Allocate a buffer with enough capacity to fit the given data.

func (*Buffer) CopyDataFrom

func (b *Buffer) CopyDataFrom(src *Buffer, srcOffset, dstOffset, size int) error

Copy data from the given buffer into this buffer.

func (*Buffer) Handle

func (b *Buffer) Handle() cl.Mem

Get opencl buffer handle.

func (*Buffer) ReadData

func (b *Buffer) ReadData(srcOffset, dstOffset, size int, hostBuffer interface{}) error

Read data from device buffer into the supplied host buffer. The behavior of this method is undefined if a non-slice argument is passed or if the argument does not use contiguous memory.

If size is <= 0 then ReadData will read the entire bufer. Both src and dst offsets are specified in bytes.

func (*Buffer) ReadDataIntoSlice

func (b *Buffer) ReadDataIntoSlice(sliceType interface{}) (interface{}, error)

Read all data from device buffer into a slice of the given type. This method will allocate a new slice with enough capacity to fit the buffer data and will panic if the buffer size is not a multiple of the slice element size.

func (*Buffer) Release

func (b *Buffer) Release()

Release buffer.

func (*Buffer) Size

func (b *Buffer) Size() int

Get buffer size.

func (*Buffer) WriteData

func (b *Buffer) WriteData(data interface{}, offset int) error

Write data to the device buffer. The behavior of this method is undefined if a non-slice argument is passed or the argument does not use contiguous memory. A byte offset may also be specified to adjust the actual data copied.

type Device

type Device struct {
	Name string
	Id   cl.DeviceId
	Type DeviceType

	// Speed estimate in GFlops.
	Speed uint32
	// contains filtered or unexported fields
}

Wrapper around opencl-supported devices.

func SelectDevices

func SelectDevices(typeMask DeviceType, matchName string) ([]*Device, error)

Scan all available opencl platforms and select devices that match the given query.

func (*Device) Buffer

func (d *Device) Buffer(name string) *Buffer

Create an empty buffer.

func (*Device) Close

func (d *Device) Close()

Shut down the device.

func (*Device) Init

func (d *Device) Init(programFile string, ctx *cl.Context) error

Initialize device.

func (*Device) Kernel

func (d *Device) Kernel(name string) (*Kernel, error)

Load kernel by name.

func (Device) String

func (d Device) String() string

Implements Stringer.

func (*Device) WaitForKernels

func (d *Device) WaitForKernels() error

Wait for the any queued kernel executiont to compete.

type DeviceList

type DeviceList []Device

A list of devices.

type DeviceType

type DeviceType uint8

func (DeviceType) String

func (dt DeviceType) String() string

type Kernel

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

A wrapper around opencl kernelHandles.

func (*Kernel) Exec1D

func (k *Kernel) Exec1D(offset, globalWorkSize, localWorkSize int) (time.Duration, error)

Execute 1D kernel. If localWorSize is equal to 0 then the opencl implementation will pick the optimal worksize split for the underlying hardware.

func (*Kernel) Exec1DNoWait

func (k *Kernel) Exec1DNoWait(offset, globalWorkSize, localWorkSize int) (time.Duration, error)

Execute 1D kernel. If localWorSize is equal to 0 then the opencl implementation will pick the optimal worksize split for the underlying hardware. This method will not wait for the kernel to finish. The client must manually invoke WaitForKernels() on the target device.

func (*Kernel) Exec2D

func (k *Kernel) Exec2D(offsetX, offsetY, globalWorkSizeX, globalWorkSizeY, localWorkSizeX, localWorkSizeY int) (time.Duration, error)

Execute 2D kernel. If both localWorkSizeX and localWorkSizeY are 0 then the opencl implementation will pick the optimal local worksize split for the underlying hardware.

func (*Kernel) Release

func (k *Kernel) Release()

Free any allocated resources used by this kernel.

func (*Kernel) SetArgs

func (k *Kernel) SetArgs(args ...interface{}) error

Bind arguments to kernelHandle.

type PlatformInfo

type PlatformInfo struct {
	Profile    string
	Version    string
	Name       string
	Vendor     string
	Extensions string
	Devices    []*Device
}

Information about a system's opencl platform and supported devices.

func GetPlatformInfo

func GetPlatformInfo() ([]PlatformInfo, error)

Get information about supported opencl platforms and devices.

func (PlatformInfo) String

func (pl PlatformInfo) String() string

Jump to

Keyboard shortcuts

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