opencl

package module
v0.0.0-...-b002893 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: MIT Imports: 7 Imported by: 0

README

go-opencl

Very minimalist OpenCL bindings in pure go, doesn't need CGo thanks to https://github.com/ebitengine/purego.

There's not much at the moment, it's experimental, only tested on Windows, and made around my own usage so far

Documentation

Index

Constants

View Source
const (
	CL_SUCCESS = 0
)
View Source
const (
	MemInfoSize memInfo = 0x1102
)

Variables

This section is empty.

Functions

func Initialize

func Initialize() error

func InitializeGLSharing

func InitializeGLSharing() error

Types

type Buffer

type Buffer uint

func (Buffer) GetGLObjectInfo

func (b Buffer) GetGLObjectInfo() (CLGLObjectType, error)

func (Buffer) GetGLTextureInfo

func (b Buffer) GetGLTextureInfo(info CLGLTextureInfo) (uint32, error)

func (Buffer) Release

func (b Buffer) Release() error

func (Buffer) Size

func (b Buffer) Size() (uint, error)

type BufferData

type BufferData struct {
	TypeSize uintptr
	DataSize uintptr
	Pointer  unsafe.Pointer
}

func GetBufferData

func GetBufferData[T BufferType](data []T) *BufferData

type BufferType

type BufferType interface {
	~float32 | ~float64 | ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type CLGLObjectType

type CLGLObjectType uint32
const (
	CLGLObjectBuffer       CLGLObjectType = 0x2000
	CLGLObjectTexture2D    CLGLObjectType = 0x2001
	CLGLObjectTexture3D    CLGLObjectType = 0x2002
	CLGLObjectRenderBuffer CLGLObjectType = 0x2003
	// ...
	CLGLObjectTextureBuffer CLGLObjectType = 0x2011
)

type CLGLTextureInfo

type CLGLTextureInfo uint32
const (
	CLGLTextureTarget      CLGLTextureInfo = 0x2004
	CLGLTextureMipmapLevel CLGLTextureInfo = 0x2005
)

type CommandQueue

type CommandQueue uint

func (CommandQueue) EnqueueAcquireGLObjects

func (cq CommandQueue) EnqueueAcquireGLObjects(objects []Buffer) error

func (CommandQueue) EnqueueBarrier

func (cq CommandQueue) EnqueueBarrier() error

func (CommandQueue) EnqueueMapBuffer

func (cq CommandQueue) EnqueueMapBuffer(buffer Buffer, blockingMap bool, flags []MapFlag, data *BufferData) error

func (CommandQueue) EnqueueMapImage

func (cq CommandQueue) EnqueueMapImage(image Buffer, blockingMap bool, flags []MapFlag, data *ImageData) error

func (CommandQueue) EnqueueNDRangeKernel

func (cq CommandQueue) EnqueueNDRangeKernel(kernel Kernel, workDim uint, globalOffsets, globalWorkSizes, localWorkSizes []uint64) error

func (CommandQueue) EnqueueReadBuffer

func (cq CommandQueue) EnqueueReadBuffer(buffer Buffer, blockingRead bool, data *BufferData) error

func (CommandQueue) EnqueueReadImage

func (cq CommandQueue) EnqueueReadImage(image Buffer, blockingRead bool, data *ImageData) error

func (CommandQueue) EnqueueReleaseGLObjects

func (cq CommandQueue) EnqueueReleaseGLObjects(objects []Buffer) error

func (CommandQueue) EnqueueUnmapBuffer

func (cq CommandQueue) EnqueueUnmapBuffer(buffer Buffer, data *BufferData) error

func (CommandQueue) EnqueueWriteBuffer

func (cq CommandQueue) EnqueueWriteBuffer(buffer Buffer, blockingWrite bool, data *BufferData) error

func (CommandQueue) Finish

func (cq CommandQueue) Finish() error

func (CommandQueue) Flush

func (cq CommandQueue) Flush() error

func (CommandQueue) Release

func (cq CommandQueue) Release() error

type CommandQueueProperty

type CommandQueueProperty uint32
const (
	CommandQueueOutOfOrderExecModeEnable CommandQueueProperty = (1 << 0)
	CommandQueueProfilingEnable          CommandQueueProperty = (1 << 1)
	CommandQueueOnDevice                 CommandQueueProperty = (1 << 2)
	CommandQueueOnDeviceDefault          CommandQueueProperty = (1 << 3)
)

type Context

type Context uint

func (Context) CreateBuffer

func (c Context) CreateBuffer(flags []MemFlag, size uint) (Buffer, error)

func (Context) CreateCommandQueue

func (c Context) CreateCommandQueue(device Device) (CommandQueue, error)

func (Context) CreateCommandQueueWithProperties

func (c Context) CreateCommandQueueWithProperties(device Device, properties []CommandQueueProperty) (CommandQueue, error)

func (Context) CreateFromGLTexture

func (c Context) CreateFromGLTexture(flags []MemFlag, target GLEnum, texture GLUint) (Buffer, error)

func (Context) CreateImage2D

func (c Context) CreateImage2D(flags []MemFlag, format ImageFormat, width, height int) (Buffer, error)

func (Context) CreateProgram

func (c Context) CreateProgram(source string) (Program, error)

func (Context) Release

func (c Context) Release() error

type ContextProperties

type ContextProperties struct {
	Platform *Platform
	// Interop
	InteropUserSync *bool
	// OpenGL
	GLContextKHR *uint
	// Windows
	WGL_HDC_KHR *uint
}

type Device

type Device uint

func (Device) CreateContext

func (d Device) CreateContext(properties *ContextProperties) (Context, error)

func (Device) GetExtensions

func (d Device) GetExtensions() ([]Extension, error)

type DeviceType

type DeviceType uint32
const (
	DeviceTypeDefault     DeviceType = 1 << 0
	DeviceTypeCPU         DeviceType = 1 << 1
	DeviceTypeGPU         DeviceType = 1 << 2
	DeviceTypeAccelerator DeviceType = 1 << 3
	DeviceTypeCustom      DeviceType = 1 << 4
	DeviceTypeAll         DeviceType = 0xFFFFFFFF
)

type Event

type Event uint

type Extension

type Extension = string
const (
	// OpenCL
	Extension_khr_gl_sharing Extension = "cl_khr_gl_sharing"
	Extension_khr_fp64       Extension = "cl_khr_fp64"
	// Nvidia
	Extension_nv_pragma_unroll    Extension = "cl_nv_pragma_unroll"
	Extension_nv_compiler_options Extension = "cl_nv_compiler_options"
)

TODO: Not exhaustive

type GLEnum

type GLEnum uint32
const (
	GLTextureTarget2D GLEnum = 0x0DE1
)

type GLInt

type GLInt int32

type GLUint

type GLUint uint32

type ImageChannelOrder

type ImageChannelOrder uint32
const (
	ImageChannelOrder_R         ImageChannelOrder = 0x10B0
	ImageChannelOrder_A         ImageChannelOrder = 0x10B1
	ImageChannelOrder_RG        ImageChannelOrder = 0x10B2
	ImageChannelOrder_RA        ImageChannelOrder = 0x10B3
	ImageChannelOrder_RGB       ImageChannelOrder = 0x10B4
	ImageChannelOrder_RGBA      ImageChannelOrder = 0x10B5
	ImageChannelOrder_BGRA      ImageChannelOrder = 0x10B6
	ImageChannelOrder_ARGB      ImageChannelOrder = 0x10B7
	ImageChannelOrder_Intensity ImageChannelOrder = 0x10B8
	ImageChannelOrder_Luminance ImageChannelOrder = 0x10B9
)

type ImageChannelType

type ImageChannelType uint32
const (
	ImageChannelType_SNormInt8      ImageChannelType = 0x10D0
	ImageChannelType_SNormInt16     ImageChannelType = 0x10D1
	ImageChannelType_UNormInt8      ImageChannelType = 0x10D2
	ImageChannelType_UNormInt16     ImageChannelType = 0x10D3
	ImageChannelType_UNormShort565  ImageChannelType = 0x10D4
	ImageChannelType_UNormShort555  ImageChannelType = 0x10D5
	ImageChannelType_UNormInt101010 ImageChannelType = 0x10D6
	ImageChannelType_SignedInt8     ImageChannelType = 0x10D7
	ImageChannelType_SignedInt16    ImageChannelType = 0x10D8
	ImageChannelType_SignedInt32    ImageChannelType = 0x10D9
	ImageChannelType_UnsignedInt8   ImageChannelType = 0x10DA
	ImageChannelType_UnsignedInt16  ImageChannelType = 0x10DB
	ImageChannelType_UnsignedInt32  ImageChannelType = 0x10DC
	ImageChannelType_HalfFloat      ImageChannelType = 0x10DD
	ImageChannelType_Float          ImageChannelType = 0x10DE
	// CL_VERSION 2.1
	ImageChannelType_UNormInt101010_2 ImageChannelType = 0x10E0
)

type ImageData

type ImageData struct {
	*BufferData
	Origin     [3]uint
	Region     [3]uint
	RowPitch   uint
	SlicePitch uint
}

func GetImageBufferData

func GetImageBufferData(img image.RGBA) *ImageData

type ImageFormat

type ImageFormat struct {
	ChannelOrder ImageChannelOrder
	ChannelType  ImageChannelType
}

type Kernel

type Kernel uint

func (Kernel) Release

func (k Kernel) Release() error

func (Kernel) SetArg

func (k Kernel) SetArg(index uint, arg KernelArg) error

type KernelArg

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

func NewKernelArg

func NewKernelArg[T any](arg *T) KernelArg

type MapFlag

type MapFlag uint32
const (
	MapFlagRead                  MapFlag = (1 << 0)
	MapFlagWrite                 MapFlag = (1 << 1)
	MapFlagWriteInvalidateRegion MapFlag = (1 << 2)
)

type MemFlag

type MemFlag uint32
const (
	MemFlagsReadWrite    MemFlag = 1 << 0
	MemFlagsWriteOnly    MemFlag = 1 << 1
	MemFlagsReadOnly     MemFlag = 1 << 2
	MemFlagsUseHostPtr   MemFlag = 1 << 3
	MemFlagsAllocHostPtr MemFlag = 1 << 4
	MemFlagsCopyHostPtr  MemFlag = 1 << 5
	// reserved
	MemFlagsHostWriteOnly MemFlag = 1 << 7
	MemFlagsHostReadOnly  MemFlag = 1 << 8
	MemFlagsHostNoAccess  MemFlag = 1 << 9
)

type Platform

type Platform uint

func GetPlatforms

func GetPlatforms() ([]Platform, error)

func (Platform) GetDevices

func (p Platform) GetDevices(deviceType DeviceType) ([]Device, error)

func (Platform) GetExtensions

func (p Platform) GetExtensions() ([]Extension, error)

func (Platform) GetName

func (p Platform) GetName() (string, error)

func (Platform) GetProfile

func (p Platform) GetProfile() (string, error)

func (Platform) GetVendor

func (p Platform) GetVendor() (string, error)

func (Platform) GetVersion

func (p Platform) GetVersion() (string, error)

type Program

type Program uint

func (Program) Build

func (p Program) Build(device Device, opts *ProgramBuildOptions) (string, error)

func (Program) CreateKernel

func (p Program) CreateKernel(name string) (Kernel, error)

func (Program) Release

func (p Program) Release() error

type ProgramBuildOptions

type ProgramBuildOptions struct {
	// Preprocessor options
	Warnings          bool
	Macros            map[string]string
	DirectoryIncludes []string
	Version           Version
	// Math intrinsics options
	SinglePrecisionConstant bool
	MadEnable               bool
	NoSignedZeros           bool
	FastRelaxedMaths        bool
	// Extensions
	NvidiaVerbose bool
}

func (*ProgramBuildOptions) String

func (po *ProgramBuildOptions) String() string

type Version

type Version string
const (
	Version1_0 Version = "CL1.0"
	Version1_1 Version = "CL1.1"
	Version1_2 Version = "CL1.2"
	Version2_0 Version = "CL2.0"
	Version3_0 Version = "CL3.0"
)

Jump to

Keyboard shortcuts

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