gotch

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

Gotch Colab

This is a special gotch version to temporarily work on Google Colab and gophernotes Only, for other use cases, please use gotch.

Here is Gotch Colab Starter

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CPU  Device = Device{Name: "CPU", Value: -1}
	CUDA Cuda   = Cuda{Name: "CUDA", Value: 0}
)

Functions

func DTypeSize

func DTypeSize(dt DType) (retVal uint, err error)

DTypeSize returns DType size in Bytes

func ElementGoType

func ElementGoType(data interface{}) (retVal reflect.Type, err error)

ElementGoType infers and returns Go type of element in given data

func IsSupportedScalar

func IsSupportedScalar(k reflect.Kind) bool

IsSupportedScalar checks whether given SCALAR type is supported TODO: check input is a scalar.

func ToGoType

func ToGoType(dtype DType) (retVal reflect.Type, err error)

ToGoType infers and returns supported equivalent Go type from given DType

func TypeOf

func TypeOf(dt DType, shape []int64) (retVal reflect.Type, err error)

TypeOf infers and returns element Go type from given tensor DType and shape

Types

type CInt

type CInt = int32

CInt is equal to C type int. Go type is int32

func DType2CInt

func DType2CInt(dt DType) (retVal CInt, err error)

type Cuda

type Cuda Device

func (Cuda) CudnnIsAvailable

func (cu Cuda) CudnnIsAvailable() bool

CudnnIsAvailable return true if cudnn support is available

func (Cuda) CudnnSetBenchmark

func (cu Cuda) CudnnSetBenchmark(b bool)

CudnnSetBenchmark sets cudnn benchmark mode

When set cudnn will try to optimize the generators during the first network runs and then use the optimized architecture in the following runs. This can result in significant performance improvements.

func (Cuda) DeviceCount

func (cu Cuda) DeviceCount() int64

DeviceCount returns the number of GPU that can be used.

func (Cuda) IsAvailable

func (cu Cuda) IsAvailable() bool

CudnnIsAvailable returns true if cuda support is available

type DType

type DType struct {
	reflect.Type
}

DType represents different kind of element that a tensor can hold. It has an embedded `reflect.Type` for type reflection.

var (
	Uint8 DType = DType{reflect.TypeOf(uint8(1))} // 0
	Int8  DType = DType{reflect.TypeOf(int8(1))}  // 1
	Int16 DType = DType{reflect.TypeOf(int16(1))} // 2
	Int   DType = DType{reflect.TypeOf(int32(1))} // 3
	Int64 DType = DType{reflect.TypeOf(int64(1))} // 4
	// Half       DType   = DType{reflect.TypeOf(GoFloat16(1))}     // 5
	Float  DType = DType{reflect.TypeOf(float32(1))} // 6
	Double DType = DType{reflect.TypeOf(float64(1))} // 7
	// ComplexHalf DType  = DType{reflect.TypeOf(GoComplexHalf(1))} // 8
	// ComplexFloat DType  = DType{reflect.TypeOf(complex64(1))}  // 9
	// ComplexDouble DType = DType{reflect.TypeOf(complex128(1))} // 10
	Bool DType = DType{reflect.TypeOf(true)} // 11
)

TODO: double check these Torch DType to Go type

func CInt2DType

func CInt2DType(v CInt) (dtype DType, err error)

func DTypeFromData

func DTypeFromData(data interface{}) (retVal DType, err error)

DTypeFromData infers returns equavalent DType from given data

func DataDType

func DataDType(v interface{}, shape []int64) (retVal DType, err error)

DataDType infers and returns data type of tensor data

func ElementDType

func ElementDType(v interface{}) (retVal DType, err error)

ElementDType infers and returns its own tensor data type

func ToDType

func ToDType(typ reflect.Type) (retVal DType, err error)

ToDType infers and returns supported equivalent DType from given Go type

func (DType) CInt

func (dt DType) CInt() (retVal CInt)

type DTypeDevice

type DTypeDevice struct {
	DType  DType
	Device Device
}

type Device

type Device struct {
	Name  string
	Value int
}

func CudaBuilder

func CudaBuilder(v uint) Device

func CudaIfAvailable

func CudaIfAvailable() Device

CudaIfAvailable returns a GPU device if available, else CPU.

func NewCuda

func NewCuda() Device

NewCuda creates a cuda device (default) if available If will be panic if cuda is not available.

func (Device) CInt

func (d Device) CInt() CInt

func (Device) CudaIfAvailable

func (d Device) CudaIfAvailable() Device

CudaIfAvailable returns a GPU device if available, else default to CPU

func (Device) IsCuda

func (d Device) IsCuda() bool

IsCuda returns whether device is a Cuda device

func (Device) OfCInt

func (d Device) OfCInt(v CInt) Device

Directories

Path Synopsis
NOTE: functions in this file would be automatically generated and named as `c-generated.go`
NOTE: functions in this file would be automatically generated and named as `c-generated.go`
aug

Jump to

Keyboard shortcuts

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