pureCL

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

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

Go to latest
Published: Feb 26, 2025 License: MIT Imports: 7 Imported by: 2

README

pure

This is fork and simplify of Zyko0's opencl, big thank.
This package provide low level wrapper to OpenCL, that means it is 1:1 wrapper C:GO - no GO error handling only GO types map OpenCL function and cl_types without cgo, powered by purego and inspired by libopencl-stub. This package use constantsCL
Thank to both of them!

goal

  • low level wrap of OpenCL for
  • be minimalistic
  • try to have all functions of OpenCL (so if you have some, give PR)
  • easy to multiplatform (thank purego)
  • easy find path (custumize path to openclLib shared library)
  • easy to compile, we do not need cgo and not need knowing link to shared library
  • try purego and bring opencl on android without complicate link

not goal

  • be faster as cgo version, purego is using same mechanism as cgo

examples

you can also use to your package independent from others ..., you can also use as this:

example

package main

import (
	"errors"
	constants "github.com/opencl-pure/constantsCL"
	pure "github.com/opencl-pure/pureCL"
	"log"
)

func main() {
  //init with version of OpenCL and variadic special paths (if you know)
	err := pure.Init(pure.Version2_0/*, "special_path1/openclLib.dll", "special_path1/openclLib.so" */) 
	if err != nil {
		log.Println(err)
		return
	}
	numPlatforms := uint32(0)
	st := pure.GetPlatformIDs(0, nil, &numPlatforms)
	if st != constants.CL_SUCCESS {
		log.Println(errors.New("oops platform error"))
		return
	}

	platformIDs := make([]pure.Platform, numPlatforms)
	st = pure.GetPlatformIDs(numPlatforms, platformIDs, nil)
	if st != constants.CL_SUCCESS {
		log.Println(errors.New("oops none ...."))
		return
	}
	// ....
}    

Documentation

Index

Constants

View Source
const (
	ErrDeviceNotFound                     = "cl: Device Not Found"
	ErrDeviceNotAvailable                 = "cl: Device Not Available"
	ErrCompilerNotAvailable               = "cl: Compiler Not Available"
	ErrMemObjectAllocationFailure         = "cl: Mem Object Allocation Failure"
	ErrOutOfResources                     = "cl: Out Of Resources"
	ErrOutOfHostMemory                    = "cl: Out Of Host Memory"
	ErrProfilingInfoNotAvailable          = "cl: Profiling Info Not Available"
	ErrMemCopyOverlap                     = "cl: Mem Copy Overlap"
	ErrImageFormatMismatch                = "cl: Image Format Mismatch"
	ErrImageFormatNotSupported            = "cl: Image Format Not Supported"
	ErrBuildProgramFailure                = "cl: Build Program Failure"
	ErrMapFailure                         = "cl: Map Failure"
	ErrMisalignedSubBufferOffset          = "cl: Misaligned Sub clBuffer Offset"
	ErrExecStatusErrorForEventsInWaitList = "cl: Exec Status Error For Events In Wait List"
	ErrCompileProgramFailure              = "cl: Compile Program Failure"
	ErrLinkerNotAvailable                 = "cl: Linker Not Available"
	ErrLinkProgramFailure                 = "cl: Link Program Failure"
	ErrDevicePartitionFailed              = "cl: Device Partition Failed"
	ErrKernelArgInfoNotAvailable          = "cl: Kernel Arg Info Not Available"
	ErrInvalidValue                       = "cl: Invalid Value"
	ErrInvalidDeviceType                  = "cl: Invalid Device Type"
	ErrInvalidPlatform                    = "cl: Invalid Platform"
	ErrInvalidDevice                      = "cl: Invalid Device"
	ErrInvalidContext                     = "cl: Invalid clContext"
	ErrInvalidQueueProperties             = "cl: Invalid Queue Properties"
	ErrInvalidCommandQueue                = "cl: Invalid Command Queue"
	ErrInvalidHostPtr                     = "cl: Invalid Host Ptr"
	ErrInvalidMemObject                   = "cl: Invalid Mem Object"
	ErrInvalidImageFormatDescriptor       = "cl: Invalid Image Format Descriptor"
	ErrInvalidImageSize                   = "cl: Invalid Image Size"
	ErrInvalidSampler                     = "cl: Invalid Sampler"
	ErrInvalidBinary                      = "cl: Invalid Binary"
	ErrInvalidBuildOptions                = "cl: Invalid Build Options"
	ErrInvalidProgram                     = "cl: Invalid Program"
	ErrInvalidProgramExecutable           = "cl: Invalid Program Executable"
	ErrInvalidKernelName                  = "cl: Invalid Kernel Name"
	ErrInvalidKernelDefinition            = "cl: Invalid Kernel Definition"
	ErrInvalidKernel                      = "cl: Invalid Kernel"
	ErrInvalidArgIndex                    = "cl: Invalid Arg Index"
	ErrInvalidArgValue                    = "cl: Invalid Arg Value"
	ErrInvalidArgSize                     = "cl: Invalid Arg Size"
	ErrInvalidKernelArgs                  = "cl: Invalid Kernel Args"
	ErrInvalidWorkDimension               = "cl: Invalid Work Dimension"
	ErrInvalidWorkGroupSize               = "cl: Invalid Work Group Size"
	ErrInvalidWorkItemSize                = "cl: Invalid Work Item Size"
	ErrInvalidGlobalOffset                = "cl: Invalid Global Offset"
	ErrInvalidEventWaitList               = "cl: Invalid Event Wait List"
	ErrInvalidEvent                       = "cl: Invalid Event"
	ErrInvalidOperation                   = "cl: Invalid Operation"
	ErrInvalidGlObject                    = "cl: Invalid Gl Object"
	ErrInvalidBufferSize                  = "cl: Invalid clBuffer Size"
	ErrInvalidMipLevel                    = "cl: Invalid Mip Level"
	ErrInvalidGlobalWorkSize              = "cl: Invalid Global Work Size"
	ErrInvalidProperty                    = "cl: Invalid Property"
	ErrInvalidImageDescriptor             = "cl: Invalid Image Descriptor"
	ErrInvalidCompilerOptions             = "cl: Invalid Compiler Options"
	ErrInvalidLinkerOptions               = "cl: Invalid Linker Options"
	ErrInvalidDevicePartitionCount        = "cl: Invalid Device Partition Count"
)

