mod_input_layer¶
Implementation of input layers for a neural network. author: Alexander Knoll
Non-OpenMP parallelized forward pass implementation for the input layer.
This routine is very efficient for small batchsizes. Non OpenMP parallelized forward gradient pass implementation for the input layer.
This routine is very efficient for small batchsizes.
Dependencies¶
Derived Types Summary¶
| Name | Description |
|---|---|
InputLayer |
An input layer for a feed-forward neural network. The output of this layer is calculated as $a... |
Procedures Summary¶
| Name | Type | Description |
|---|---|---|
init_inputlayer |
Subroutine | Construct a new InputLayer object. |
reset_inputlayer |
Subroutine | Reset a InputLayer object. Should be called before any new backward pass. |
reset_prediction_inputlayer |
Subroutine | Reset all forward-pass related arrays, but keep the collected gradients. Should be called before... |
reallocate_inputlayer |
Subroutine | Change the dimensions of all internal arrays to accomodate batchsize input and output values. |
print_inputlayer |
Subroutine | Print information about an InputLayer object. |
forward_inputlayer |
Subroutine | Entry point for input layer forward passes. This is the top-level routine for forward passes... |
forward_gradient_inputlayer |
Subroutine | Entry point for input layer forward gradient passes. See <a... |
forward_inputlayer_omp_parallel |
Subroutine | OMP-parallel input layer forward pass implementation. The OMP-parallelization in this routine... |
forward_gradient_inputlayer_omp_parallel |
Subroutine | OMP-parallel input layer forward gradient pass implementation. See <a... |
forward_inputlayer_serial |
Subroutine | |
forward_gradient_inputlayer_serial |
Subroutine | |
backward_inputlayer |
Subroutine | |
backward_gradient_inputlayer |
Subroutine |
Derived Types Details¶
type InputLayer¶
An input layer for a feed-forward neural network.
The output of this layer is calculated as \(a = f(x)\) where - \(x \in \R^(N_b, N_x)\) is the input vector to the layer - \(f: \R\to\R\) is a vector of activation functions, which can be different for each node. - \(a \in \R^(N_b, N_x)\) is the activation vector of the layer i.e. the output. This layer does not have any trainable parameters.
Components
-
num_nodes: integer– Inherited from InputLayer -
batchsize: integer– Inherited from InputLayer -
x: real(DP) (dim: (:,:))– The input to this layer, which is stored temporarily to be reused during a backward pass. -
z: real(DP) (dim: (:,:))– Pre-activations, the node values before application of the activation function. -
a: real(DP) (dim: (:,:))– Activations, the node values after application of the activation function. This is the output of the layer. -
dz_dq: real(DP) (dim: (:,:))– Derivatives of the pre-activations with respect to `q` during forward-mode differentiation. -
da_dq: real(DP) (dim: (:,:))– Derivatives of the activations with respect to `q` during forward-mode differentiation. -
grad: real(DP) (dim: (:,:))– The gradient passing through the layer during a backward pass. Usually this is the derivative of the loss function with respect to the activation of the layer preceeding this one. As there is no preceeding layer, this is simply the derivative of the loss function with respect to the input of the network. -
dgrad_dq: real(DP) (dim: (:,:))– Inherited from InputLayer -
forward_ptr: procedure– Pointer for delegating the forward pass to the correct implementation. We have an OpenMP-parallel and a non-parallel forward pass implementation. The serial implementation is more efficient for small batchsizes. We align the pointer whenever reallocate_inputlayer is called, which is usually only once. -
forward_gradient_ptr: procedure– Pointer for delegating the forward gradient pass. See forward_ptr for details.
Type-Bound Procedures
| Name | Attributes | Binding |
|---|---|---|
| initialize | public | ⇒ init_inputlayer |
| public | ⇒ print_inputlayer | |
| reallocate | public | ⇒ reallocate_inputlayer |
| reset | public | ⇒ reset_inputlayer |
| reset_prediction | public | ⇒ reset_prediction_inputlayer |
| forward_inputlayer_omp_parallel | private | ⇒ forward_inputlayer_omp_parallel |
| forward_inputlayer_serial | private | ⇒ forward_inputlayer_serial |
| forward_gradient_inputlayer_omp_parallel | private | ⇒ forward_gradient_inputlayer_omp_parallel |
| forward_gradient_inputlayer_serial | private | ⇒ forward_gradient_inputlayer_serial |
| forward | public | ⇒ forward_inputlayer |
| forward_gradient | public | ⇒ forward_gradient_inputlayer |
| backward | public | ⇒ backward_inputlayer |
| backward_gradient | public | ⇒ backward_gradient_inputlayer |
Inherited By
Procedure Details¶
subroutine init_inputlayer¶
subroutine init_inputlayer( &
self, &
num_nodes, &
batchsize &
)
Construct a new InputLayer object.
Arguments
-
self: class(InputLayer) [inout]– The constructed layer. -
num_nodes: integer [in]– The number of input features, i.e. the size of the layer. -
batchsize: integer [in]– How many samples can pass through the layer concurrently.
Called By
subroutine reset_inputlayer¶
subroutine reset_inputlayer( &
self &
)
Reset a InputLayer object. Should be called before any new
backward pass.
Arguments
-
self: class(InputLayer) [inout]
Called By
subroutine reset_prediction_inputlayer¶
subroutine reset_prediction_inputlayer( &
self &
)
Reset all forward-pass related arrays, but keep the collected gradients. Should be called before any new forward pass.
Arguments
-
self: class(InputLayer) [inout]
Called By
subroutine reallocate_inputlayer¶
subroutine reallocate_inputlayer( &
self, &
batchsize &
)
Change the dimensions of all internal arrays to accomodate
batchsize input and output values.
Arguments
-
self: class(InputLayer) [inout] -
batchsize: integer [in]
Called By
subroutine print_inputlayer¶
subroutine print_inputlayer( &
self &
)
Print information about an InputLayer object.
Arguments
-
self: class(InputLayer) [in]
subroutine forward_inputlayer¶
subroutine forward_inputlayer( &
self, &
x &
)
Entry point for input layer forward passes.
This is the top-level routine for forward passes that is exposed as the
public interface of this type. It is a wrapper routine that delegates the
forward call to one of the two forward implementations. See
forward_ptr for details.
Arguments
-
self: class(InputLayer) [inout] -
x: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]
Called By
subroutine forward_gradient_inputlayer¶
subroutine forward_gradient_inputlayer( &
self, &
x, &
dx_dq &
)
Entry point for input layer forward gradient passes.
See forward_inputlayer for details.
Arguments
-
self: class(InputLayer) [inout] -
x: real(DP) (dim: (self%num_nodes,self%batchsize)) [in] -
dx_dq: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]
Called By
subroutine forward_inputlayer_omp_parallel¶
subroutine forward_inputlayer_omp_parallel( &
self, &
x &
)
OMP-parallel input layer forward pass implementation.
The OMP-parallelization in this routine is only efficient for larger batchsizes. For small batchsizes, the overhead of thread initialization becomes too large. In those cases, use forward_inputlayer_serial.
Arguments
-
self: class(InputLayer) [inout] -
x: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]
subroutine forward_gradient_inputlayer_omp_parallel¶
subroutine forward_gradient_inputlayer_omp_parallel( &
self, &
x, &
dx_dq &
)
OMP-parallel input layer forward gradient pass implementation.
See forward_inputlayer_omp_parallel fpr details.
Arguments
-
self: class(InputLayer) [inout] -
x: real(DP) (dim: (self%num_nodes,self%batchsize)) [in] -
dx_dq: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]
subroutine forward_inputlayer_serial¶
subroutine forward_inputlayer_serial( &
self, &
x &
)
Arguments
-
self: class(InputLayer) [inout] -
x: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]
subroutine forward_gradient_inputlayer_serial¶
subroutine forward_gradient_inputlayer_serial( &
self, &
x, &
dx_dq &
)
Arguments
-
self: class(InputLayer) [inout] -
x: real(DP) (dim: (self%num_nodes,self%batchsize)) [in] -
dx_dq: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]
subroutine backward_inputlayer¶
subroutine backward_inputlayer( &
self, &
grad &
)
Arguments
-
self: class(InputLayer) [inout] -
grad: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]
subroutine backward_gradient_inputlayer¶
subroutine backward_gradient_inputlayer( &
self, &
grad, &
dgrad_dq &
)
Arguments
-
self: class(InputLayer) [inout] -
grad: real(DP) (dim: (self%num_nodes,self%batchsize)) [in] -
dgrad_dq: real(DP) (dim: (self%num_nodes,self%batchsize)) [in]