highCL

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

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

highCL

This is fork of blackcl, I believe that is not about black magic,
This package provide high level wrapper to OpenCL, that means it is completly hiding call of OpenCL. This package use pureCL to call OpenCL WITHOUT CGO!!! And it is continue of middleCL
Absence cgo means you do not need c compiler, it is powered by. purego and inspired by libopencl-stub and Zyko0's opencl. Thank to all of them!

goal

  • 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
  • be high level and allow more than []float32 vectors

not goal

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

examples

0

examples dictionary:

Sierpinski Triangle Mandelbrot Julia Mandelbrot Basic
Mandelbrot Pseudo Random Colors Sierpinski Triangle 2 Julia Set Julia Basic

1

package main

import (
	"fmt"
	opencl "github.com/opencl-pure/highCL"
	pure "github.com/opencl-pure/pureCL"
	"log"
)

func main() {	
	//init with version of OpenCL and variadic special paths (if you know)
	err := opencl.Init(pure.Version2_0/*, "some/special/path/opencl.dll", "some/special/path/opencl.so"*/)
	if err != nil {
		log.Fatal(err)
	}
	//Do not create platforms/devices/contexts/queues/...
	//Just get the GPU
	d, err := opencl.GetDefaultDevice()
	if err != nil {
		log.Fatal(err)
	}
	defer d.Release()

	data := []float32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} // []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
	// has several kinds of device memory object: Bytes, Vector, Image
	//allocate buffer on the device (16 elems of float32)
	v, err := d.NewVector(data)
	if err != nil {
		log.Fatal(err)
	}
	defer v.Release()

	//an complicated kernel
	const kernelSource = `
__kernel void addOne(__global float* data) {
	const int i = get_global_id (0);
	data[i] += 1;
}
`

	//Add program source to device, get kernel
	_, err = d.AddProgram(fmt.Sprint(kernelSource))
	if err != nil {
		log.Fatal(err)
	}
	k, err := d.Kernel("addOne")
	if err != nil {
		log.Fatal(err)
	}
	//run kernel (global work size 16 and local work size 1)
	event, err := k.Global(16).Local(1).Run(nil, v)
	if err != nil {
		log.Fatal(err)
	}
	defer event.Release()

	//Get data from vector
	newData, err := v.Data()
	if err != nil {
		log.Fatal(err)
	}

	//prints out [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
	fmt.Println(newData.Interface().([]float32))
}

Documentation

Overview

program

Index

Constants

View Source
const (
	ImageTypeGray = ImageType(constants.CL_INTENSITY)
	ImageTypeRGBA = ImageType(constants.CL_RGBA)
)

available image types

Variables

View Source
var (
	//ErrUnknown Generally an unexpected result from an OpenCL function (e.g. CL_SUCCESS but null pointer)
	ErrUnknown = errors.New("cl: unknown error")
)

Functions

func Init

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

func SetHandle

func SetHandle(handle uintptr)

Types

type BuildOptions

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

func (*BuildOptions) String

func (op *BuildOptions) String() string

type Bytes

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

Bytes is a memory buffer on the device that holds []byte

func (*Bytes) Data

func (b *Bytes) Data() ([]byte, error)

Data gets data from device, it's a blocking call

func (*Bytes) Map

func (b *Bytes) Map(k *Kernel, waitEvents []*Event) (*Event, error)

Map applies an map kernel on all elements of the buffer It's a non-blocking call, so it can return an event object that you can wait on. The caller is responsible to release the returned event when it's not used anymore.

func (*Bytes) Release

func (b *Bytes) Release() error

Release releases the buffer on the device

func (*Bytes) Set

func (b *Bytes) Set(data []byte) <-chan error

Set copies the data from host data to device buffer it's a non-blocking call, channel will return an error or nil if the data transfer is complete

func (*Bytes) Size

func (b *Bytes) Size() int

Size the size of the bytes buffer

type Device

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