Common OpenCl errors

View Source
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"

	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"
)

TODO: Not exhaustive

Variables

View Source
var (
	// GetPlatformIDs this wrap opencl clGetPlatformIDs and do returns a list of available OpenCL platforms
	GetPlatformIDs func(numEntries uint32, platforms []Platform, numPlatforms *uint32) Status = nil
	// GetPlatformInfo this wrap opencl clGetPlatformInfo and do queries information about a specific platform
	GetPlatformInfo func(platform Platform, platformInfo PlatformInfo, paramValueSize Size, paramValue []byte, paramValueSizeRet *Size) Status = nil

	// GetDeviceIDs this wrap opencl clGetDeviceIDs and do returns a list of available OpenCL devices
	GetDeviceIDs func(platform Platform, deviceType DeviceType, numEntries uint32, devices []Device, numDevices *uint32) Status = nil
	// GetDeviceInfo this wrap opencl clGetDeviceInfo and do queries information about a specific device
	GetDeviceInfo func(device Device, deviceInfo DeviceInfo, paramValueSize Size, paramValue []byte, paramValueSizeRet *Size) Status = nil
	// ReleaseDevice this wrap opencl clReleaseDevice and do releases the OpenCL device
	ReleaseDevice func(id Device) Status = nil

	// ReleaseEvent this wrap opencl clReleaseEvent and do releases an OpenCL event
	ReleaseEvent func(event Event) Status = nil
	// WaitForEvents this wrap opencl clWaitForEvents and do waits on the host thread for commands identified by num_events to complete
	WaitForEvents func(numEvents uint32, eventList []Event) Status = nil

	// CreateContext this wrap opencl clCreateContext and do creates an OpenCL context
	CreateContext func(properties unsafe.Pointer, numDevices uint32, devices []Device, pfnNotify *CreateContextNotifyFuncType, userData []byte, errCodeRet *Status) Context = nil
	// ReleaseContext this wrap opencl clReleaseContext and do releases the OpenCL context
	ReleaseContext func(ctx Context) Status = nil
	// CreateProgramWithSource this wrap opencl clCreateProgramWithSource and do creates a program object for a context
	CreateProgramWithSource func(ctx Context, count Size, strings []string, lengths []Size, errCodeRet *Status) Program = nil
	// CreateBuffer this wrap opencl clCreateBuffer and do creates a buffer object
	CreateBuffer func(ctx Context, memFlags MemFlag, size Size, hostPtr unsafe.Pointer, errCodeRet *Status) Buffer = nil
	// CreateImage this wrap opencl clCreateImage and do creates a image object
	CreateImage func(ctx Context, memFlags MemFlag, imageFormat *ImageFormat, desc *ImageDesc, hostPtr unsafe.Pointer, errCodeRet *Status) Buffer = nil
	// CreateImage2D this wrap opencl clCreateImage2D and do creates a 2D image object
	CreateImage2D func(ctx Context, memFlags MemFlag, imageFormat *ImageFormat, imageWidth, imageHeight, imageRowPitch Size, hostPtr unsafe.Pointer, errCodeRet *Status) Buffer = nil
	// CreateImage3D this wrap opencl clCreateImage3D and do creates a 3D image object
	CreateImage3D func(ctx Context, memFlags MemFlag, imageFormat *ImageFormat, imageWidth, imageHeight, imageDepth, imageRowPitch, imageSlicePitch Size, hostPtr unsafe.Pointer, errCodeRet *Status) Buffer = nil

	// CreateCommandQueue this wrap opencl clCreateCommandQueue and do creates a command-queue on a specific device
	CreateCommandQueue func(context Context, device Device, properties CommandQueueProperty, errCodeRet *Status) CommandQueue = nil
	// CreateCommandQueueWithProperties this wrap opencl clCreateCommandQueueWithProperties and do creates a command-queue on a specific device with specified properties
	CreateCommandQueueWithProperties func(context Context, device Device, properties CommandQueueProperty, errCodeRet *Status) CommandQueue = nil
	// EnqueueBarrier this wrap opencl clEnqueueBarrier and do inserts a barrier command
	EnqueueBarrier func(queue CommandQueue) Status = nil
	// EnqueueNDRangeKernel this wrap opencl clEnqueueNDRangeKernel and do enqueue a kernel to execute on a device
	EnqueueNDRangeKernel func(queue CommandQueue, kernel Kernel, workDim uint, globalWorkOffset, globalWorkSize, localWorkSize []Size, numEventsWaitList uint, eventWaitList []Event, event *Event) Status = nil
	// EnqueueReadBuffer this wrap opencl clEnqueueReadBuffer and do enqueue a command to read from a buffer object to host memory
	EnqueueReadBuffer func(queue CommandQueue, buffer Buffer, blockingRead bool, offset, cb Size, ptr unsafe.Pointer, numEventsWaitList uint, eventWaitList []Event, event *Event) Status = nil
	// EnqueueReadImage this wrap opencl clEnqueueReadImage and do enqueue a command to read from a 2D or 3D image object to host memory
	EnqueueReadImage func(queue CommandQueue, image Buffer, blockingRead bool, origin, region [3]Size, row_pitch, slice_pitch Size, ptr unsafe.Pointer, numEventsWaitList uint, eventWaitList []Event, event *Event) Status = nil
	// EnqueueWriteImage this wrap opencl clEnqueueWriteImage and do enqueue a command to write from host memory to a 2D or 3D image object
	EnqueueWriteImage func(queue CommandQueue, image Buffer, blockingRead bool, origin, region [3]Size, row_pitch, slice_pitch Size, ptr unsafe.Pointer, numEventsWaitList uint, eventWaitList []Event, event *Event) Status = nil
	// EnqueueWriteBuffer this wrap opencl clEnqueueWriteBuffer and do enqueue a command to write to a buffer object from host memory
	EnqueueWriteBuffer func(queue CommandQueue, buffer Buffer, blockingWrite bool, offset, cb Size, ptr unsafe.Pointer, numEventsWaitList uint, eventWaitList []Event, event *Event) Status = nil
	// EnqueueMapBuffer this wrap opencl clEnqueueMapBuffer and do enqueue a command to map a buffer object into the host address space
	EnqueueMapBuffer func(queue CommandQueue, buffer Buffer, blockingMap bool, mapFlags MapFlag, offset, size Size, numEventsWaitList uint, eventWaitList []Event, event *Event, errCodeRet *Status) uintptr = nil
	// EnqueueUnmapMemObject this wrap opencl clEnqueueUnmapMemObject and do enqueue a command to unmap a previously mapped buffer object
	EnqueueUnmapMemObject func(queue CommandQueue, buffer Buffer, mappedPtr unsafe.Pointer, numEventsWaitList uint, eventWaitList []Event, event *Event) Status = nil
	// EnqueueMapImage this wrap opencl clEnqueueMapImage and do enqueue a command to map a 2D or 3D image object into the host address space
	EnqueueMapImage func(queue CommandQueue, image Buffer, blockingMap bool, mapFlags MapFlag, origin, region [3]Size, imageRowPitch, imageSlicePitch *Size, numEventsWaitList uint, eventWaitList []Event, event *Event, errCodeRet *Status) uintptr = nil
	// FinishCommandQueue this wrap opencl clFinish and do issues all previously queued OpenCL commands in a command-queue to the device
	FinishCommandQueue func(queue CommandQueue) Status = nil
	// FlushCommandQueue this wrap opencl clFlush and do ensures that all previously queued OpenCL commands in a command-queue are submitted to the device
	FlushCommandQueue func(queue CommandQueue) Status = nil
	// ReleaseCommandQueue this wrap opencl clReleaseCommandQueue and do releases a kernel object
	ReleaseCommandQueue func(queue CommandQueue) Status = nil

	// BuildProgram this wrap opencl clBuildProgram and do builds (compiles & links) a program executable from the program source or binary
	BuildProgram func(program Program, numDevices uint32, devices []Device, options []byte, pfnNotify *BuildProgramNotifyFuncType, userData []byte) Status = nil
	// GetProgramBuildInfo this wrap opencl clGetProgramBuildInfo and do returns build information for each device in the program object
	GetProgramBuildInfo func(program Program, device Device, info ProgramBuildInfo, paramSize Size, paramValue unsafe.Pointer, paramSizeRet *Size) Status = nil
	// CreateKernel this wrap opencl clCreateKernel and do creates a kernel object
	CreateKernel func(program Program, kernelName string, errCodeRet *Status) Kernel = nil
	// ReleaseProgram this wrap opencl clReleaseProgram and do releases the OpenCL program object
	ReleaseProgram func(program Program) Status = nil
	// GetProgramInfo this wrap opencl clGetProgramInfo and do queries information about a program object
	GetProgramInfo func(program Program, info ProgramBuildInfo, size Size, pointer unsafe.Pointer, t *Size) Status = nil

	// SetKernelArg this wrap opencl clSetKernelArg and do sets the argument value for a specific argument of a kernel
	SetKernelArg func(kernel Kernel, argIndex uint32, argSize Size, argValue unsafe.Pointer) Status = nil
	// ReleaseKernel this wrap opencl clReleaseKernel and do releases a kernel object
	ReleaseKernel func(kernel Kernel) Status = nil

	// GetMemObjectInfo this wrap opencl clGetMemObjectInfo and do queries information about a memory object
	GetMemObjectInfo func(buffer Buffer, memInfo MemInfo, paramValueSize Size, paramValue unsafe.Pointer, paramValueSizeRet *Size) Status = nil
	// ReleaseMemObject this wrap opencl clReleaseMemObject and do releases an OpenCL memory object
	ReleaseMemObject func(buffer Buffer) Status = nil

	// CreateFromGLTexture this wrap opencl clCreateFromGLTexture and do creates a 2D image object from an OpenGL texture object
	CreateFromGLTexture func(ctx Context, memFlags MemFlag, textureTarget GLEnum, mipLevel GLInt, texture GLUint, errCodeRet *Status) Buffer = nil
	// GetGLObjectInfo this wrap opencl clGetGLObjectInfo and do returns information about the OpenCL memory object and OpenGL object
	GetGLObjectInfo func(memObj Buffer, objectType *CLGLObjectType, objectName *GLUint) Status = nil
	// GetGLTextureInfo this wrap opencl clGetGLTextureInfo and do returns information about the OpenGL texture object associated with a memory object
	GetGLTextureInfo func(memObj Buffer, paramName CLGLTextureInfo, paramValueSize Size, paramValue unsafe.Pointer, paramValueSizeRet *Size) Status = nil
	// EnqueueAcquireGLObjects this wrap opencl clEnqueueAcquireGLObjects and do enqueue commands to acquire OpenCL memory objects that have been created from OpenGL objects
	EnqueueAcquireGLObjects func(queue CommandQueue, numObjects uint32, memObjects unsafe.Pointer, numEventsInWaitList uint32, eventWaitList []Event, event *Event) Status = nil
	// EnqueueReleaseGLObjects this wrap opencl clEnqueueReleaseGLObjects and do enqueue commands to release OpenCL memory objects that have been created from OpenGL objects
	EnqueueReleaseGLObjects func(queue CommandQueue, numObjects uint32, memObjects unsafe.Pointer, numEventsInWaitList uint32, eventWaitList []Event, event *Event) Status = nil
)

