LCOV - code coverage report
Current view: top level - xenolith/utils/shadernn/src/layers - XLSnnLayer.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 21 61.9 %
Date: 2024-05-06 04:51:23 Functions: 11 17 64.7 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef SRC_LAYERS_XLSNNLAYER_H_
      24             : #define SRC_LAYERS_XLSNNLAYER_H_
      25             : 
      26             : #include "XLSnnModel.h"
      27             : #include "XLCoreQueue.h"
      28             : 
      29             : namespace stappler::xenolith::shadernn {
      30             : 
      31             : struct ModelSpecialization;
      32             : 
      33             : struct LayerInputInfo {
      34             :         uint32_t index;
      35             :         uint32_t layer;
      36             :     Extent3 extent;
      37             :     core::ImageFormat format;
      38             :     String name;
      39             :     Attachment *attachment;
      40             : };
      41             : 
      42             : // This structure describes image shape transformation
      43             : struct LayerTransformInfo {
      44             :         bool isFixed = 0;
      45             :         union {
      46             :                 struct {
      47             :                         float scaleWidth;
      48             :                         float scaleHeight;
      49             :                         float translateWidth;
      50             :                         float translateHeight;
      51             :                 };
      52             :                 struct {
      53             :                         uint32_t fixedWidth;
      54             :                         uint32_t fixedHeight;
      55             :                         uint32_t fixedDepth;
      56             :                         uint32_t fixedBatch;
      57             :                 };
      58             :         };
      59             : 
      60       22808 :         static constexpr LayerTransformInfo identity() {
      61       22808 :                 return {0, { {1.0f, 1.0f, 0.0f, 0.0f}}};
      62             :         }
      63             : };
      64             : 
      65             : class Layer : public Ref {
      66             : public:
      67           2 :         virtual ~Layer() = default;
      68             : 
      69             :         virtual bool init(Model *, StringView tag, size_t idx, const Value &);
      70             : 
      71             :         virtual void setInputExtent(uint32_t index, Attachment *, Extent3 e);
      72             : 
      73           6 :         virtual void setOutput(Attachment *a) { _output = a; }
      74        7212 :         virtual Attachment *getOutput() const { return _output; }
      75             : 
      76             :         virtual bool isInputDefined() const;
      77             : 
      78             :         virtual Extent3 getOutputExtent() const;
      79             : 
      80             :         virtual Extent3 getOutputExtent(const ModelSpecialization &) const;
      81             : 
      82       22808 :         virtual LayerTransformInfo getOutputTransform() const {
      83       22808 :                 return LayerTransformInfo::identity();
      84             :         }
      85             : 
      86           0 :         virtual bool isTrainable() const { return false; }
      87             : 
      88           2 :         const Model * getModel() { return _model; }
      89             : 
      90          44 :         uint32_t getInputIndex() const { return _inputIndex; }
      91             : 
      92        7218 :         bool isInput() const { return _isInputLayer; }
      93             : 
      94          36 :         SpanView<LayerInputInfo> getInputs() const { return _inputs; }
      95             : 
      96          32 :         StringView getName() const { return _name; }
      97           4 :         StringView getTag() const { return _tag; }
      98             : 
      99           0 :         uint32_t getNumOutputPlanes() const { return _numOutputPlanes; }
     100             :         uint32_t getNumInputPlanes() const { return _numInputPlanes; }
     101             : 
     102           0 :         virtual const core::QueuePassData *prepare(core::Queue::Builder &builder,
     103             :                         Map<Layer *, const core::AttachmentData *> inputs,
     104             :                         Map<Attachment *, const core::AttachmentData *> attachments) {
     105           0 :                 return nullptr;
     106             :         }
     107             : 
     108           0 :         virtual const core::AttachmentData *makeInputAttachment(core::Queue::Builder &builder) {
     109           0 :                 return nullptr;
     110             :         }
     111             : 
     112           0 :         virtual const core::AttachmentData *makeOutputAttachment(core::Queue::Builder &builder, bool isGlobalOutput) {
     113           0 :                 return nullptr;
     114             :         }
     115             : 
     116             : protected:
     117             :         Model *_model = nullptr;
     118             :         String _tag;
     119             :         String _name;
     120             : 
     121             :         bool _isInputLayer = false;
     122             : 
     123             :         uint32_t _numOutputPlanes = 0;
     124             :         uint32_t _numInputPlanes = 0;
     125             :         uint32_t _kernelSize = 0; // move here for layer name
     126             : 
     127             :         // The index of this layer in all layers array
     128             :         uint32_t _inputIndex = 0;
     129             : 
     130             :         Vector<LayerInputInfo> _inputs;
     131             : 
     132             :         Attachment *_output = nullptr;
     133             : };
     134             : 
     135             : }
     136             : 
     137             : #endif /* SRC_LAYERS_XLSNNLAYER_H_ */

Generated by: LCOV version 1.14