DLPrimitives
Public Member Functions | Protected Attributes | List of all members
dlprim::Operator Class Referenceabstract

Base class for backward/forward propogation calculations for internal network. More...

#include <include/dlprim/operator.hpp>

Inheritance diagram for dlprim::Operator:
dlprim::Activation dlprim::BatchNorm dlprim::Concat dlprim::Convolution2D dlprim::Elementwise dlprim::GlobalPooling dlprim::InnerProduct dlprim::MSELoss dlprim::NLLLoss dlprim::PointwiseBase dlprim::Pooling2D dlprim::ReshapeBase dlprim::Slice dlprim::Softmax dlprim::SoftmaxWithLoss dlprim::TransposedConvolution2D

Public Member Functions

 Operator (Context const &ctx)
 Create operator for specific context (device/platform)
 
SharedResourceshared_resource ()
 Getter for object that is shared between operators accross the net, for example random numbers generator.
 
void shared_resource (std::shared_ptr< SharedResource > r)
 Setter of the shared resource.
 
virtual char const * operator_type () const =0
 name of the operator type
 
virtual void mode (CalculationsMode mode)
 Can be called with both train and predict before setup() is called. afterwards if original mode was train - it can be switched to predict and back but if original mode was predict it can't be switched to train. More...
 
virtual CalculationsMode mode ()
 get current mode
 
 Operator (Operator const &)=delete
 operator non-copyable/moveable More...
 
void operator= (Operator const &)=delete
 
 Operator (Operator &&)=delete
 
void operator= (Operator &&)=delete
 
virtual bool alias_generator ()
 returns true of the operator is alias - generation - it only changes the shape of tensor but not its content it actually does not perform any operation but only changes semantics, in this casse input and output are aliases of each other
 
virtual void initialize_params (std::vector< Tensor > &, ExecutionContext const &)
 Set default parameters iniitalization.
 
virtual void setup (std::vector< TensorSpecs > const &in, std::vector< TensorSpecs > &out, std::vector< TensorSpecs > &parameters, size_t &workspace)=0
 Convigure operator. More...
 
virtual void reshape (std::vector< Shape > const &in, std::vector< Shape > &out, size_t &workspace)=0
 Reshape layer according to new input size. More...
 
virtual void forward (std::vector< Tensor > &input, std::vector< Tensor > &output, std::vector< Tensor > &parameters, Tensor &workspace, ExecutionContext const &ctx)=0
 Enqueue forward propogation computations. More...
 
virtual void backward (std::vector< TensorAndGradient > &, std::vector< TensorAndGradient > &, std::vector< TensorAndGradient > &, Tensor &, ExecutionContext const &)
 Enqueue backward propogation computations. More...
 

Protected Attributes

Context ctx_
 OpenCL/CPU Context to work with.
 
CalculationsMode mode_
 computaions mode
 
std::shared_ptr< SharedResourceshared_resource_
 

Detailed Description

Base class for backward/forward propogation calculations for internal network.

Constructor & Destructor Documentation

dlprim::Operator::Operator ( Operator const &  )
delete

operator non-copyable/moveable

manage it with smart pointers

Member Function Documentation

virtual void dlprim::Operator::backward ( std::vector< TensorAndGradient > &  ,
std::vector< TensorAndGradient > &  ,
std::vector< TensorAndGradient > &  ,
Tensor ,
ExecutionContext const &   
)
inlinevirtual

Enqueue backward propogation computations.

Parameters
input- inputs and their gradients marked for computatins
output- outputs and their gradients
parameters- parameters parameters and their gradients
workspace- workspace as required
ctx- execution context

Note: actual inputs are

  • inputs[index].data
  • outputs[index].data
  • outputs[index].diff
  • parameters[index].data

And it computes in backpropogation

  • inputs[index].diff
  • parameters[index].diff

If computation is not needed TensorAndGradient::requires_gradient need to be set to false

Reimplemented in dlprim::TransposedConvolution2D, dlprim::GlobalPooling, dlprim::SoftmaxWithLoss, dlprim::Slice, dlprim::Convolution2D, dlprim::Pooling2D, dlprim::Concat, dlprim::Softmax, dlprim::Elementwise, dlprim::BatchNorm, dlprim::InnerProduct, dlprim::MSELoss, dlprim::NLLLoss, dlprim::Activation, dlprim::ReshapeBase, and dlprim::PointwiseBase.

virtual void dlprim::Operator::forward ( std::vector< Tensor > &  input,
std::vector< Tensor > &  output,
std::vector< Tensor > &  parameters,
Tensor workspace,
ExecutionContext const &  ctx 
)
pure virtual

Enqueue forward propogation computations.

Parameters
input- input tesnosrs (X)
output- output tesnors (Y)
parameters- parameters for computation
workspace- workspace as required
ctx- execution context

Implemented in dlprim::TransposedConvolution2D, dlprim::GlobalPooling, dlprim::SoftmaxWithLoss, dlprim::Slice, dlprim::Convolution2D, dlprim::Pooling2D, dlprim::Concat, dlprim::Softmax, dlprim::Elementwise, dlprim::BatchNorm, dlprim::InnerProduct, dlprim::MSELoss, dlprim::NLLLoss, dlprim::Activation, dlprim::ReshapeBase, and dlprim::PointwiseBase.

virtual void dlprim::Operator::mode ( CalculationsMode  mode)
inlinevirtual

Can be called with both train and predict before setup() is called. afterwards if original mode was train - it can be switched to predict and back but if original mode was predict it can't be switched to train.

Default is predict

Reimplemented in dlprim::BatchNorm.

virtual void dlprim::Operator::reshape ( std::vector< Shape > const &  in,
std::vector< Shape > &  out,
size_t &  workspace 
)
pure virtual
virtual void dlprim::Operator::setup ( std::vector< TensorSpecs > const &  in,
std::vector< TensorSpecs > &  out,
std::vector< TensorSpecs > &  parameters,
size_t &  workspace 
)
pure virtual

Convigure operator.

Parameters
in- a list of expected input tensors
out- a list of output tensots - that opertor calculates in fwd propogation
parameters- a list of parameters need for computation. If parameter should not participate in gradient desend it should be marked as not trainable
workspacesize needed for computations in bytes - not preserved between different calls

Implemented in dlprim::TransposedConvolution2D, dlprim::GlobalPooling, dlprim::SoftmaxWithLoss, dlprim::Slice, dlprim::Convolution2D, dlprim::Pooling2D, dlprim::Concat, dlprim::Softmax, dlprim::Elementwise, dlprim::BatchNorm, dlprim::InnerProduct, dlprim::MSELoss, dlprim::NLLLoss, dlprim::Activation, dlprim::ReshapeBase, and dlprim::PointwiseBase.


The documentation for this class was generated from the following file: