go_matrix_cuda: github.com/alonsovidales/go_matrix_cuda Index | Files

package mt

import "github.com/alonsovidales/go_matrix_cuda"

Index

Package Files

cuda_kernel_add_bias.go cuda_kernel_matrix_add.go cuda_kernel_matrix_add_bias_top.go cuda_kernel_matrix_log.go cuda_kernel_matrix_mult.go cuda_kernel_matrix_mult_all.go cuda_kernel_matrix_mult_by.go cuda_kernel_matrix_mult_trans.go cuda_kernel_matrix_neg.go cuda_kernel_matrix_one_minus.go cuda_kernel_matrix_pow_two.go cuda_kernel_matrix_set_bias_to_zero.go cuda_kernel_matrix_sigmoid.go cuda_kernel_matrix_sigmoid_gradient.go cuda_kernel_matrix_sub.go cuda_kernel_matrix_trans.go cuda_kernel_remove_bias.go cuda_kernel_remove_bias_top.go cuda_kernel_sum_all.go matrix.go

Constants

const DEBUG = false

Set the ptx files to be used from the cuda_modules directory if true, or the go kernels if false

const KER_MATRIX_ADD = "" /* 1505 byte string literal not displayed */
const KER_MATRIX_ADD_BIAS = "" /* 1605 byte string literal not displayed */
const KER_MATRIX_ADD_BIAS_TOP = "" /* 1591 byte string literal not displayed */
const KER_MATRIX_LOG = "" /* 4341 byte string literal not displayed */
const KER_MATRIX_MULT = "" /* 2021 byte string literal not displayed */
const KER_MATRIX_MULT_ALL = "" /* 1565 byte string literal not displayed */
const KER_MATRIX_MULT_BY = "" /* 1315 byte string literal not displayed */
const KER_MATRIX_MULT_TRANS = "" /* 2192 byte string literal not displayed */
const KER_MATRIX_NEG = "" /* 1193 byte string literal not displayed */
const KER_MATRIX_ONE_MINUS = "" /* 1293 byte string literal not displayed */
const KER_MATRIX_POW_TWO = "" /* 1235 byte string literal not displayed */
const KER_MATRIX_REMOVE_BIAS = "" /* 1482 byte string literal not displayed */
const KER_MATRIX_REMOVE_BIAS_TOP = "" /* 1492 byte string literal not displayed */
const KER_MATRIX_SET_BIAS_TO_ZERO = "" /* 986 byte string literal not displayed */
const KER_MATRIX_SIGMOID = "" /* 10832 byte string literal not displayed */
const KER_MATRIX_SIGMOID_GRADIENT = "" /* 10981 byte string literal not displayed */
const KER_MATRIX_SUB = "" /* 1505 byte string literal not displayed */
const KER_MATRIX_SUM_ALL = "" /* 3536 byte string literal not displayed */
const KER_MATRIX_TRANS = "" /* 1475 byte string literal not displayed */

func AddToBuff Uses

func AddToBuff(ptr cu.DevicePtr)

AddToBuff Adds a memory allocated by cu.MemAlloc to the memory used on this memory space

func Apply Uses

func Apply(m [][]float64, f func(x float64) float64) (rm [][]float64)

Apply a function to all the elements of a matrix, the function will receive a float64 as param and returns a float64 too

func Cofactors Uses

func Cofactors(m [][]float64) (rm [][]float64)

Cofactors Returns the cofactors matrix TODO Implement using CUDA

func Concat Uses

func Concat(m1 [][]float64, m2 [][]float64) (rm [][]float64)

Concat Concatenates two matrix elements, ex: m1 = (M111, M112, M113)

(M121, M122, M123)
(M131, M132, M133)

m2 = (M211, M212, M213)

(M221, M222, M223)
(M231, M232, M233)

rm = (M111, M112, M113, M221, M222, M223)

(M121, M122, M123, M221, M222, M223)
(M131, M132, M133, M231, M232, M233)

func CudaMemAlloc Uses

func CudaMemAlloc(bytes int64) cu.DevicePtr

CudaMemAlloc Allocated memory in the CUDA device and returns a pointer to the allocated memory space

func CudaSync Uses

func CudaSync()

CudaSync Blocks until the CUDA device has completed all preceding requested tasks

func Det Uses

func Det(m [][]float64) (rm float64)

Det Calculates the determinant of the matrix TODO Implement using CUDA

func Div Uses

func Div(m1 [][]float64, m2 [][]float64) (rm [][]float64)

Div Divide the first matrix by the second one TODO Implement using CUDA

func FreeAllMem Uses

func FreeAllMem()

FreeAllMem Releases all the memory allocated in all the namespaces

func FreeMem Uses

func FreeMem()

