tensor

package
v0.0.0-...-98db5b7 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: CC-BY-4.0 Imports: 18 Imported by: 17

Documentation

Overview

Package tensor is used to make tensors by using gocudnn. It is currently not supporting what I call the "EX" functions. because the Tensor struct is also going to be carrying a filter descripter. Also I call it "EX" functions loosly, because I think there is a miss labeling of the function names in cudnn. Basicly it is the set tensor fuctions that don't include the format and include the strides asdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeJPG

func MakeJPG(folder, subfldr string, index int, img image.Image) error

MakeJPG will make a JPG file for the image passed it can be sepperated by neurons and the such

func ToOneImage

func ToOneImage(layer [][]image.Image, X, Y int) image.Image

ToOneImage will spread out the image.Images into one image.Image. It will only work if all the [][]image.Image are the same size Channels will be in the x direction, and neurons will be in the y direction. X and Y are the amount of separation in pixels in the given dim between images. The separator will be in the color black!

Types

type Concat

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

Concat concats the channels of multiple tensors into a new tensor. Concats are seperated by batch.

func CreateConcat

func CreateConcat(h *cudnn.Handler) (c *Concat, err error)

CreateConcat creates a concat handler. It contains the kernel that does the concat operation on the gpu Default alpha, beta are set to alpha = 1, beta =0.

func (*Concat) Backward

func (c *Concat) Backward(h *cudnn.Handler, srcs []*Volume, dest *Volume) error

Backward does the backward algorithm where the data in dest goes to the srcs.

func (*Concat) Forward

func (c *Concat) Forward(h *cudnn.Handler, srcs []*Volume, dest *Volume) error

Forward does the forward where data in srcs goes to dest

func (*Concat) GetOutputDimsfromInputDims

func (c *Concat) GetOutputDimsfromInputDims(srcs [][]int32, frmt gocudnn.TensorFormat) ([]int32, error)

GetOutputDimsfromInputDims gets the outputdims from the inputdims. If srcs dims other than the channel dims not equal. Function will return an error.

func (*Concat) GetOutputdims

func (c *Concat) GetOutputdims(srcs []*Volume) (outputdims []int32, err error)

GetOutputdims returns the output dims of the tensor for the outputed Volume.

func (*Concat) SetBackwardAlpha

func (c *Concat) SetBackwardAlpha(alpha float64)

SetBackwardAlpha sets the backward alpha

func (*Concat) SetBackwardBeta

func (c *Concat) SetBackwardBeta(beta float64)

SetBackwardBeta sets the backward beta

func (*Concat) SetForwardAlpha

func (c *Concat) SetForwardAlpha(alpha float64)

SetForwardAlpha sets the forward alpha

func (*Concat) SetForwardBeta

func (c *Concat) SetForwardBeta(beta float64)

SetForwardBeta sets the forward beta

type Info

type Info struct {
	Format   gocudnn.TensorFormat `json:"Format,omitempty"`
	DataType gocudnn.DataType     `json:"DataType,omitempty"`
	Nan      gocudnn.NANProp      `json:"Nan,omitempty"`
	Dims     []int32              `json:"Dims,omitempty"`
	Stride   []int32              `json:"Stride,omitempty"`
	MaxDims  []int32              `json:"max_dims,omitempty"`
	Data     []byte               `json:"data,omitempty"`
}

Info struct contains the info that is needed to build a volume

func MakeInfo

func MakeInfo(frmt gocudnn.TensorFormat, dtype gocudnn.DataType, currnetdims, maxdims []int32) Info

MakeInfo makes an info struct

func (Info) Build

func (i Info) Build(handle *cudnn.Handler) (*Volume, error)

Build is a method for Info that will retrun a volume type. If Weights is nil the memory will still be malloced on the cuda side. So make sure to add values if needed.

type Volume

type Volume struct {
	*nvidia.Malloced
	// contains filtered or unexported fields
}

Volume holds both a gocudnn.TensorD and gocudnn.FilterD and the allocated memory associated with it

func Build

func Build(handle *cudnn.Handler, frmt gocudnn.TensorFormat, dtype gocudnn.DataType, dims []int32) (*Volume, error)

Build creates a tensor and mallocs the memory for the tensor.

func BuildEX

func BuildEX(handle *cudnn.Handler, frmt gocudnn.TensorFormat, dtype gocudnn.DataType, dims []int32, mem *nvidia.Malloced) (v *Volume, err error)

BuildEX builds a volume with settings passed. And uses the mem passed as its memory. if mem is nil function will allocate memory to gpu itself

func BuildRandNorm

func BuildRandNorm(handle *cudnn.Handler, frmt gocudnn.TensorFormat, dtype gocudnn.DataType, currentdims []int32, mean, std float32) (*Volume, error)

BuildRandNorm sets a randomnorm volume that can have its values set to random values over and over again

func BuildWeights

func BuildWeights(handle *cudnn.Handler, frmt gocudnn.TensorFormat, dtype gocudnn.DataType, dims []int32) (*Volume, error)

BuildWeights builds the weights

func BuildtoCudaHost

func BuildtoCudaHost(handle *cudnn.Handler, frmt gocudnn.TensorFormat, dtype gocudnn.DataType, startdims []int32) (*Volume, error)

BuildtoCudaHost stores the tensor memory to paged memory

func ZeroClone

func ZeroClone(h *cudnn.Handler, t *Volume) (*Volume, error)

ZeroClone clones the Volume with only zeros

func (*Volume) AddTo

func (t *Volume) AddTo(handle *cudnn.Handler, A *Volume, Ascalar, tscalar float64) error

AddTo formula is (t *Tensor)= alpha*(A)+beta*(t *Tensor) Dim max is 5. Number of dims need to be the same. Dim size need to match or be equal to 1. In the later case the same value from the A tensor for the dims will be used to blend into (t *Tensor).

func (*Volume) DataType

func (t *Volume) DataType() gocudnn.DataType

DataType returns the datatype of the volume

func (*Volume) Dims

func (t *Volume) Dims() []int32

Dims returns the dims of the tensor

func (*Volume) FD

func (t *Volume) FD() *gocudnn.FilterD

FD returns the filter descriptor for Tensor

func (*Volume) Format

func (t *Volume) Format() gocudnn.TensorFormat

Format returns the format of the volume

func (*Volume) Info

func (t *Volume) Info() (Info, error)

Info returns an Info struct that is used for saving info. If an error is returned then the values of Info will be set to default golang's default

func (*Volume) LoadMem

func (t *Volume) LoadMem(handle *cudnn.Handler, input cutil.Mem, size uint) error

LoadMem will Load the volume with the inputed mem. Input mem with the size of size

func (*Volume) NormalRand

func (t *Volume) NormalRand(h *cudnn.Handler, mean, std float32) error

NormalRand sets the values in the volume to some Normalized Noise

func (*Volume) OpAdd

func (t *Volume) OpAdd(h *cudnn.Handler, A, B *Volume, alpha1, alpha2, beta float64) error

OpAdd adds the op into t

func (*Volume) OpMax

func (t *Volume) OpMax(h *cudnn.Handler, A, B *Volume, alpha1, alpha2, beta float64) error

OpMax does max comparison Operation C = op ( alpha1[0] * A, alpha2[0] * B ) + beta[0] * C,

func (*Volume) OpMin

func (t *Volume) OpMin(h *cudnn.Handler, A, B *Volume, alpha1, alpha2, beta float64) error

OpMin does min comparison Operation C = op ( alpha1[0] * A, alpha2[0] * B ) + beta[0] * C,

func (*Volume) OpMult

func (t *Volume) OpMult(h *cudnn.Handler, A, B *Volume, alpha1, alpha2, beta float64) error

OpMult does a multiplication Operation C = op ( alpha1[0] * A, alpha2[0] * B ) + beta[0] * C,

func (*Volume) OpNot

func (t *Volume) OpNot(h *cudnn.Handler, A *Volume, alpha1, beta float64) error

OpNot does negation Operation performed on only the A C = op ( alpha1[0] * A) + beta[0] * C,

func (*Volume) OpSqrt

func (t *Volume) OpSqrt(h *cudnn.Handler, A *Volume, alpha1, beta float64) error

OpSqrt does squareroot Operation C = op ( alpha1[0] * A ) + beta[0] * C,

func (*Volume) Properties

func (t *Volume) Properties() (gocudnn.TensorFormat, gocudnn.DataType, []int32, error)

Properties returns the properties of the tensor

func (*Volume) SIB

func (t *Volume) SIB() uint

SIB will returns the size in bytes

func (*Volume) ScaleValues

func (t *Volume) ScaleValues(handle *cudnn.Handler, alpha float64) error

ScaleValues values will scale the values to the scalar passed

func (*Volume) SetNotPropNan

func (t *Volume) SetNotPropNan()

SetNotPropNan will set the nan propigation flag to NotPropigationNan (NotPropigationNan is default)

func (*Volume) SetPropNan

func (t *Volume) SetPropNan()

SetPropNan will change the default nan propigation flag from PropNanNon to PropNaN

func (*Volume) SetRandom

func (t *Volume) SetRandom(mean, max, fanin float64) error

SetRandom sets Random Value to weights Double and Float datatype only supported

func (*Volume) SetRandomNormal

func (t *Volume) SetRandomNormal(handle *cudnn.Handler, min, max float32) error

SetRandomNormal sets random numbers for values in volume

func (*Volume) SetValues

func (t *Volume) SetValues(handle *cudnn.Handler, input float64) error

SetValues sets all the values in the tensor to whatever is passed. It does this by looking at the format that is held in the tensor descriptor and auto retypes it. Documentation states that you have to pass a value that is the same type as the DataType. input is typecase

func (*Volume) String

func (t *Volume) String() string

func (*Volume) TD

func (t *Volume) TD() *gocudnn.TensorD

TD returns the tensor descriptor for Tensor

func (*Volume) TDStrided

func (t *Volume) TDStrided() *gocudnn.TensorD

TDStrided is a function that returns the strided tensor descriptor.

func (*Volume) ToImages

func (t *Volume) ToImages(handle *cudnn.Handler) ([][]image.Image, error)

ToImages makes a 2d array of images. If it is a filter then it will be listed by the images[x][y] x is the neurons. y is the feature maps for neuron x if it is a tensor then x is the batch. y is the channel. It doesn't matter what format was used

func (*Volume) ToImagesColor

func (t *Volume) ToImagesColor(h *cudnn.Handler) ([][]image.Image, error)

ToImagesColor makes a 2d array of images. Negative will be Green. Positive will be purple it returns a double array of image.Image. Only Float32 support right now

func (*Volume) ToOneImageColor

func (t *Volume) ToOneImageColor(h *cudnn.Handler, X, Y int) (image.Image, error)

ToOneImageColor will return an image.Image of the volume in batch/neuron for the rows, and channels for the column Y and X represent how much padding of (hopefully black) there is between the channels and neurons

func (*Volume) TogglePrintValueForStringer

func (t *Volume) TogglePrintValueForStringer()

TogglePrintValueForStringer is for debugging. It will include the array values in String().

func (*Volume) Vol

func (t *Volume) Vol() int32

Vol returns the volume of tensor

Jump to

Keyboard shortcuts

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