Apache SINGA
A distributed deep learning platform .
 All Classes Namespaces Files Functions Variables Typedefs Macros
Namespaces | Classes | Typedefs | Functions | Variables
mshadow Namespace Reference

namespace for mshadow More...

Namespaces

 expr
 namespace for abstract expressions and expressions template, have no dependecy on tensor.h, These data structure takes no charge in computations, they are only used to define operations and represent expression in a symbolic way
 
 op
 operations for algorithm
 
 red
 namespace for potential reducer operations
 
 sse2
 namespace to support sse2 vectorization
 
 sv
 namespace for savers
 
 utils
 namespace for helper utils of the project
 

Classes

struct  Shape
 shape of a tensor IMPORTANT NOTE: this shape is different from numpy.shape shape[0] gives the lowest dimension, shape[dimension-1] gives the highest dimension shape[k] corresponds to k-th dimension of tensor More...
 
struct  cpu
 device name CPU More...
 
struct  gpu
 device name CPU More...
 
struct  Tensor
 general tensor More...
 
struct  Tensor< Device, 1 >
 
class  TensorContainer
 tensor container that does memory allocation and resize like STL, use it to save the lines of FreeSpace in class. Do not abuse it, efficiency can come from pre-allocation and no re-allocation More...
 
struct  MapExpCPUEngine
 
struct  MapExpCPUEngine< false, SV, dim, E, etype >
 
struct  MapExpCPUEngine< true, SV, dim, E, etype >
 
class  Random
 random number generator More...
 
class  Random< cpu >
 CPU random number generator. More...
 

Typedefs

typedef float real_t
 type that will be used for content
 
typedef unsigned index_t
 type that will be used for index
 

Functions

MSHADOW_XINLINE Shape< 1 > Shape1 (index_t s0)
 construct a one dimension shape, stride will equal s0 More...
 
MSHADOW_XINLINE Shape< 2 > Shape2 (index_t s1, index_t s0)
 construct a two dimension shape, stride will equal s0 More...
 
MSHADOW_XINLINE Shape< 3 > Shape3 (index_t s2, index_t s1, index_t s0)
 construct a three dimension shape, stride will equal s0 More...
 
MSHADOW_XINLINE Shape< 4 > Shape4 (index_t s3, index_t s2, index_t s1, index_t s0)
 construct a four dimension shape, stride will equal s0 More...
 
void InitTensorEngine (int device_id=0)
 initialize tensor engine, used to call intialization functions of dependent libs this function should be called before all GPU tensor operations, for using tensors in CPU, this call is actually not needed More...
 
void ShutdownTensorEngine (void)
 Shutdown tensor engine, this function should be called after all GPU tensor operations, for using tensors in CPU, this call is actually not needed.
 
template<int dim>
void AllocSpace (Tensor< cpu, dim > &obj, bool pad=MSHADOW_ALLOC_PAD)
 CPU/CPU: allocate space for CTensor, according to the shape in the obj this function is responsible to set the stride_ in each obj.shape. More...
 
template<int dim>
void AllocSpace (Tensor< gpu, dim > &obj, bool pad=MSHADOW_ALLOC_PAD)
 refer to comment of cpu ver More...
 
template<int dim>
void FreeSpace (Tensor< cpu, dim > &obj)
 CPU/GPU: free the space of tensor, will set obj.dptr to NULL. More...
 
template<int dim>
void FreeSpace (Tensor< gpu, dim > &obj)
 refer to comment of cpu ver More...
 
template<typename Device , int dim>
Tensor< Device, dim > NewTensor (const Shape< dim > &shape, real_t initv, bool pad=MSHADOW_ALLOC_PAD)
 CPU/GPU: short cut to allocate and initialize a Tensor. More...
 
template<int dim>
void Copy (Tensor< cpu, dim > dst, const Tensor< cpu, dim > &src)
 copy data from one tensor to another, with same shape More...
 
template<int dim>
void Copy (Tensor< cpu, dim > dst, const Tensor< gpu, dim > &src)
 refer to comment of cpu ver More...
 
template<int dim>
void Copy (Tensor< gpu, dim > dst, const Tensor< cpu, dim > &src)
 refer to comment of cpu ver More...
 