FreeMem Releases the memory allocated in the current namespace

func InitCuda Uses

func InitCuda()

InitCuda Initialize the CUDA driver, and loads all the CUDA kernels on the graphic card

func Inv Uses

func Inv(m [][]float64) (rm [][]float64)

Inv Calculates the inverse matrix TODO Implement using CUDA

func Minors Uses

func Minors(m [][]float64) (rm [][]float64)

Minors Returns the minors matrix TODO Implement using CUDA

func MoveToCuda Uses

func MoveToCuda(m [][]float64, p *CudaMatrix)

MoveToCuda Moves a two dimensional array from the memory of the machine to the memory of the CUDA device on a previously initialized CudaMatrix struct

func SetDefaultBuff Uses

func SetDefaultBuff()

SetDefaultBuff Sets the default buffer to be used

func SetDevice Uses

func SetDevice(dev int)

SetDevice Specify the CUDA device to be used, 0 by default

func StartBufferingMem Uses

func StartBufferingMem(buff string)

StartBufferingMem Specifies a namespace to be used in order to define a space in memory, this namespace will be used by the garbage collector in order to release memory. @see FreeAllMem, FreeMem methods

func SumAll Uses

func SumAll(m [][]float64) (rm float64)

SumAll all the elements in a matrix

type CudaMatrix Uses

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

CudaMatrix This struct represents a matrix allocated in the memory of the CUDA device

func CudaSub Uses

func CudaSub(m1 *CudaMatrix, m2 *CudaMatrix) (rm *CudaMatrix)

CudaSub Matrix subtraction, returns the result in a new CudaMatrix allocating memory on the CUDA device to store it

func CudaSubTo Uses

func CudaSubTo(m1 *CudaMatrix, m2 *CudaMatrix, rm *CudaMatrix) *CudaMatrix

CudaSubTo Matrix subtraction, returns the result in the provided Cuda Matrix without need to allocate new memory to store it

func CudaSum Uses

func CudaSum(m1 *CudaMatrix, m2 *CudaMatrix) (rm *CudaMatrix)

CudaSum Sums two matrices, returns the result in a new CudaMatrix allocating memory on the CUDA device to store it

func CudaSumTo Uses

func CudaSumTo(m1 *CudaMatrix, m2 *CudaMatrix, rm *CudaMatrix) *CudaMatrix

CudaSumTo Sums two matrices and returns the result in the provided Cuda Matrix without need to allocate new memory to store it

func GetCudaMatrix Uses

func GetCudaMatrix(m [][]float64) (p *CudaMatrix)

GetCudaMatrix Initilizes and returns a CudaMatrix struct allocating the necessary memory on the cuda device, and copying from the machine memory to the CUDA device memory the especified matrix

func InitCudaMatrix Uses

func InitCudaMatrix(w int, h int) (m *CudaMatrix)

InitCudaMatrix Initializes a CUDA matrix struct allocating all the necesary memory on the CUDA device

func Mult Uses

func Mult(m1 *CudaMatrix, m2 *CudaMatrix) (rm *CudaMatrix)

Mult Multiplies two matrices, and returns the result in a new CudaMatrix allocating memory to store the result on the CUDA device memory

func MultAllElems Uses

func MultAllElems(m1 *CudaMatrix, m2 *CudaMatrix) (rm *CudaMatrix)

MultAllElems Multiplies one by one all the elements of two matrices, and returns the result in a new allocated matrix on the CUDA device memory ex:

1 2 3 4 5 * 1 2 3 4 5 --> 1 4 9 16 25
1 2 3 4 5 * 1 2 3 4 5 --> 1 4 9 16 25
1 2 3 4 5 * 1 2 3 4 5 --> 1 4 9 16 25

func MultAllElemsTo Uses

func MultAllElemsTo(m1 *CudaMatrix, m2 *CudaMatrix, rm *CudaMatrix) *CudaMatrix

MultAllElemsTo Multiplies one by one all the elements of two matrices, and uses the allocated memory on the third specified matrix to store the result, this method is much more faster than allocate new memory for the result, and can reutilize previously allocated memory on the CUDA device ex:

1 2 3 4 5 * 1 2 3 4 5 --> 1 4 9 16 25
1 2 3 4 5 * 1 2 3 4 5 --> 1 4 9 16 25
1 2 3 4 5 * 1 2 3 4 5 --> 1 4 9 16 25

func MultTo Uses

func MultTo(m1 *CudaMatrix, m2 *CudaMatrix, rm *CudaMatrix) *CudaMatrix

MultTo Multiplies two matrices, and returns the result in the given CudaMatrix without allocate memory on the CUDA device

func MultTrans Uses

func MultTrans(m1 *CudaMatrix, m2 *CudaMatrix) (rm *CudaMatrix)

