LCOV - code coverage report
Current view: top level - nntrainer/layers - matmul_layer.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 85.7 % 14 12
Test Date: 2025-12-14 20:38:17 Functions: 83.3 % 6 5

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2025 SeungBaek Hong <sb92.hong@samsung.com>
       4              :  *
       5              :  * @file   matmul_layer.h
       6              :  * @date   26 March 2025
       7              :  * @see    https://github.com/nnstreamer/nntrainer
       8              :  * @author SeungBaek Hong <sb92.hong@samsung.com>
       9              :  * @bug    No known bugs except for NYI items
      10              :  * @brief  This is matmul layer class (operation layer)
      11              :  */
      12              : 
      13              : #ifndef __MATMUL_LAYER_H__
      14              : #define __MATMUL_LAYER_H__
      15              : #ifdef __cplusplus
      16              : 
      17              : #include <common_properties.h>
      18              : #include <layer_devel.h>
      19              : #include <operation_layer.h>
      20              : 
      21              : namespace nntrainer {
      22              : 
      23              : /**
      24              :  * @class MatMul Layer
      25              :  * @brief MatMul Layer
      26              :  */
      27              : class MatMulLayer : public BinaryOperationLayer {
      28              : public:
      29              :   /**
      30              :    * @brief Constructor of MatMul Layer
      31              :    */
      32           40 :   MatMulLayer() :
      33              :     BinaryOperationLayer(),
      34           80 :     matmul_props(props::Print(), props::InPlaceProp()),
      35           40 :     support_backwarding(true) {}
      36              : 
      37              :   /**
      38              :    * @brief Destructor of MatMul Layer
      39              :    */
      40           40 :   ~MatMulLayer(){};
      41              : 
      42              :   /**
      43              :    *  @brief  Move constructor of MatMul Layer.
      44              :    *  @param[in] MatMulLayer &&
      45              :    */
      46              :   MatMulLayer(MatMulLayer &&rhs) noexcept = default;
      47              : 
      48              :   /**
      49              :    * @brief Move assignment operator.
      50              :    * @parma[in] rhs MatMulLayer to be moved.
      51              :    */
      52              :   MatMulLayer &operator=(MatMulLayer &&rhs) = default;
      53              : 
      54              :   /**
      55              :    * @copydoc Layer::finalize(InitLayerContext &context)
      56              :    */
      57              :   void finalize(InitLayerContext &context) final;
      58              : 
      59              :   /**
      60              :    * @brief forwarding operation for matmul
      61              :    *
      62              :    * @param input1 first input tensor
      63              :    * @param input2 second input tensor
      64              :    * @param hidden tensor to store the result value
      65              :    */
      66              :   void forwarding_operation(const Tensor &input1, const Tensor &input2,
      67              :                             Tensor &hidden) final;
      68              : 
      69              :   /**
      70              :    * @copydoc Layer::calcDerivative(RunLayerContext &context)
      71              :    */
      72              :   void calcDerivative(RunLayerContext &context) final;
      73              : 
      74              :   /**
      75              :    * @copydoc bool supportBackwarding() const
      76              :    */
      77           14 :   bool supportBackwarding() const final { return support_backwarding; };
      78              : 
      79              :   /**
      80              :    * @brief Initialize the in-place settings of the layer
      81              :    * @return InPlaceType
      82              :    */
      83            2 :   InPlaceType initializeInPlace() final {
      84            2 :     is_inplace = !std::get<props::InPlaceProp>(matmul_props).empty() &&
      85            0 :                  std::get<props::InPlaceProp>(matmul_props).get();
      86            2 :     support_backwarding = !is_inplace;
      87              : 
      88            2 :     if (!supportInPlace())
      89              :       return InPlaceType::NONE;
      90              :     else
      91            0 :       return InPlaceType::NON_RESTRICTING;
      92              :   }
      93              : 
      94              :   /**
      95              :    * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
      96              :    * method)
      97              :    */
      98            2 :   void exportTo(Exporter &exporter,
      99            2 :                 const ml::train::ExportMethods &method) const final {}
     100              : 
     101              :   /**
     102              :    * @copydoc Layer::setProperty(const std::vector<std::string> &values)
     103              :    */
     104              :   void setProperty(const std::vector<std::string> &values) final;
     105              : 
     106              :   /**
     107              :    * @copydoc Layer::getType()
     108              :    */
     109          130 :   const std::string getType() const final { return MatMulLayer::type; };
     110              : 
     111              :   std::tuple<props::Print, props::InPlaceProp> matmul_props;
     112              :   bool support_backwarding;
     113              : 
     114              :   inline static const std::string type = "matmul";
     115              : };
     116              : 
     117              : } // namespace nntrainer
     118              : 
     119              : #endif /* __cplusplus */
     120              : #endif /* __MATMUL_LAYER_H__ */
        

Generated by: LCOV version 2.0-1