LCOV - code coverage report
Current view: top level - nntrainer/layers - grucell.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 3 3
Test Date: 2025-12-14 20:38:17 Functions: 100.0 % 4 4

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2021 hyeonseok lee <hs89.lee@samsung.com>
       4              :  *
       5              :  * @file   grucell.h
       6              :  * @date   28 Oct 2021
       7              :  * @brief  This is Gated Recurrent Unit Cell Layer Class of Neural Network
       8              :  * @see    https://github.com/nnstreamer/nntrainer
       9              :  * @author hyeonseok lee <hs89.lee@samsung.com>
      10              :  * @bug    No known bugs except for NYI items
      11              :  *
      12              :  */
      13              : 
      14              : #ifndef __GRUCELL_H__
      15              : #define __GRUCELL_H__
      16              : #ifdef __cplusplus
      17              : 
      18              : #include <acti_func.h>
      19              : #include <common_properties.h>
      20              : #include <layer_impl.h>
      21              : 
      22              : namespace nntrainer {
      23              : 
      24              : /**
      25              :  * @class   GRUCellLayer
      26              :  * @brief   GRUCellLayer
      27              :  */
      28              : class GRUCellLayer : public LayerImpl {
      29              : public:
      30              :   /**
      31              :    * @brief     Constructor of GRUCellLayer
      32              :    */
      33              :   GRUCellLayer();
      34              : 
      35              :   /**
      36              :    * @brief     Destructor of GRUCellLayer
      37              :    */
      38          122 :   ~GRUCellLayer() = default;
      39              : 
      40              :   /**
      41              :    *  @brief  Move constructor.
      42              :    *  @param[in] GRUCellLayer &&
      43              :    */
      44              :   GRUCellLayer(GRUCellLayer &&rhs) noexcept = default;
      45              : 
      46              :   /**
      47              :    * @brief  Move assignment operator.
      48              :    * @parma[in] rhs GRUCellLayer to be moved.
      49              :    */
      50              :   GRUCellLayer &operator=(GRUCellLayer &&rhs) = default;
      51              : 
      52              :   /**
      53              :    * @copydoc Layer::finalize(InitLayerContext &context)
      54              :    */
      55              :   void finalize(InitLayerContext &context) override;
      56              : 
      57              :   /**
      58              :    * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
      59              :    */
      60              :   void forwarding(RunLayerContext &context, bool training) override;
      61              : 
      62              :   /**
      63              :    * @copydoc Layer::calcDerivative(RunLayerContext &context)
      64              :    */
      65              :   void calcDerivative(RunLayerContext &context) override;
      66              : 
      67              :   /**
      68              :    * @copydoc Layer::calcGradient(RunLayerContext &context)
      69              :    */
      70              :   void calcGradient(RunLayerContext &context) override;
      71              : 
      72              :   /**
      73              :    * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
      74              :    * method)
      75              :    */
      76              :   void exportTo(Exporter &exporter,
      77              :                 const ml::train::ExportMethods &method) const override;
      78              : 
      79              :   /**
      80              :    * @copydoc Layer::getType()
      81              :    */
      82          775 :   const std::string getType() const override { return GRUCellLayer::type; };
      83              : 
      84              :   /**
      85              :    * @copydoc Layer::supportBackwarding()
      86              :    */
      87           70 :   bool supportBackwarding() const override { return true; }
      88              : 
      89              :   /**
      90              :    * @copydoc Layer::setProperty(const PropertyType type, const std::string
      91              :    * &value)
      92              :    */
      93              :   void setProperty(const std::vector<std::string> &values) override;
      94              : 
      95              :   /**
      96              :    * @copydoc Layer::setBatch(RunLayerContext &context, unsigned int batch)
      97              :    */
      98              :   void setBatch(RunLayerContext &context, unsigned int batch) override;
      99              : 
     100              :   static constexpr const char *type = "grucell";
     101              : 
     102              : private:
     103              :   static constexpr unsigned int NUM_GATE = 3;
     104              :   enum INOUT_INDEX {
     105              :     INPUT = 0,
     106              :     INPUT_HIDDEN_STATE = 1,
     107              :     OUTPUT = 0,
     108              :   };
     109              : 
     110              :   /**
     111              :    * Unit: number of output neurons
     112              :    * IntegrateBias: integrate bias_ih, bias_hh to bias_h
     113              :    * ResetAfter: Whether apply reset gate before/after the matrix
     114              :    * multiplication. Apply reset gate after the mulplication if true.
     115              :    * HiddenStateActivation: activation type for hidden state. default is tanh
     116              :    * RecurrentActivation: activation type for recurrent. default is sigmoid
     117              :    * DropOutRate: dropout rate
     118              :    *
     119              :    * */
     120              :   std::tuple<props::Unit, props::IntegrateBias, props::ResetAfter,
     121              :              props::HiddenStateActivation, props::RecurrentActivation,
     122              :              props::DropOutRate>
     123              :     grucell_props;
     124              :   std::array<unsigned int, 7> wt_idx; /**< indices of the weights */
     125              : 
     126              :   /**
     127              :    * @brief     activation function for h_t : default is sigmoid
     128              :    */
     129              :   ActiFunc acti_func;
     130              : 
     131              :   /**
     132              :    * @brief     activation function for recurrent : default is tanh
     133              :    */
     134              :   ActiFunc recurrent_acti_func;
     135              : 
     136              :   /**
     137              :    * @brief     to protect overflow
     138              :    */
     139              :   float epsilon;
     140              : };
     141              : } // namespace nntrainer
     142              : 
     143              : #endif /* __cplusplus */
     144              : #endif /* __GRUCELL_H__ */
        

Generated by: LCOV version 2.0-1