tensor

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2022 License: MIT Imports: 10 Imported by: 5

Documentation

Overview

Package tensor provides GPU tensor and tensor operation implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AvgPoolingKernelArgsBackward

type AvgPoolingKernelArgsBackward struct {
	NumThreads uint64
	Top        driver.Ptr
	N          int32
	C          int32
	H          int32
	W          int32
	PooledH    int32
	PooledW    int32
	KernelH    int32
	KernelW    int32
	StrideH    int32
	StrideW    int32
	PadH       int32
	PadW       int32
	Bottom     driver.Ptr

	HiddenGlobalOffsetX int64
	HiddenGlobalOffsetY int64
	HiddenGlobalOffsetZ int64
}

AvgPoolingKernelArgsBackward defines forward kernel arguments

type AvgPoolingKernelArgsForward

type AvgPoolingKernelArgsForward struct {
	NumThreads uint64
	Bottom     driver.Ptr
	N          int32
	C          int32
	H          int32
	W          int32
	PooledH    int32
	PooledW    int32
	KernelH    int32
	KernelW    int32
	StrideH    int32
	StrideW    int32
	PadH       int32
	PadW       int32
	Top        driver.Ptr

	HiddenGlobalOffsetX int64
	HiddenGlobalOffsetY int64
	HiddenGlobalOffsetZ int64
}

AvgPoolingKernelArgsForward defines forward kernel arguments

type GPUOperator

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

GPUOperator can perform operations on GPU tensors.

func NewGPUOperator

func NewGPUOperator(
	gpuDriver *driver.Driver,
	ctx *driver.Context,
) *GPUOperator

NewGPUOperator creates a new GPU Operator.

func (*GPUOperator) Adam

func (o *GPUOperator) Adam(
	params, gradient, vHistory, sHistory tensor.Tensor,
	smoothFactor1, smoothFactor2, learningRate float64,
)

Adam uses the Adam algorithm to update the parameters

func (*GPUOperator) AvgPoolingBackward

func (o *GPUOperator) AvgPoolingBackward(
	forwardIn, backwardIn tensor.Tensor,
	kernelSize, padding, stride []int,
) tensor.Tensor

AvgPoolingBackward claculates the backward propagation of the average pooling layer.

func (*GPUOperator) AvgPoolingForward

func (o *GPUOperator) AvgPoolingForward(
	t tensor.Tensor,
	kernelSize, padding, stride []int,
) tensor.Tensor

AvgPoolingForward calculates the forward propagation of the average pooling layer.

func (*GPUOperator) Clear

func (o *GPUOperator) Clear(t tensor.Tensor)

Clear sets the content of the tensor to 0.

func (*GPUOperator) Clone

func (o *GPUOperator) Clone(t tensor.Tensor) tensor.Tensor

Clone duplicates the input tensor.

func (*GPUOperator) Copy

func (o *GPUOperator) Copy(dst tensor.Tensor, src tensor.Tensor)

Copy copies data from one tensor to another tensor. The src and dst tensor must have the same number of elements.

func (*GPUOperator) Create

func (o *GPUOperator) Create(size []int) tensor.Tensor

Create creates a new GPU tensor

func (*GPUOperator) CreateWithData

func (o *GPUOperator) CreateWithData(
	data []float64,
	size []int,
	descriptor string,
) tensor.Tensor

CreateWithData creates the tensor and copies the given data to the GPU memory.

func (*GPUOperator) CrossEntropy

func (o *GPUOperator) CrossEntropy(t tensor.Tensor, label []int) float64

CrossEntropy calculates the cross entropy of the output.

func (*GPUOperator) CrossEntropyDerivative

func (o *GPUOperator) CrossEntropyDerivative(
	t tensor.Tensor, label []int,
) tensor.Tensor

CrossEntropyDerivative calculates the derivative using cross entropies.

func (*GPUOperator) Dilate

func (o *GPUOperator) Dilate(t tensor.Tensor, dilate []int) tensor.Tensor

Dilate adds 0s between rows and columns.

func (*GPUOperator) Dump

func (o *GPUOperator) Dump(t tensor.Tensor) string

Dump writes the content of the tensor to a string.

func (*GPUOperator) ElementWiseMul

func (o *GPUOperator) ElementWiseMul(
	a, b tensor.Tensor,
) tensor.Tensor

ElementWiseMul calculates the element multiplication of A and B.

func (*GPUOperator) EnableVerification

func (o *GPUOperator) EnableVerification()

EnableVerification will run the same operations in a CPU operator and compare the results.

func (*GPUOperator) Free

func (o *GPUOperator) Free(t tensor.Tensor)

Free releases the allocated GPU memory.

func (*GPUOperator) Gemm

func (o *GPUOperator) Gemm(
	transA, transB bool,
	alpha, beta float64,
	a, b, c tensor.Tensor,
) tensor.Tensor

Gemm performs alpha * A * B + beta * C operation.

func (*GPUOperator) Im2Col