functions

Functions

func ErrJoin

func ErrJoin(e1, e2 error) error

func Init

func Init(version Version, paths ...string) error

func InitializeGLSharing

func InitializeGLSharing(paths ...string) error

func SetHandle

func SetHandle(handleExternal uintptr)

func StatusToErr

func StatusToErr(code Status) error

func Uninitialized

func Uninitialized(name string) error

Types

type Buffer

type Buffer uint

type BufferData

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

func GetBufferData

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

type BufferRect

type BufferRect struct {
	Origin [3]Size
	Region [3]Size
}

type BufferType

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

type BuildProgramNotifyFuncType

type BuildProgramNotifyFuncType func(program Program, userData []byte)

type CLGLObjectType

type CLGLObjectType uint32

type CLGLTextureInfo

type CLGLTextureInfo uint32

type CommandQueue

type CommandQueue uint

type CommandQueueProperties

type CommandQueueProperties uint32

type CommandQueueProperty

type CommandQueueProperty uint32

type Context

type Context uint

type ContextProperties

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

type ContextProperty

type ContextProperty uint

type CreateContextNotifyFuncType

type CreateContextNotifyFuncType func(errinfo, privateInfo []byte, cb Size, userData []byte)

notify function types

type Device

type Device uint

type DeviceAffinityDomain