MultTrans Multiply a CudaMatrix by the transpose of another CudaMatrix and returns the result in a new CudaMatrix allocating memory on the CUDA device to store it

func MultTransTo Uses

func MultTransTo(m1 *CudaMatrix, m2 *CudaMatrix, rm *CudaMatrix) *CudaMatrix

MultTransTo Multiply a CudaMatrix by the transpose of another CudaMatrix and returns the result in the provided CudaMatrix without need to allocate new memory to store it

func (*CudaMatrix) AddBias Uses

func (m *CudaMatrix) AddBias() (rm *CudaMatrix)

AddBias Method for machine learning: Adds a bias column setted to one to a given CudaMatrix and returns a new CudaMatrix allocating memory on the CUDA device to store the resulting matrix ex:

1 2 3 4 5  --> 1 2 3 4 5 1
1 2 3 4 5  --> 1 2 3 4 5 1
1 2 3 4 5  --> 1 2 3 4 5 1

func (*CudaMatrix) AddBiasTo Uses

func (m *CudaMatrix) AddBiasTo(rm *CudaMatrix) *CudaMatrix

AddBiasTo Method for machine learning: Adds a bias column setted to one to a given CudaMatrix and stores the result in the given matrix withouth allocate new memory on the CUDA device ex:

1 2 3 4 5  --> 1 2 3 4 5 1
1 2 3 4 5  --> 1 2 3 4 5 1
1 2 3 4 5  --> 1 2 3 4 5 1

func (*CudaMatrix) AddBiasTop Uses

func (m *CudaMatrix) AddBiasTop() (rm *CudaMatrix)

AddBiasTop Method for machine learning: Adds a new row at the top of the matrix filled by 1's, and returns a new CudaMatrix allocating the necessary memory on the CUDA device ex:

           --> 1 1 1 1 1
1 2 3 4 5  --> 1 2 3 4 5
1 2 3 4 5  --> 1 2 3 4 5

func (*CudaMatrix) AddBiasTopTo Uses

func (m *CudaMatrix) AddBiasTopTo(rm *CudaMatrix) *CudaMatrix

AddBiasTopTo Method for machine learning: Adds a new row at the top of the matrix filled by 1's, stores the result in the given CudaMatrix without allocate memory on the CUDA device if is not necessary ex:

           --> 1 1 1 1 1
1 2 3 4 5  --> 1 2 3 4 5
1 2 3 4 5  --> 1 2 3 4 5

func (*CudaMatrix) Copy Uses

func (m *CudaMatrix) Copy() (r *CudaMatrix)

Copy Returns a copy of the cuda matrix in a new memory allocated space inside the same device. This operation is performed internally in the CUDA device

func (*CudaMatrix) CopyTo Uses

func (m *CudaMatrix) CopyTo(t *CudaMatrix) *CudaMatrix

CopyTo Copy a cuda matrix to a previously memory allocated cuda matrix, this copy operation is performed internally in the CUDA device

func (*CudaMatrix) Free Uses

func (m *CudaMatrix) Free()

Free Removes all the memory used to allocate a CudaMatrix

func (*CudaMatrix) GetMatrixFromCuda Uses

func (m *CudaMatrix) GetMatrixFromCuda() (r [][]float64)

GetMatrixFromCuda Returns a two domensional array that represents a matrix allocated on the machine memory from a CudaMatrix. Downloads a matrix from the CUDA device

func (*CudaMatrix) H Uses

func (m *CudaMatrix) H() int

H Returns the number of rows on a cuda matrix

func (*CudaMatrix) Log Uses

func (m *CudaMatrix) Log() *CudaMatrix

Log Apply the log to all the elements of the CudaMatrix

func (*CudaMatrix) MultBy Uses

func (m *CudaMatrix) MultBy(by float64) *CudaMatrix

MultBy Multiply all the elements of a matrix by a given float and returns a new CudaMatrix allocating memory on the CUDA device to store the result

func (*CudaMatrix) Neg Uses

func (m *CudaMatrix) Neg() *CudaMatrix

Neg Negates all the elements of the CudaMatrix ex:

1 2 3 4 5 --> -1 -2 -3 -4 -5
1 2 3 4 5 --> -1 -2 -3 -4 -5

func (*CudaMatrix) OneMinus Uses

func (m *CudaMatrix) OneMinus() *CudaMatrix

OneMinus Applies 1 - n where n is each element of the matrix on the same given CudaMatrix ex:

1 2 3 4 5 --> 0 -1 -2 -3 -4
1 2 3 4 5 --> 0 -1 -2 -3 -4

func (*CudaMatrix) PowTwo Uses

func (m *CudaMatrix) PowTwo() *CudaMatrix

