nnlib
GPU-accelerated, C/C++ neural network library.
Functions
tensor_operations_on_host.h File Reference

Header file declaring tensor operations that happen on host. More...

#include <tensor.h>

Go to the source code of this file.

Functions

void sumTensorOnHost (const Tensor &tensor, Tensor &destination)
 Sum all values of a tensor. More...
 
void fillTensorOnHost (Tensor &tensor, float value)
 Fill a tensor with a constant value. More...
 
void fillTensorOnHost (Tensor &tensor, const Tensor &value)
 
void addTensorsOnHost (const Tensor &a, const Tensor &b, Tensor &destination)
 Element-wise add two tensors. More...
 
void subtractTensorsOnHost (const Tensor &a, const Tensor &b, Tensor &destination)
 Subtract one tensor from another. More...
 
void hadamardTensorsOnHost (const Tensor &a, const Tensor &b, Tensor &destination)
 Perform hadamard product (element-wise multiplication) between two tensors. More...
 
void divideTensorsOnHost (const Tensor &a, const Tensor &b, Tensor &destination)
 Divide one tensor by another. More...
 
void logTensorOnHost (const Tensor &a, Tensor &destination)
 Apply natural logarithm to each element of the tensor. More...
 
void addBroadcastOnHost (const Tensor &matrix, const Tensor &vector, Tensor &destination)
 Perform the broadcast-add operation. More...
 
void multiplyTensorOnHost (const Tensor &tensor, float constant, Tensor &destination)
 Multiply a tensor with a constant. More...
 
void multiplyMatrixVectorOnHost (const Tensor &matrix, const Tensor &vector, Tensor &destination)
 Multiply a matrix with a vector. More...
 
void multiplyMatrixMatrixOnHost (const Tensor &m1, const Tensor &m2, Tensor &destination)
 Multiply a matrix with a matrix. More...
 
void transposeMatrixOnHost (const Tensor &matrix, Tensor &destination)
 Transpose a matrix. More...
 
void reluTensorOnHost (const Tensor &tensor, Tensor &destination)
 
void reluDerivativeTensorOnHost (const Tensor &tensor, Tensor &destination)
 
void sigmoidTensorOnHost (const Tensor &tensor, Tensor &destination)
 

Detailed Description

Header file declaring tensor operations that happen on host.

The methods declared in this file are only called when all operands are located on the CPU.

These methods do not perform any checking with regards to the size or location of the operands. This is already done in the corresponding methods in tensor.cpp.

Author
Jan Warchocki
Date
29 August 2022

Function Documentation

◆ addBroadcastOnHost()

void addBroadcastOnHost ( const Tensor matrix,
const Tensor vector,
Tensor destination 
)

Perform the broadcast-add operation.

Parameters
matrixThe matrix tensor.
vectorThe vector tensor.
destinationWhere the result of the addition should be stored.

◆ addTensorsOnHost()

void addTensorsOnHost ( const Tensor a,
const Tensor b,
Tensor destination 
)

Element-wise add two tensors.

Parameters
aThe first tensor.
bThe second tensor.
destinationWhere the result of the addition should be stored.

◆ divideTensorsOnHost()

void divideTensorsOnHost ( const Tensor a,
const Tensor b,
Tensor destination 
)

Divide one tensor by another.

Parameters
aThe tensor to divide.
bThe tensor to divide by.
destinationWhere the result of the operation should be stored.

◆ fillTensorOnHost()

void fillTensorOnHost ( Tensor tensor,
float  value 
)

Fill a tensor with a constant value.

Parameters
tensorThe tensor to fill.
valueThe value to fill the tensor with.

◆ hadamardTensorsOnHost()

void hadamardTensorsOnHost ( const Tensor a,
const Tensor b,
Tensor destination 
)

Perform hadamard product (element-wise multiplication) between two tensors.

Parameters
aThe first tensor.
bThe second tensor.
destinationWhere the result of the operation should be stored.

◆ logTensorOnHost()

void logTensorOnHost ( const Tensor a,
Tensor destination 
)

Apply natural logarithm to each element of the tensor.

Parameters
aThe tensor to apply natural logarithm to.
destinationWhere the result of the operation should be stored.

◆ multiplyMatrixMatrixOnHost()

void multiplyMatrixMatrixOnHost ( const Tensor m1,
const Tensor m2,
Tensor destination 
)

Multiply a matrix with a matrix.

Parameters
m1The first matrix tensor.
m2The second matrix tensor.
destinationWhere the result of the multiplication should be stored.

◆ multiplyMatrixVectorOnHost()

void multiplyMatrixVectorOnHost ( const Tensor matrix,
const Tensor vector,
Tensor destination 
)

Multiply a matrix with a vector.

Parameters
matrixThe matrix tensor.
vectorThe vector tensor.
destinationWhere the result of the multiplication should be stored.

◆ multiplyTensorOnHost()

void multiplyTensorOnHost ( const Tensor tensor,
float  constant,
Tensor destination 
)

Multiply a tensor with a constant.

Parameters
tensorThe tensor to multiply.
constantThe constant to multiply with.
destinationWhere the result of the multiplication should be stored.

◆ subtractTensorsOnHost()

void subtractTensorsOnHost ( const Tensor a,
const Tensor b,
Tensor destination 
)

Subtract one tensor from another.

Parameters
aThe tensor to subtract from.
bThe tensor to be subtracted.
destinationWhere the result of the subtraction should be stored.

◆ sumTensorOnHost()

void sumTensorOnHost ( const Tensor tensor,
Tensor destination 
)

Sum all values of a tensor.

Parameters
tensorThe tensor to sum.
Returns
The sum of all values of a tensor.

◆ transposeMatrixOnHost()

void transposeMatrixOnHost ( const Tensor matrix,
Tensor destination 
)

Transpose a matrix.

Parameters
matrixThe matrix vector to transpose.
destinationWhere the result of the transpose operation should be stored.