type DeviceAffinityDomain uint64

type DeviceInfo

type DeviceInfo uint32

type DevicePartition

type DevicePartition struct {
	Properties     []DevicePartitionProperty
	AffinityDomain DeviceAffinityDomain
}

type DevicePartitionProperty

type DevicePartitionProperty struct {
	Type  uint32
	Flags uint32
}

type DeviceType

type DeviceType uint32

type Event

type Event uint

type EventCommandExecStatus

type EventCommandExecStatus uint32

type EventInfo

type EventInfo uint32

type Extension

type Extension = string

type GLEnum

type GLEnum uint32

GL

type GLInt

type GLInt int32

type GLUint

type GLUint uint32

type ImageChannelOrder

type ImageChannelOrder uint32

type ImageChannelType

type ImageChannelType uint32

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 ImageDesc

type ImageDesc struct {
	Type        MemObjectType
	Width       Size
	Height      Size
	Depth       Size
	ArraySize   Size
	RowPitch    Size
	SlisePitch  Size
	Buffer      Buffer
	NumMipLevel uint32
	NumSamples  uint32
}

func CreateImageDesc

func CreateImageDesc(imageType MemObjectType,
	imageWidth, imageHeight, imageDepth, imageArraySize, imageRowPitch, imageSlicePitch Size,
	numMipLevels, numSamples uint32,
	buffer Buffer) *ImageDesc

type ImageFormat

type ImageFormat struct {
	ChannelOrder ImageChannelOrder
	ChannelType  ImageChannelType
}

type ImageInfo

type ImageInfo uint32

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
}

structs

func NewKernelArg

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

type KernelWorkGroupInfo

type KernelWorkGroupInfo uint32

type MapFlag

type MapFlag uint32

type MapPointer

type MapPointer unsafe.Pointer

type MemFlag

type MemFlag uint32

type MemInfo

type MemInfo uint32

type MemObjectType

type MemObjectType uint32

type PipeProperties

type PipeProperties uint32

untested and unintergrateed

type Platform

type Platform uint

type PlatformInfo

type PlatformInfo uint

type Program

type Program uint

type ProgramBuildInfo

type ProgramBuildInfo uint32

type Sampler

type Sampler uint

type Size

type Size uint

primitive types

type Status

type Status int32

type Version

type Version string

Jump to

Keyboard shortcuts

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