Device the only needed entrence for the BlackCL represents the device on which memory can be allocated and kernels run it abstracts away all the complexity of contexts/platforms/queues

func GetDefaultDevice

func GetDefaultDevice() (*Device, error)

GetDefaultDevice ...

func GetDevices

func GetDevices(deviceType pure.DeviceType) ([]*Device, error)

GetDevices returns all devices of all platforms with specified type

func (*Device) AddMultipleProgram

func (d *Device) AddMultipleProgram(sources []string) (*Program, error)

AddMultipleProgram compiles programs sources, this function is very sensitive to strings coding

func (*Device) AddMultipleProgramWithBuildingFlags

func (d *Device) AddMultipleProgramWithBuildingFlags(sources []string, flags string) (*Program, error)

AddMultipleProgramWithBuildingFlags compiles programs sources with flags, this function is very sensitive to strings coding add flags only when you know what you do

func (*Device) AddProgram

func (d *Device) AddProgram(source string) (*Program, error)

AddProgram compiles program source, this function is very sensitive to strings coding, and more then 3 programs, so I recommend all kernels put in one string

func (*Device) DriverVersion

func (d *Device) DriverVersion() (string, error)

DriverVersion device info - driver version

func (*Device) Extensions

func (d *Device) Extensions() (string, error)

Extensions device info - extensions

func (*Device) GetInfoString

func (d *Device) GetInfoString(param pure.DeviceInfo) (string, error)

func (*Device) Kernel

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

Kernel returns an kernel if retrieving the kernel didn't complete the function will panic

func (*Device) Name

func (d *Device) Name() (string, error)

Name device info - name

func (*Device) NewBytes

func (d *Device) NewBytes(size int) (*Bytes, error)

NewBytes allocates new memory buffer with specified size on device

func (*Device) NewImage2D

func (d *Device) NewImage2D(imageType ImageType, bounds image.Rectangle) (*Image, error)

NewImage2D NewImage allocates an image buffer

func (*Device) NewImageFromImage2D

func (d *Device) NewImageFromImage2D(img image.Image) (*Image, error)

NewImageFromImage2D NewImageFromImage creates new Image and copies data from image.Image

func (*Device) NewVector

func (d *Device) NewVector(data interface{}) (*Vector, error)

NewVector want slice or array to create opencl vector in gpu I highly recommend primitive types such as int, uint, float32, uint8, ..., but you are free to experiment with GO structs, but you must keep in mind, that is there no guarantee how OpenCL will pass them

func (*Device) OpenCLCVersion

func (d *Device) OpenCLCVersion() (string, error)

OpenCLCVersion device info - OpenCL C Version

func (*Device) PlatformDriverVersion

func (d *Device) PlatformDriverVersion() (string, error)

func (*Device) PlatformExtensions

func (d *Device) PlatformExtensions() ([]pure.Extension, error)

func (*Device) PlatformName

func (d *Device) PlatformName() (string, error)

func (*Device) PlatformOpenCLCVersion

func (d *Device) PlatformOpenCLCVersion() (string, error)

func (*Device) PlatformProfile

func (d *Device) PlatformProfile() (string, error)

func (*Device) PlatformVendor

func (d *Device) PlatformVendor() (string, error)

func (*Device) Profile

func (d *Device) Profile() (string, error)

Profile device info - profile

func (*Device) Release

func (d *Device) Release() error

Release releases the device

func (*Device) String

func (d *Device) String() (string, error)

func (*Device) Vendor

func (d *Device) Vendor() (string, error)

Vendor device info - vendor

func (*Device) Version

func (d *Device) Version() (string, error)

Version device info - version

type ErrUnsupportedArgumentType

type ErrUnsupportedArgumentType struct {
	Index int
	Value interface{}
}

ErrUnsupportedArgumentType error

func (ErrUnsupportedArgumentType) Error

type Event

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

func (*Event) Release

func (event *Event) Release() error

Decrements the event reference count.

func (*Event) Wait

func (event *Event) Wait() error

