Apache Singa
A General Distributed Deep Learning Library
Classes | Typedefs | Functions | Variables
singa Namespace Reference

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. More...

Classes

struct  _Context
 
class  Accuracy
 Compute the accuray of the prediction, which is matched against the ground truth labels. More...
 
class  AdaGrad
 
class  Block
 Block represent a chunk of memory (on device or host). More...
 
class  Channel
 Channel for appending metrics or other information into files or screen. More...
 
class  ChannelManager
 
class  Constraint
 Apply constraints for parameters (gradient). More...
 
class  CppCPU
 Represent a CPU device which may have multiple threads/executors. More...
 
class  CSVDecoder
 Decode the string of csv formated data into data tensor (dtype is kFloat32) and optionally a label tensor (dtype is kInt). More...
 
class  CSVEncoder
 Convert values from tensors into a csv formated string. More...
 
class  Decoder
 The base decoder that converts a string into a set of tensors. More...
 
class  Device
 Allocate memory and execute Tensor operations. More...
 
class  DeviceMemPool
 
class  Encoder
 Base encoder class that convert a set of tensors into string for storage. More...
 
class  FeedForwardNet
 The feed-forward neural net. More...
 
class  ImageTransformer
 
class  Initializer
 
class  Layer
 The base layer class. More...
 
class  LocalUpdater
 LocalUpdater do gradient aggregation and update gradient calling the wrapped Optimizer on a specific device (i.e., CPU or GPU). More...
 