template<int dim>
void Copy (Tensor< gpu, dim > dst, const Tensor< gpu, dim > &src)
 refer to comment of cpu ver More...
 
void Softmax (Tensor< cpu, 2 > dst, const Tensor< cpu, 2 > &energy)
 CPU/GPU: normalize softmax: dst[i][j] = exp( energy[i][j] ) /( sum_j exp( energy[i][j] ) ) More...
 
void Softmax (Tensor< gpu, 2 > dst, const Tensor< gpu, 2 > &energy)
 refer to comment of cpu ver More...
 
template<typename Saver , int dim, typename E , int etype>
void MapExp (Tensor< cpu, dim > dst, const expr::Exp< E, etype > &exp)
 CPU/GPU: map a expression to a tensor, this function calls MapPlan. More...
 
template<typename Saver , int dim, typename E , int etype>
void MapExp (Tensor< gpu, dim > dst, const expr::Exp< E, etype > &exp)
 refer to comment of cpu ver More...
 
template<typename Saver , typename Reducer , typename E , int etype>
void MapReduceKeepLowest (Tensor< cpu, 1 > dst, const expr::Exp< E, etype > &exp, real_t scale=1.0f)
 CPU/GPU: map a expression, do reduction to 1D Tensor in lowest dimension (dimension 0) More...
 
template<typename Saver , typename Reducer , typename E , int etype>
void MapReduceKeepLowest (Tensor< gpu, 1 > dst, const expr::Exp< E, etype > &exp, real_t scale=1.0f)
 refer to comment of cpu ver More...
 
template<typename Saver , typename Reducer , int dimkeep, typename E , int etype>
void MapReduceKeepHighDim (Tensor< cpu, 1 > dst, const expr::Exp< E, etype > &exp, real_t scale=1.0f)
 CPU/GPU: map a expression, do reduction to 1D Tensor in third dimension (dimension 2) More...
 
template<typename Saver , typename Reducer , int dimkeep, typename E , int etype>
void MapReduceKeepHighDim (Tensor< gpu, 1 > dst, const expr::Exp< E, etype > &exp, real_t scale=1.0f)
 refer to comment of cpu ver More...
 
template<typename Saver , typename E , int dim>
void MapPlan (Tensor< cpu, dim > _dst, const expr::Plan< E > &plan)
 
void Softmax (Tensor< cpu, 1 > dst, const Tensor< cpu, 1 > &energy)
 
template<typename A , typename B , int dim>
void Copy (Tensor< A, dim > _dst, Tensor< B, dim > _src, cudaMemcpyKind kind)
 
template<int dim, typename TStream >
void SaveBinary (TStream &fo, const Tensor< cpu, dim > &src)
 CPU/GPU: save a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allocated. More...
 
template<int dim, typename TStream >
void SaveBinary (TStream &fo, const Tensor< gpu, dim > &src)
 refer to comment of cpu ver More...
 
template<int dim, typename TStream >
void LoadBinary (TStream &fi, Tensor< cpu, dim > &dst, bool pre_alloc)
 CPU/GPU: load a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allocated if pre_alloc is true , then space in dst is preallocated, and must have same shape of the tensor loaded if pre_alloc is false, then dst originally does not have space allocated, LoadBinary will allocate space for dst. More...
 
template<int dim, typename TStream >
void LoadBinary (TStream &fi, Tensor< gpu, dim > &dst, bool pre_alloc)
 refer to comment of cpu ver More...
 
template<typename SV , typename E , int dim>
void MapSSEPlan (Tensor< cpu, dim > _dst, const expr::SSEPlan< E > &plan)
 use SSEPlan to compute result
 

Variables

const unsigned kRandBufferSize = 1000000
 buffer size for each random number generator
 
const float kPi = 3.1415926f
 pi
 

Detailed Description

namespace for mshadow

Function Documentation

template<int dim>
void mshadow::AllocSpace ( Tensor< cpu, dim > &  obj,
bool  pad = MSHADOW_ALLOC_PAD 
)
inline

CPU/CPU: allocate space for CTensor, according to the shape in the obj this function is responsible to set the stride_ in each obj.shape.

