Documentation ¶
Overview ¶
Package tensor provides GPU tensor and tensor operation implementations.
Index ¶
- type AvgPoolingKernelArgsBackward
- type AvgPoolingKernelArgsForward
- type GPUOperator
- func (o *GPUOperator) Adam(params, gradient, vHistory, sHistory tensor.Tensor, ...)
- func (o *GPUOperator) AvgPoolingBackward(forwardIn, backwardIn tensor.Tensor, kernelSize, padding, stride []int) tensor.Tensor
- func (o *GPUOperator) AvgPoolingForward(t tensor.Tensor, kernelSize, padding, stride []int) tensor.Tensor
- func (o *GPUOperator) Clear(t tensor.Tensor)
- func (o *GPUOperator) Clone(t tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) Copy(dst tensor.Tensor, src tensor.Tensor)
- func (o *GPUOperator) Create(size []int) tensor.Tensor
- func (o *GPUOperator) CreateWithData(data []float64, size []int, descriptor string) tensor.Tensor
- func (o *GPUOperator) CrossEntropy(t tensor.Tensor, label []int) float64
- func (o *GPUOperator) CrossEntropyDerivative(t tensor.Tensor, label []int) tensor.Tensor
- func (o *GPUOperator) Dilate(t tensor.Tensor, dilate []int) tensor.Tensor
- func (o *GPUOperator) Dump(t tensor.Tensor) string
- func (o *GPUOperator) ElementWiseMul(a, b tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) EnableVerification()
- func (o *GPUOperator) Free(t tensor.Tensor)
- func (o *GPUOperator) Gemm(transA, transB bool, alpha, beta float64, a, b, c tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) Im2Col(t tensor.Tensor, kernelSize, padding, stride, dilation []int) tensor.Tensor
- func (o *GPUOperator) Init(t tensor.Tensor, data []float64)
- func (o *GPUOperator) MaxPoolingBackward(forwardIn, backwardIn tensor.Tensor, mask tensor.Tensor, ...) tensor.Tensor
- func (o *GPUOperator) MaxPoolingForward(t tensor.Tensor, kernelSize, padding, stride []int) (out tensor.Tensor, mask tensor.Tensor)
- func (o *GPUOperator) RMSProp(params, gradient, sHistory tensor.Tensor, smoothFactor, learningRate float64)
- func (o *GPUOperator) ReluBackward(forwardIn, backIn tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) ReluForward(in tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) Repeat(t tensor.Tensor, times int) tensor.Tensor
- func (o *GPUOperator) ReportTime()
- func (o *GPUOperator) Reshape(t tensor.Tensor, newSize []int) tensor.Tensor
- func (o *GPUOperator) Rotate180(t tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) ScaleAdd(alpha, beta float64, a, b tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) Slice(t tensor.Tensor, start int, end int) tensor.Tensor
- func (o *GPUOperator) Softmax(t tensor.Tensor) tensor.Tensor
- func (o *GPUOperator) SoftmaxCrossEntropyDerivative(t tensor.Tensor, label []int) tensor.Tensor
- func (o *GPUOperator) Sum(t tensor.Tensor, axis []int) tensor.Tensor
- func (o *GPUOperator) Transpose(t tensor.Tensor, order []int) tensor.Tensor
- func (o *GPUOperator) Zeros(size []int) tensor.Tensor
- type Tensor
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 ¶
CrossEntropyDerivative calculates the derivative using cross entropies.
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 ¶
Repeat will create another tensor that duplicates the input tensor by n times.
func (*GPUOperator) ReportTime ¶
func (o *GPUOperator) ReportTime()
ReportTime lets the operator to report the execution time of each kernel.
func (*GPUOperator) Reshape ¶
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) Slice ¶
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 ¶
SoftmaxCrossEntropyDerivative calculates the derivatives using both softmax /// and cross entropy algorithms.
type Tensor ¶
type Tensor struct {
// contains filtered or unexported fields
}
A Tensor is a multi-dementional array.
func (Tensor) Descriptor ¶
Descriptor returns the descriptor of the tensor.
func (Tensor) NumElement ¶
NumElement returns the number of elements in the tensor.
func (*Tensor) SetDescriptor ¶
SetDescriptor sets the descriptor of the tensor.