class  Loss
 The base loss class, which declares the APIs for computing the objective score (loss) for a pair of prediction (from the model) and the target (i.e. More...
 
class  Metric
 The base metric class, which declares the APIs for computing the performance evaluation metrics given the prediction of the model and the ground truth, i.e., the target. More...
 
class  MSE
 MSE is for mean squared error or squared euclidean distance. More...
 
class  Nesterov
 
class  Optimizer
 The base class for gradient descent algorithms used to update the model parameters in order to optimize the objective (loss) function. More...
 
class  Platform
 This class queries all available calculating devices on a given machine grouped according to manufacturer or device drivers. More...
 
class  Regularizer
 Apply regularization for parameters (gradient), e.g., L1 norm and L2 norm. More...
 
class  RMSProp
 
class  Scheduler
 Scheduling Tensor operations with dependency detection. More...
 
class  SGD
 
class  Snapshot
 The snapshot management. More...
 
class  SoftmaxCrossEntropy
 Softmax + cross entropy for multi-category classification. More...
 
class  Tensor
 A Tensor instance is a multi-dimensional array resident on a Device (default device is the host CPU). More...
 
class  Timer
 For benchmarking the time cost of operations. More...
 
class  Tokenizer
 Tokenize a string. More...
 
class  Transformer
 Base apply class that does data transformations in pre-processing stage. More...
 
class  Updater
 Basic Updater class just forward all the method function call to the wrapped Optimizer. More...
 
class  VirtualMemory
 Manage device memory pool including garbage collection, memory opt. More...
 

Typedefs

typedef struct singa::_Context Context
 
typedef vector< size_t > Shape
 
using InitializerConf = FillerConf
 Base class for initializing parameter values.
 

Functions

size_t SizeOf (DataType t)
 
size_t Product (const Shape &shape, int start=0, size_t len=0)
 
void CheckDataTypeAndLang (const Tensor &in1, const Tensor &in2)
 
template<typename FromType , typename ToType >
ToType TypeCast (const FromType &x)
 
Tensor Boradcast (const Shape &shape)
 
Tensor Reshape (const Tensor &in, const Shape &s)
 Reshape the given tensor and generate a new tensor; the total vol should match which shares the memory with in if possible.
 
Tensor Resize (const Tensor &in, const Shape &s)
 
Tensor Transpose (const Tensor &in)
 Reverse the shape vector.
 
Tensor Broadcast (const Tensor &in, const Shape &shape)
 Return a view of the input tensor whose shape is broadcasted to be compitable with the given shape.
 
Tensor Transpose (const Tensor &in, const vector< size_t > &axes)
 Change the axes.
 
void CopyDataToFrom (Tensor *dst, const Tensor &src, const size_t num, const size_t dst_offset=0, const size_t src_offset=0)
 Copy 'num' elements of src to dst. More...
 
void RepeatDataToFrom (bool broadcast_flag, const vector< size_t > &repeats, int axis, Tensor *dst, const Tensor &in, const size_t num)
 
Tensor Abs (const Tensor &in)
 
Tensor Exp (const Tensor &in)
 
Tensor Log (const Tensor &in)
 
Tensor ReLU (const Tensor &in)
 
Tensor Sigmoid (const Tensor &in)
 
Tensor Sign (const Tensor &in)
 
Tensor Sqrt (const Tensor &in)
 
Tensor Square (const Tensor &in)
 
Tensor Tanh (const Tensor &in)
 
Tensor Transform (const Tensor &in)
 
void Abs (const Tensor &in, Tensor *out)
 
void Exp (const Tensor &in, Tensor *out)
 
void Log (const Tensor &in, Tensor *out)
 
void ReLU (const Tensor &in, Tensor *out)
 
void Sigmoid (const Tensor &in, Tensor *out)
 
void Sign (const Tensor &in, Tensor *out)
 
void Sqrt (const Tensor &in, Tensor *out)
 
void Square (const Tensor &in, Tensor *out)
 
void Tanh (const Tensor &in, Tensor *out)
 
void Transform (const Tensor &in, Tensor *out)
 
template<typename SType >
Tensor Pow (const Tensor &in, const SType x)
 Element-wise opeartion, out[i]=in[i]^x.
 
template<typename SType >
void Pow (const Tensor &in, const SType x, Tensor *out)
 Element-wise opeartion, out[i]=in[i]^x.
 
Tensor Pow (const Tensor &base, const Tensor &exp)
 Element-wise opeartion, out[i]=baes[i]^exp[i].
 
void Pow (const Tensor &base, const Tensor &exp, Tensor *out)
 Element-wise opeartion, out[i]=baes[i]^exp[i].
 
template<typename SType >
Tensor operator< (const Tensor &in, const SType x)
 Element-wise operation, out[i]= (in[i] < x) ? 1.f : 0.f.
 
template<typename SType >
void LT (const Tensor &in, const SType x, Tensor *out)
 
Tensor operator< (const Tensor &in1, const Tensor &in2)
 Element-wise operation, out[i]= (in1[i] < in2[i]) ? 1.f : 0.f.
 
void LT (const Tensor &in1, const Tensor &in2, Tensor *out)
 
template<typename SType >
Tensor operator<= (const Tensor &in, const SType x)
 Element-wise operation, out[i]= (in[i] <= x) ? 1.f : 0.f.
 
template<typename SType >
void LE (const Tensor &in, const SType x, Tensor *out)
 
Tensor operator<= (const Tensor &in1, const Tensor &in2)
 Element-wise operation, out[i]= (in1[i] <= in2[i]) ? 1.f : 0.f.
 
void LE (const Tensor &in1, const Tensor &in2, Tensor *out)
 
template<typename SType >
Tensor operator> (const Tensor &in, const SType x)
 Element-wise operation, out[i]= (in[i] > x) ? 1.f : 0.f.
 
template<typename SType >
void GT (const Tensor &in, const SType x, Tensor *out)
 
Tensor operator> (const Tensor &in1, const Tensor &in2)
 Element-wise operation, out[i]= (in1[i] > in2[i]) ? 1.f : 0.f.
 
void GT (const Tensor &in1, const Tensor &in2, Tensor *out)
 
template<typename SType >
Tensor operator>= (const Tensor &in, const SType x)
 Element-wise operation, out[i]= (in[i] >= x) ? 1.f : 0.f.
 
template<typename SType >
void GE (const Tensor &in, const SType x, Tensor *out)
 
Tensor operator>= (const Tensor &in1, const Tensor &in2)
 Element-wise operation, out[i]= (in1[i] >= in2[i]) ? 1.f : 0.f.
 
void GE (const Tensor &in1, const Tensor &in2, Tensor *out)
 
Tensor operator+ (const Tensor &lhs, const Tensor &rhs)
 
void Add (const Tensor &lhs, const Tensor &rhs, Tensor *out)
 
Tensor operator- (const Tensor &lhs, const Tensor &rhs)
 
void Sub (const Tensor &lhs, const Tensor &rhs, Tensor *out)
 
Tensor operator* (const Tensor &lhs, const Tensor &rhs)
 
void EltwiseMult (const Tensor &lhs, const Tensor &rhs, Tensor *out)
 
Tensor operator/ (const Tensor &lhs, const Tensor &rhs)
 
void Div (const Tensor &lhs, const Tensor &rhs, Tensor *out)
 
template<typename SType >
Tensor operator+ (const Tensor &in, const SType x)
 
template<typename SType >
void Add (const Tensor &in, const SType x, Tensor *out)
 
template<typename SType >
Tensor operator- (const Tensor &in, const SType x)
 
template<typename SType >
void Sub (const Tensor &in, const SType x, Tensor *out)
 
template<typename SType >
Tensor operator* (const Tensor &in, const SType x)
 
template<typename SType >
void EltwiseMult (const Tensor &in, const SType x, Tensor *out)
 
template<typename SType >
Tensor operator/ (const Tensor &in, const SType x)
 For each element e of Tensor 'in', compute e / x.
 
template<typename SType >
void Div (const Tensor &in, const SType x, Tensor *out)
 For each element e of Tensor 'in', compute e / x into out.
 
template<typename SType >
Tensor Div (const SType x, const Tensor &in)
 For each element e of Tensor 'in', compute x/e.
 
template<typename SType >
void Div (const SType x, const Tensor &in, Tensor *out)
 For each element e of Tensor 'in', compute x/e into 'out'.
 
template<typename SType = float>
SType Sum (const Tensor &in)
 
Tensor Average (const Tensor &in, const int axis)
 Average elements in the Tensor, currently only support vector and matrix. More...
 
void AddColumn (const Tensor &v, Tensor *M)
 Add column 'v' with each column of matrix M.
 
template<typename SType >
void AddColumn (const SType alpha, const SType beta, const Tensor &v, Tensor *out)
 For each column 'c' of matrix out, do c=alpha*v + beta*c.
 
void AddRow (const Tensor &v, Tensor *out)
 Add row 'v' with each row of matrix M; write results into 'out'.
 
template<typename SType >
void AddRow (const SType alpha, const SType beta, const Tensor &v, Tensor *M)
 For each row 'r' of matrix out, do r=alpha*v + beta*r.
 
void DivColumn (const Tensor &v, Tensor *M)
 Divide column 'v' by each column of matrix M; write results into 'out'.
 
void DivRow (const Tensor &v, Tensor *M)
 Divide row 'v' by each row of matrix M; write results into 'out'.
 
void MultColumn (const Tensor &v, Tensor *M)
 Multiply column 'v' and each column of matrix M; write results into 'out'.
 
void MultRow (const Tensor &v, Tensor *M)
 Multiply row 'v' with each row of matrix M; write results into 'out'.
 
Tensor SoftMax (const Tensor &in)
 Do softmax for each row. 'in' could be a 1-d or 2-d Tensor.
 
Tensor RowMax (const Tensor &in)
 
void SoftMax (const Tensor &in, Tensor *out)
 Do softmax for each row. 'in' could be a 1-d or 2-d Tensor.
 
void SubColumn (const Tensor &v, Tensor *M)
 Sub column 'v' by each column of matrix M.
 
void SubRow (const Tensor &v, Tensor *M)
 Sub row 'v' by each row of matrix M; write results into 'out'.
 
void SumColumns (const Tensor &M, Tensor *out)
 Sum all columns of matrix M into a single column as 'out'.
 
void SumRows (const Tensor &M, Tensor *out)
 Sum all rows of matrix M into a single row as 'out'.
 
Tensor Sum (const Tensor &in, const int axis)
 Sum elements in the Tensor, currently only support vector and matrix. More...
 
template<typename SType >
void Bernoulli (const SType p, Tensor *out)
 For each element x set x = 1 if random() < p; otherwise x = 1.
 
template<typename SType >
void Gaussian (const SType mean, const SType std, Tensor *out)
 Fill in Tensor 't' following Gaussian distribution.
 
template<typename SType >
void Uniform (const SType low, const SType high, Tensor *out)
 Fill in Tensor 't' following uniform distribution.
 
template<typename SType >
void Axpy (SType alpha, const Tensor &in, Tensor *out)
 out = alpha*in + out
 
Tensor Mult (const Tensor &A, const Tensor &B)
 Do matrix vector multipication or matrix matrix multiplication depdending on the Tensor shape. More...
 
void Mult (const Tensor &A, const Tensor &B, Tensor *C)
 Do matrix vector multipication or matrix matrix multiplication depdending on the Tensor shape. More...
 
template<typename SType >
void Mult (const SType alpha, const Tensor &A, const Tensor &B, const SType beta, Tensor *C)
 Do matrix vector multipication or matrix matrix multiplication depdending on the Tensor shape. More...
 
void ComputeCrossEntropy (const Tensor &p, const Tensor &t, Tensor *loss)
 Compute the cross entropy loss given the prediction probability 'p' and the target (ground truth) labels 't'. More...
 
void SoftmaxCrossEntropyBwd (const Tensor &t, Tensor *p)
 Compute the dx, given prediction probability 'p' (p=softmax(x)) and the target (ground truth) labels 't'. More...
 
Tensor CrossEntropyFwd (const Tensor &p, const Tensor &t)
 To be called by pysinga autograd operations; swig ignores the const qualifier http://www.swig.org/Doc3.0/SWIGPlus.html#SWIGPlus_const.
 
Tensor SoftmaxCrossEntropyBwd (const Tensor &p, const Tensor &t)
 
Tensor CopyRows (const Tensor &in, const size_t start, const size_t end)
 Return a tensor consisting of rows ([start, end)) from 'in'. More...
 
Tensor SliceRows (const Tensor &in, const size_t start, const size_t end)
 Alias of CopyRows.
 
Tensor SliceOn (const Tensor &in, const size_t start, const size_t end, int axis)
 Slice the input tensor along the give axis to generate a new tensor.
 
Tensor CopyColumns (const Tensor &in, const size_t start, const size_t end)
 Return a tensor consisting of columns ([start, end)) from 'in'. More...
 
Tensor SliceColumns (const Tensor &in, const size_t start, const size_t end)
 Alias of CopyColumns.
 
Tensor ConcatenateRows (const vector< Tensor > &in)
 Return a tensor which is vertically stacked from tensors in 'in'. More...
 
Tensor ConcatOn (const std::vector< Tensor > &in, int axis)
 Return a tensor concatenated of the input tensors along the give axis.
 
Tensor ConcatRows (const vector< Tensor > &in)
 Alias name for function ConcatenateRows.
 
Tensor ConcatenateColumns (const vector< Tensor > &in)
 Return a tensor which is horizontally stacked from tensors in 'in'. More...
 
Tensor ConcatColumns (const vector< Tensor > &in)
 Alias name for function ConcatenateColumns.
 
Tensor crop (Tensor &input, const size_t crop_height, const size_t crop_width, const size_t crop_h_offset, const size_t crop_w_offset, const string &image_dim_order)
 
Tensor mirror (Tensor &input, const bool horizontal_mirror, const bool vertical_mirror, const string &image_dim_order)
 
std::shared_ptr< InitializerCreateInitializer (const InitializerConf &conf)
 TODO(wangwei) create the initializers from factory like that for Layer.
 
std::shared_ptr< LayerCreateLayer (const std::string type)
 
const std::vector< std::string > GetRegisteredLayers ()
 
std::shared_ptr< ConstraintCreateConstraint (std::string type)
 
std::shared_ptr< RegularizerCreateRegularizer (std::string type)
 
std::shared_ptr< OptimizerCreateOptimizer (const string &type)
 
void InitChannel (const char *argv)
 Initial function for global usage of channel. More...
 
void SetChannelDirectory (const char *path)
 Set the directory name for persisting channel content.
 
ChannelGetChannel (const std::string &channel_name)
 Get the channel instance.
 
void InitLogging (const char *argv)
 Global functions for both glog and built-in log.
 
void LogToStderr ()
 Make it so that all log messages go only to stderr.
 
void SetStderrLogging (int severity)
 Make it so that all log messages of at least a particular severity are logged to stderr (in addtion to logging to the usual log files)
 
void SetLogDestination (int severity, const char *path)
 Set the file name for logging (and disable logging to stderr)
 
mkldnn::memory::data_type GetMKLDNNDataType (DataType dtype)
 
bool icasecmp (const string &l, const string &r)
 
string ToLowerCase (const string &input)
 
int ArgPos (int argc, char **arglist, const char *arg)
 
template<typename T >
std::string VecToStr (const std::vector< T > &in)
 

Variables

std::shared_ptr< DevicedefaultDevice
 a singleton CppDevice as the host for all devices.
 
const size_t kDataWidth []
 hardcode the width of types defined in DataType More...
 
const int INFO = 0
 
const int WARNING = 1
 
const int ERROR = 2
 
const int FATAL = 3
 
const int NUM_SEVERITIES = 4
 

Detailed Description

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ Average()

Tensor singa::Average ( const Tensor in,
const int  axis 
)

Average elements in the Tensor, currently only support vector and matrix.

if 'axis' is 0, average all rows into a single row if 'axis' is 1, average all columns into a single column TODO(wangwei) support arbitrary Tensor like numpy.average

◆ ComputeCrossEntropy()

void singa::ComputeCrossEntropy ( const Tensor p,
const Tensor t,
Tensor loss 
)

Compute the cross entropy loss given the prediction probability 'p' and the target (ground truth) labels 't'.

'p' could be either a 1-d vector for a single instance or a 2-d matrix for a batch of instances. t[i] could be the ground truth label index or a label weighted array of the i-th instance. For example, if there are 3 candidate labels for each instance, t[i] could be 2 or [0, 0, 1]. If one instance could have multiple labels, then t[i] could be [1, 0, 1]. The loss is computed into p.

◆ ConcatenateColumns()

Tensor singa::ConcatenateColumns ( const vector< Tensor > &  in)

Return a tensor which is horizontally stacked from tensors in 'in'.

Each tensor in 'in' is a 2D tensor. Values are copied, no memory sharing.

◆ ConcatenateRows()

Tensor singa::ConcatenateRows ( const vector< Tensor > &  in)

Return a tensor which is vertically stacked from tensors in 'in'.

Each tensor in 'in' is a 2D tensor. Values are copied, no memory sharing.

◆ CopyColumns()

Tensor singa::CopyColumns ( const Tensor in,
const size_t  start,
const size_t  end 
)

Return a tensor consisting of columns ([start, end)) from 'in'.

It copies the values from 'in'. 'in' is a 2D Tensor.

◆ CopyDataToFrom()

void singa::CopyDataToFrom ( Tensor dst,
const Tensor src,
const size_t  num,
const size_t  dst_offset = 0,
const size_t  src_offset = 0 
)

Copy 'num' elements of src to dst.

The first 'src_offset' ('dst_offset') elements will be skipped.

◆ CopyRows()

Tensor singa::CopyRows ( const Tensor in,
const size_t  start,
const size_t  end 
)

Return a tensor consisting of rows ([start, end)) from 'in'.

It copies the values from 'in'. 'in' ia a 2D Tensor.

◆ InitChannel()

void singa::InitChannel ( const char *  argv)

Initial function for global usage of channel.

'argv' is for future use.

◆ Mult() [1/3]

Tensor singa::Mult ( const Tensor A,
const Tensor B 
)

Do matrix vector multipication or matrix matrix multiplication depdending on the Tensor shape.

result = A * B

◆ Mult() [2/3]

void singa::Mult ( const Tensor A,
const Tensor B,
Tensor C 
)

Do matrix vector multipication or matrix matrix multiplication depdending on the Tensor shape.

C = A * B

◆ Mult() [3/3]

template<typename SType >
void singa::Mult ( const SType  alpha,
const Tensor A,
const Tensor B,
const SType  beta,
Tensor C 
)

Do matrix vector multipication or matrix matrix multiplication depdending on the Tensor shape.

out = alpha lhs * rhs + beta * out

◆ SoftmaxCrossEntropyBwd()

void singa::SoftmaxCrossEntropyBwd ( const Tensor t,
Tensor p 
)

Compute the dx, given prediction probability 'p' (p=softmax(x)) and the target (ground truth) labels 't'.

'p' and 't' are either 1-d vector or 2-d matrix. 'grad' has the same shape as 'p'. dx is computed into p.

◆ Sum()

Tensor singa::Sum ( const Tensor in,
const int  axis 
)

Sum elements in the Tensor, currently only support vector and matrix.

if 'axis' is 0, sum all rows into a single row if 'axis' is 1, sum all columns into a single column TODO(wangwei) support arbitrary Tensor like numpy.sum

Variable Documentation

◆ kDataWidth

const size_t singa::kDataWidth[]
Initial value:
= {sizeof(float), sizeof(float) / 2,
sizeof(int), sizeof(char),
sizeof(double), sizeof(unsigned char)
}

hardcode the width of types defined in DataType