func (o *GPUOperator) Im2Col(
	t tensor.Tensor,
	kernelSize, padding, stride, dilation []int,
) tensor.Tensor

Im2Col converts images to columns so that convolutional operations can be completed with GEMM.

func (*GPUOperator) Init

func (o *GPUOperator) Init(t tensor.Tensor, data []float64)

Init sets the data of the tensor

func (*GPUOperator) MaxPoolingBackward

func (o *GPUOperator) MaxPoolingBackward(
	forwardIn, backwardIn tensor.Tensor,
	mask tensor.Tensor,
	kernelSize, padding, stride []int,
) tensor.Tensor

MaxPoolingBackward calculates the backward propagation of the max pooling layer.

func (*GPUOperator) MaxPoolingForward

func (o *GPUOperator) MaxPoolingForward(
	t tensor.Tensor,
	kernelSize, padding, stride []int,
) (out tensor.Tensor, mask tensor.Tensor)

MaxPoolingForward calculates the forward propagation of the max pooling layer.

func (*GPUOperator) RMSProp

func (o *GPUOperator) RMSProp(
	params, gradient, sHistory tensor.Tensor,
	smoothFactor, learningRate float64,
)

RMSProp uses the RMSProp algorithm to update the parameters

func (*GPUOperator) ReluBackward

func (o *GPUOperator) ReluBackward(
	forwardIn, backIn tensor.Tensor,
) tensor.Tensor

ReluBackward Implementation

func (*GPUOperator) ReluForward

func (o *GPUOperator) ReluForward(
	in tensor.Tensor,
) tensor.Tensor

ReluForward Implementation

func (*GPUOperator) Repeat

func (o *GPUOperator) Repeat(t tensor.Tensor, times int) tensor.Tensor

Repeat will create another tensor that duplicates the input tensor by n times.

func (*GPUOperator) ReportTime added in v2.0.1

func (o *GPUOperator) ReportTime()

ReportTime lets the operator to report the execution time of each kernel.

func (*GPUOperator) Reshape

func (o *GPUOperator) Reshape(t tensor.Tensor, newSize []int) tensor.Tensor

Reshape creates another tensor with the same elements but a different size.

func (*GPUOperator) Rotate180

func (o *GPUOperator) Rotate180(t tensor.Tensor) tensor.Tensor

Rotate180 rotates the lowest two dimensions of the tensor by 180 degree.

func (*GPUOperator) ScaleAdd

func (o *GPUOperator) ScaleAdd(
	alpha, beta float64,
	a, b tensor.Tensor,
) tensor.Tensor

ScaleAdd performs element-wide alpha*A + beta*B operation.

func (*GPUOperator) Slice

func (o *GPUOperator) Slice(t tensor.Tensor, start int, end int) tensor.Tensor

Slice will create another tensor that shares part of the buffer with the input tensor.

func (*GPUOperator) Softmax

func (o *GPUOperator) Softmax(t tensor.Tensor) tensor.Tensor

Softmax performs the softmax operation.

func (*GPUOperator) SoftmaxCrossEntropyDerivative

func (o *GPUOperator) SoftmaxCrossEntropyDerivative(
	t tensor.Tensor,
	label []int,
) tensor.Tensor

SoftmaxCrossEntropyDerivative calculates the derivatives using both softmax /// and cross entropy algorithms.

func (*GPUOperator) Sum

func (o *GPUOperator) Sum(t tensor.Tensor, axis []int) tensor.Tensor

Sum reduces the number of axes by summing the numbers on given axes.

func (*GPUOperator) Transpose

func (o *GPUOperator) Transpose(t tensor.Tensor, order []int) tensor.Tensor

Transpose reorders the axises of the tensor.

func (*GPUOperator) Zeros

func (o *GPUOperator) Zeros(size []int) tensor.Tensor

Zeros creates a tensor prefilled with zeros.

type Tensor

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

A Tensor is a multi-dementional array.

func (Tensor) Descriptor

func (t Tensor) Descriptor() string

Descriptor returns the descriptor of the tensor.

func (Tensor) Dim

func (t Tensor) Dim() int

Dim returns the number of dimensions that the tensor has.

func (Tensor) NumElement

func (t Tensor) NumElement() int

NumElement returns the number of elements in the tensor.

func (*Tensor) Ptr

func (t *Tensor) Ptr() driver.Ptr

Ptr returns the GPU pointer of the tensor.

func (*Tensor) SetDescriptor

func (t *Tensor) SetDescriptor(d string)

SetDescriptor sets the descriptor of the tensor.

func (*Tensor) SetSize

func (t *Tensor) SetSize(s []int)

SetSize sets the size of the tensor.

func (Tensor) Size

func (t Tensor) Size() []int

Size returns the size of the tensor on each dimension.

func (*Tensor) Vector

func (t *Tensor) Vector() []float64

Vector copies the data from the GPU to the simulator.

Jump to

Keyboard shortcuts

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