opencl

package module
v0.0.0-...-2d437b2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 4 Imported by: 1

README

Test Go Reference

go-opencl

go-opencl provides a high-level interface to the OpenCL API, allowing you to run OpenCL programs from Go.

Development Status

WARNING: This project is currently under development and has not been fully tested. Use it at your own risk. We welcome any feedback and contributions.

Requirements

linux

sudo apt install ocl-icd-opencl-dev opencl-headers

windows

This project incorporates OpenCL-Headers and OpenCL-ICD-Loader, which are included in the include-3.0.13 and lib-windows-3.0.13-x64 directories respectively for Windows.

The sources for these components are as follows:

cl-info command

The cl-info command provides information about the OpenCL platforms and devices on your system.

To install cl-info, run the following command:

go install github.com/CyberChainXyz/go-opencl/cmd/cl-info

OpenCL runner

import cl "github.com/CyberChainXyz/go-opencl"

Refer to the runner_test.go file for usage examples of the OpenCL runner.

Other resources

OPENCL 3.0 Reference: https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/

Documentation

Index

Constants

View Source
const (
	READ_WRITE     C.cl_mem_flags = C.CL_MEM_READ_WRITE
	WRITE_ONLY                    = C.CL_MEM_WRITE_ONLY
	READ_ONLY                     = C.CL_MEM_READ_ONLY
	USE_HOST_PTR                  = C.CL_MEM_USE_HOST_PTR
	ALLOC_HOST_PTR                = C.CL_MEM_ALLOC_HOST_PTR
	COPY_HOST_PTR                 = C.CL_MEM_COPY_HOST_PTR
)

Variables

This section is empty.

Functions

func ReadBuffer

func ReadBuffer[E any](runner *OpenCLRunner, offset int, buffer *Buffer, target []E) error

ReadBuffer reads data from an OpenCL buffer into the target slice.

func WriteBuffer

func WriteBuffer[E any](runner *OpenCLRunner, offset int, buffer *Buffer, source []E, blocking bool) error

WriteBuffer writes data from the source slice to an OpenCL buffer.

Types

type Buffer

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

Buffer represents an OpenCL buffer.

func CreateBuffer

func CreateBuffer[E any](runner *OpenCLRunner, flags C.cl_mem_flags, source []E) (*Buffer, error)

CreateBuffer creates an OpenCL buffer with the specified flags and source data.

type KernelParam

type KernelParam struct {
	Size    uintptr
	Pointer unsafe.Pointer
}

KernelParam represents a parameter for an OpenCL kernel.

func BufferParam

func BufferParam(v *Buffer) KernelParam

BufferParam creates a KernelParam for an OpenCL buffer.

func Param

func Param[E any](v *E) KernelParam

Param creates a KernelParam for a value.

type OpenCLDevice

type OpenCLDevice struct {
	Device_id   C.cl_device_id
	Platform_id C.cl_platform_id

	Device_type    C.cl_device_type
	Name           string
	Profile        string
	Version        string
	Vendor         string
	Driver_version string

	Max_clock_frequency C.cl_uint
	Max_mem_alloc_size  C.cl_ulong
	Global_mem_size     C.cl_ulong
	Max_compute_units   C.cl_uint
	Max_work_group_size C.size_t

	Max_work_item_dimensions C.cl_uint
	Max_work_item_sizes      []C.size_t
}

func (*OpenCLDevice) InitRunner

func (device *OpenCLDevice) InitRunner() (*OpenCLRunner, error)

InitRunner initializes an OpenCLRunner for the given OpenCLDevice. It creates a context and a command queue.

type OpenCLInfo

type OpenCLInfo struct {
	Platform_count C.cl_uint
	Platforms      []*OpenCLPlatform
}

func Info

func Info() (*OpenCLInfo, error)

type OpenCLPlatform

type OpenCLPlatform struct {
	Platform_id  C.cl_platform_id
	Device_count C.cl_uint
	Name         string
	Profile      string
	Version      string
	Vendor       string
	Devices      []*OpenCLDevice
}

type OpenCLRunner

type OpenCLRunner struct {
	Device       *OpenCLDevice
	Context      C.cl_context
	CommandQueue C.cl_command_queue

	Program C.cl_program
	Kernels map[string]C.cl_kernel
	Buffers []*Buffer
}

OpenCLRunner represents an OpenCL runner.

func (*OpenCLRunner) CompileKernels

func (runner *OpenCLRunner) CompileKernels(codeSourceList []string, kernelNameList []string, options string) error

CompileKernels compiles OpenCL kernels from the provided source code.

func (*OpenCLRunner) CreateEmptyBuffer

func (runner *OpenCLRunner) CreateEmptyBuffer(flags C.cl_mem_flags, size int) (*Buffer, error)

CreateEmptyBuffer creates an empty OpenCL buffer with the specified flags and size.

func (*OpenCLRunner) Free

func (runner *OpenCLRunner) Free() error

Free releases all resources associated with the OpenCLRunner.

func (*OpenCLRunner) ReleaseBuffer

func (runner *OpenCLRunner) ReleaseBuffer(buffer *Buffer) error

ReleaseBuffer releases the specified OpenCL buffer.

func (*OpenCLRunner) RunKernel

func (runner *OpenCLRunner) RunKernel(kernelName string, work_dim int,
	global_work_offset []uint64, global_work_size []uint64, local_work_size []uint64, args []KernelParam, wait bool) error

RunKernel runs an OpenCL kernel with the specified work dimensions, work sizes, and arguments.

func (*OpenCLRunner) SetKernelArgs

func (runner *OpenCLRunner) SetKernelArgs(kernelName string, args []KernelParam) error

SetKernelArgs sets the arguments for a specific OpenCL kernel.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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