Wait on the host thread for commands identified by event objects to complete. Returns an error regarding the outcome of the associated task.

type Image

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

Image memory buffer on the device with image data

func (*Image) Bounds

func (img *Image) Bounds() image.Rectangle

Bounds returns the image size

func (*Image) Copy

func (img *Image) Copy(i image.Image) <-chan error

Copy writes the image data to the buffer

func (*Image) Data

func (img *Image) Data() (image.Image, error)

Data gets data from an image buffer and returns an image.Image

func (*Image) Release

func (img *Image) Release() error

Release releases the buffer on the device

type ImageType

type ImageType int

ImageType type of the image enum

type Kernel

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

Kernel represent an single kernel

func (*Kernel) Finish

func (k *Kernel) Finish() error

func (*Kernel) Flush

func (k *Kernel) Flush() error

func (*Kernel) Global

func (k *Kernel) Global(globalWorkSizes ...int) KernelCall

Global returns an KernelCall with global size set

func (*Kernel) GlobalOffset

func (k *Kernel) GlobalOffset(globalWorkOffsets ...int) KernelCall

Global returns an kernel with global offsets set

func (*Kernel) Local

func (k *Kernel) Local(localWorkSizes ...int) KernelCall

Local sets the local work sizes and returns an KernelCall which takes kernel arguments and runs the kernel

func (*Kernel) ReleaseKernel

func (k *Kernel) ReleaseKernel() error

type KernelCall

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

KernelCall is a kernel with global and local work sizes set and it's ready to be run

func (KernelCall) Global

func (kc KernelCall) Global(globalWorkSizes ...int) KernelCall

Global returns an KernelCall with global size set

func (KernelCall) GlobalOffset

func (kc KernelCall) GlobalOffset(globalWorkOffsets ...int) KernelCall

Global returns an kernel with global offsets set

func (KernelCall) Local

func (kc KernelCall) Local(localWorkSizes ...int) KernelCall

Local sets the local work sizes and returns an KernelCall which takes kernel arguments and runs the kernel

func (KernelCall) Run

func (kc KernelCall) Run(waitEvents []*Event, args ...interface{}) (event *Event, err error)

Run calls the kernel on its device with specified global and local work sizes and arguments It's a non-blocking call, so it can return an event object that you can wait on. The caller is responsible to release the returned event when it's not used anymore.

type Platform

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

func (*Platform) GetExtensions

func (p *Platform) GetExtensions() ([]pure.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 struct {
	// contains filtered or unexported fields
}

func (*Program) GetBinaries

func (p *Program) GetBinaries() ([][]byte, error)

GetBinaries Return the program binaries associated with program.

type Vector

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

Vector is a memory buffer on device that holds []float32

func (*Vector) Data

func (v *Vector) Data() (*reflect.Value, error)

Data gets data *reflect.Value in from device, it's a blocking call use v, err := Data(); elen := any(retrievedData.Index(i).Float()) ...

func (*Vector) DataArray

func (v *Vector) DataArray() (*reflect.Value, error)

DataArray gets data *reflect.Value in from device, it's a blocking call use v, err := DataArray(); array := *(v.Interface().(*[16]float32))

func (*Vector) Length

func (v *Vector) Length() int

Length the length of the vector

func (*Vector) Map

func (v *Vector) Map(k *Kernel, waitEvents []*Event) (*Event, error)

Map applies an map kernel on all elements of the vector It's a non-blocking call, so it can return an event object that you can wait on. The caller is responsible to release the returned event when it's not used anymore.

func (*Vector) Release

func (v *Vector) Release() error

Release releases the buffer on the device

func (*Vector) Reset

func (v *Vector) Reset(data interface{}) <-chan error

Reset want equal data as NewVector was given (slice or array), it must have equal length as vector it is usefully for recall kernel with others data without locate new vector it's a non-blocking call, channel will return an error or nil if the data transfer is complete

Jump to

Keyboard shortcuts

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