gocu

package
v0.0.0-...-c9f06ed Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: MIT Imports: 7 Imported by: 26

Documentation

Overview

Package gocu contains common interfaces to allow the different cuda packages/libraries to intermix with each other and with go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

type Allocator interface {
	Malloc(size uint) (cutil.Mem, error)
}

Allocator allocates memory for cuda. //Example can be seen in cudart.

type Attributes

type Attributes interface {
	MaxThreadsPerMultiProcessor() (int32, error)
	MultiProcessorCount() (int32, error)
	MaxThreadsPerBlock() (int32, error)
	MaxGridDimXYZ() ([]int32, error)
	MaxBlockDimXYZ() ([]int32, error)
}

Attributes are the attributes a device needs to return.

type Config

type Config struct {
	Dimx            int32
	Dimy            int32
	Dimz            int32
	ThreadPerBlockx uint32
	ThreadPerBlocky uint32
	ThreadPerBlockz uint32
	BlockCountx     uint32
	BlockCounty     uint32
	BlockCountz     uint32
}

Config holds configuration values for launching a kernel

type ConfigHelper

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

ConfigHelper creates Config structs through methods.

func CreateConfigHelper

func CreateConfigHelper(device Attributes) (*ConfigHelper, error)

CreateConfigHelper a launch config helper.

func (*ConfigHelper) CreateLaunchConfig

func (l *ConfigHelper) CreateLaunchConfig(x, y, z int32) (launch Config)

CreateLaunchConfig creates a launch configurator. It is used when launching kernels

type CudaPtr

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

CudaPtr can be used to allocate mem that is used by cuda. I didn't want to do this but it is unintuitive in the means of making it otherwise. The reason being is that cgo will yell at you if you try to use an unsafe pointer using a go type. Just make one by the built in x:=new(gocu.DevicePtr)

func WrapUnsafe

func WrapUnsafe(d unsafe.Pointer) *CudaPtr

WrapUnsafe wraps an unsafe.Pointer around a *CudaPtr

func (*CudaPtr) DPtr

func (d *CudaPtr) DPtr() *unsafe.Pointer

DPtr returns the *unsafe.Pointer

func (*CudaPtr) Ptr

func (d *CudaPtr) Ptr() unsafe.Pointer

Ptr returns the unsafepointer

type Device

type Device interface {
	Set() error
}

Device is a cuda device that can be set on the host thread Major is the major compute capability Minor is the minor compute capability

type Streamer

type Streamer interface {
	Ptr() unsafe.Pointer
	Sync() error
}

Streamer allows streams made from cuda or

type Worker

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

Worker works on functions on a device

func NewWorker

func NewWorker(d Device) (w *Worker)

NewWorker creates a worker that works on a single host thread

func (*Worker) Close

func (w *Worker) Close()

Close closes the worker channel

func (*Worker) Work

func (w *Worker) Work(fn func() error) error

Work takes a call back function, sends it through a channel to a locked thread hosting a gpu.

This function will block until work is done. You don't have to wait though.

If not wanting to wait. I would recomend wrapping this around a go func(){}() so that you could pick up the error.

type Wrapper

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

Wrapper allows go memory to interact with cuda using the Mem interface

func MakeGoMem

func MakeGoMem(input interface{}) (*Wrapper, error)

MakeGoMem returns a GoMem considering the input type. Will only support slices and pointers to go types

func (*Wrapper) DPtr

func (g *Wrapper) DPtr() *unsafe.Pointer

DPtr is a double pointer of the unsafe.Pointer

func (*Wrapper) OffSet

func (g *Wrapper) OffSet(byunits uint) *Wrapper

OffSet returns a new Wrapper

func (*Wrapper) Ptr

func (g *Wrapper) Ptr() unsafe.Pointer

Ptr is an unsafe.Pointer of some cuda memory

func (*Wrapper) TotalBytes

func (g *Wrapper) TotalBytes() uint

TotalBytes returns the total bytes this has

Jump to

Keyboard shortcuts

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