Template Parameters
dimspecify the dim of tensor
Parameters
objthe tensor object, with shape specified
padwhether padding dimension 0, to make last dimension aligned, padding may help improve efficiency of matrix multiplications if true, will allocate space with stride_ that may not equals shape[0] if false, will allocate continuous space
template<int dim>
void mshadow::AllocSpace ( Tensor< gpu, dim > &  obj,
bool  pad = MSHADOW_ALLOC_PAD 
)
inline

refer to comment of cpu ver

See Also
AllocSpace
template<int dim>
void mshadow::Copy ( Tensor< cpu, dim >  dst,
const Tensor< cpu, dim > &  src 
)
inline

copy data from one tensor to another, with same shape

Template Parameters
dimspecify the dim of tensor
Parameters
dsttarget tensor
srcsource tensor
template<int dim>
void mshadow::Copy ( Tensor< cpu, dim >  dst,
const Tensor< gpu, dim > &  src 
)
inline

refer to comment of cpu ver

See Also
Copy
template<int dim>
void mshadow::Copy ( Tensor< gpu, dim >  dst,
const Tensor< cpu, dim > &  src 
)
inline

refer to comment of cpu ver

See Also
Copy
template<int dim>
void mshadow::Copy ( Tensor< gpu, dim >  dst,
const Tensor< gpu, dim > &  src 
)
inline

refer to comment of cpu ver

See Also
Copy
template<int dim>
void mshadow::FreeSpace ( Tensor< cpu, dim > &  obj)
inline

CPU/GPU: free the space of tensor, will set obj.dptr to NULL.

Template Parameters
dimspecify the dim of tensor
Parameters
objthe tensor object
template<int dim>
void mshadow::FreeSpace ( Tensor< gpu, dim > &  obj)
inline

refer to comment of cpu ver

See Also
FreeSpace
void mshadow::InitTensorEngine ( int  device_id = 0)
inline

initialize tensor engine, used to call intialization functions of dependent libs this function should be called before all GPU tensor operations, for using tensors in CPU, this call is actually not needed

Parameters
device_idGPU device id to be choosed
template<int dim, typename TStream >
void mshadow::LoadBinary ( TStream &  fi,
Tensor< cpu, dim > &  dst,
bool  pre_alloc 
)
inline

CPU/GPU: load a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allocated if pre_alloc is true , then space in dst is preallocated, and must have same shape of the tensor loaded if pre_alloc is false, then dst originally does not have space allocated, LoadBinary will allocate space for dst.

Parameters
fioutput binary stream
dstdestination file
pre_allocwhether space is pre-allocated, if false, space allocation will happen
Template Parameters
dimdimension of tensor
TStreamtype of stream, need to support Read, Write, one example is utils::IStream.
template<int dim, typename TStream >
void mshadow::LoadBinary ( TStream &  fi,
Tensor< gpu, dim > &  dst,
bool  pre_alloc 
)
inline

refer to comment of cpu ver

See Also
LoadBinary
template<typename Saver , int dim, typename E , int etype>
void mshadow::MapExp ( Tensor< cpu, dim >  dst,
const expr::Exp< E, etype > &  exp 
)
inline

CPU/GPU: map a expression to a tensor, this function calls MapPlan.

Template Parameters
Saverspecify storage method
dimdim of the tensor, during usage, there is no need to specify this parameter
Especifies the expression type, not need to specify this parameter during usage
etypeexpression type
Parameters
dstdestination
expexpression
See Also
namespace mshadow:sv, mshadow::op, mshadow::expr
template<typename Saver , int dim, typename E , int etype>
void mshadow::MapExp ( Tensor< gpu, dim >  dst,
const expr::Exp< E, etype > &  exp 
)
inline

refer to comment of cpu ver

See Also
MapExp
template<typename Saver , typename Reducer , int dimkeep, typename E , int etype>
void mshadow::MapReduceKeepHighDim ( Tensor< cpu, 1 >  dst,
const expr::Exp< E, etype > &  exp,
real_t  scale = 1.0f 
)
inline

CPU/GPU: map a expression, do reduction to 1D Tensor in third dimension (dimension 2)