PowTwo Multiplies all the elements of a CudaMatrix by themselves

func (*CudaMatrix) RemoveBias Uses

func (m *CudaMatrix) RemoveBias() (rm *CudaMatrix)

RemoveBias Method for machine learning: Removes the last column of a matrix and returns a new CudaMatrix performing the memory allocation in the CUDA device ex:

1 2 3 4 5 1  --> 1 2 3 4 5
1 2 3 4 5 1  --> 1 2 3 4 5
1 2 3 4 5 1  --> 1 2 3 4 5

func (*CudaMatrix) RemoveBiasTo Uses

func (m *CudaMatrix) RemoveBiasTo(rm *CudaMatrix) *CudaMatrix

RemoveBiasTo Method for machine learning: Removes the last column of a matrix and uses the given CudaMatrix to allocate the result, if the CudaMatrix CUDA memory was previously allocates, reuses the memory without need to perform an alocation ex:

1 2 3 4 5 1  --> 1 2 3 4 5
1 2 3 4 5 1  --> 1 2 3 4 5
1 2 3 4 5 1  --> 1 2 3 4 5

func (*CudaMatrix) RemoveBiasTop Uses

func (m *CudaMatrix) RemoveBiasTop() (rm *CudaMatrix)

RemoveBiasTop Method for machine learning: Removes a bias row from the top of the given matrix, and stores the result on the given CudaMatrix without allocate new memory on the CUDA device ex:

1 1 1 1 1  -->
1 2 3 4 5  --> 1 2 3 4 5
1 2 3 4 5  --> 1 2 3 4 5

func (*CudaMatrix) RemoveBiasTopTo Uses

func (m *CudaMatrix) RemoveBiasTopTo(rm *CudaMatrix) *CudaMatrix

RemoveBiasTopTo Method for machine learning: Removes a bias row from the top of the given matrix, and stores the result on the given CudaMatrix without allocate new memory on the CUDA device ex:

1 1 1 1 1
1 2 3 4 5  --> 1 2 3 4 5
1 2 3 4 5  --> 1 2 3 4 5

func (*CudaMatrix) SetBiasToZero Uses

func (m *CudaMatrix) SetBiasToZero() *CudaMatrix

SetBiasToZero Method for machine learning: Sets the right column to zero, this transformation is applied directly in the same CudaMatrix ex:

1 2 3 4 5 1 --> 1 2 3 4 5 0
1 2 3 4 5 1 --> 1 2 3 4 5 0
1 2 3 4 5 1 --> 1 2 3 4 5 0

func (*CudaMatrix) SetPosTo Uses

func (m *CudaMatrix) SetPosTo(val float64, x int, y int) *CudaMatrix

SetPosTo Modifies the value on a position given by the x and y coordinates by the given value on a cuda matrix

func (*CudaMatrix) Sigmoid Uses

func (m *CudaMatrix) Sigmoid() *CudaMatrix

Sigmoid Applies the sigmoid function to all the elements of the CudaMatrix with z as element: 1.0 / (1.0 + exp(-z));

func (*CudaMatrix) SigmoidGradient Uses

func (m *CudaMatrix) SigmoidGradient() *CudaMatrix

SigmoidGradient Applies the sigmoid gradient to all the elements of the CudaMatrix with z as element: sigmoid(z) * (1 - sigmoid(z));

func (*CudaMatrix) SumAll Uses

func (m *CudaMatrix) SumAll() float64

SumAll Returns the sum of all the elements in a CudaMatrix ex: 1 2 3 4 5 6 7 8 9 10 --> 55

func (*CudaMatrix) Trans Uses

func (m *CudaMatrix) Trans() (rm *CudaMatrix)

Trans Transposes a CudaMatrix and stores the result in a new CudaMatrix allocating the necessary memory on the CUDA device to it

func (*CudaMatrix) TransOneDimMatrix Uses

func (m *CudaMatrix) TransOneDimMatrix() *CudaMatrix

TransOneDimMatrix Transposes a one dimensional CudaMatrix, this method doesn't performs any operation in the CUDA device, and is recomended to transform 1D matrices ex:

1 2 3 --> 1
      --> 2
      --> 3

func (*CudaMatrix) TransTo Uses

func (m *CudaMatrix) TransTo(rm *CudaMatrix) *CudaMatrix

TransTo Transposes a CudaMatrix and stores the result in the provided CudaMatrix, if the CudaMatrix points to a previously allocated memory on the CUDA device, doesn't allocate new memory for the result

func (*CudaMatrix) W Uses

func (m *CudaMatrix) W() int

W Returns the number of columns on a cuda matrix

Package mt imports 3 packages (graph). Updated 2017-11-23. Refresh now. Tools for package owners.