Template Parameters
Saverspecify storage method
Reducerspecify a reducer method
Especifies the expression type, not need to specify this parameter during usage
dimkeepthe target dimension to be kept, should be larger than 0, for 0, use MapReduceKeepLowest
etypeexpression type
Parameters
dstdestination
expexpression
scalescale the result before save
See Also
namespace mshadow:sv, mshadow::op, mshadow::red, mshadow::expr
template<typename Saver , typename Reducer , int dimkeep, typename E , int etype>
void mshadow::MapReduceKeepHighDim ( Tensor< gpu, 1 >  dst,
const expr::Exp< E, etype > &  exp,
real_t  scale = 1.0f 
)
inline

refer to comment of cpu ver

See Also
MapReduceKeepHighDim
template<typename Saver , typename Reducer , typename E , int etype>
void mshadow::MapReduceKeepLowest ( Tensor< cpu, 1 >  dst,
const expr::Exp< E, etype > &  exp,
real_t  scale = 1.0f 
)
inline

CPU/GPU: map a expression, do reduction to 1D Tensor in lowest dimension (dimension 0)

Template Parameters
Saverspecify storage method
Reducerspecify a reducer method
Especifies the expression type, not need to specify this parameter during usage
etypeexpression type
Parameters
dstdestination
expexpression
scalescale the result before save
See Also
namespace mshadow:sv, mshadow::op, mshadow::red, mshadow::expr
template<typename Saver , typename Reducer , typename E , int etype>
void mshadow::MapReduceKeepLowest ( Tensor< gpu, 1 >  dst,
const expr::Exp< E, etype > &  exp,
real_t  scale = 1.0f 
)
inline

refer to comment of cpu ver

See Also
MapReduceKeepLowest
template<typename Device , int dim>
Tensor< Device, dim > mshadow::NewTensor ( const Shape< dim > &  shape,
real_t  initv,
bool  pad = MSHADOW_ALLOC_PAD 
)
inline

CPU/GPU: short cut to allocate and initialize a Tensor.

Template Parameters
Devicedevice of tensor
dimdimention of tensor
Parameters
shapeshape of tensor
initvinitialization value
pad: padding option
See Also
AllocSpace
template<int dim, typename TStream >
void mshadow::SaveBinary ( TStream &  fo,
const Tensor< cpu, dim > &  src 
)
inline

CPU/GPU: save a tensor by binary format, for GPU version, a temp Tensor<cpu,dim> storage will be allocated.

Parameters
fooutput binary stream
srcsource data file
Template Parameters
dimdimension of tensor
TStreamtype of stream, need to support Read, Write, one example is utils::IStream.
template<int dim, typename TStream >
void mshadow::SaveBinary ( TStream &  fo,
const Tensor< gpu, dim > &  src 
)
inline

refer to comment of cpu ver

See Also
SaveBinary
MSHADOW_XINLINE Shape<1> mshadow::Shape1 ( index_t  s0)

construct a one dimension shape, stride will equal s0

Parameters
s0size of dimension 0
Returns
the shape construction
MSHADOW_XINLINE Shape<2> mshadow::Shape2 ( index_t  s1,
index_t  s0 
)

construct a two dimension shape, stride will equal s0

Parameters
s1size of dimension 1
s0size of dimension 0
Returns
the shape construction
MSHADOW_XINLINE Shape<3> mshadow::Shape3 ( index_t  s2,
index_t  s1,
index_t  s0 
)

construct a three dimension shape, stride will equal s0

Parameters
s2size of dimension 2
s1size of dimension 1
s0size of dimension 0
Returns
the shape construction
MSHADOW_XINLINE Shape<4> mshadow::Shape4 ( index_t  s3,
index_t  s2,
index_t  s1,
index_t  s0 
)

construct a four dimension shape, stride will equal s0

Parameters
s3size of dimension 3
s2size of dimension 2
s1size of dimension 1
s0size of dimension 0
Returns
the shape construction
void mshadow::Softmax ( Tensor< cpu, 2 >  dst,
const Tensor< cpu, 2 > &  energy 
)
inline

CPU/GPU: normalize softmax: dst[i][j] = exp( energy[i][j] ) /( sum_j exp( energy[i][j] ) )

Parameters
dstdestination
energyinput energy
void mshadow::Softmax ( Tensor< gpu, 2 >  dst,
const Tensor< gpu, 2 > &  energy 
)
inline

refer to comment of cpu ver

See Also
Softmax