NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
LayerList.h
Go to the documentation of this file.
1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23 
25 
26 #ifndef NVNEURAL_LAYERLIST_H
27 #define NVNEURAL_LAYERLIST_H
28 
29 #include <nvneural/CoreTypes.h>
30 #include <nvneural/LayerTypes.h>
31 #include <nvneural/RefPtr.h>
32 #include <nvneural/RefObject.h>
33 
34 #include <algorithm>
35 #include <iterator>
36 #include <vector>
37 
38 namespace nvneural {
39 
44 class LayerList : public refobj::RefObjectBase<refobj::Implements<ILayerList>>
45 {
46 public:
50  explicit LayerList(const std::vector<ILayer*>& layerList)
51  {
52  std::transform(
53  layerList.begin(),
54  layerList.end(),
55  std::back_inserter(m_layerList),
56  [](ILayer* pRaw) { return RefPtr<ILayer>::fromPointer(pRaw); });
57  }
58 
60  explicit LayerList(const std::vector<RefPtr<ILayer>>& layerList)
61  : m_layerList(layerList)
62  {
63  }
64 
66  explicit LayerList(std::vector<RefPtr<ILayer>>&& layerList)
67  : m_layerList(std::move(layerList))
68  {
69  }
70 
72  size_t layerCount() const noexcept override
73  {
74  return m_layerList.size();
75  }
76 
78  ILayer* getLayerByIndex(size_t layerIndex) const noexcept override
79  {
80  if (layerIndex < m_layerList.size())
81  {
82  return m_layerList[layerIndex].get();
83  }
84  else
85  {
86  return nullptr;
87  }
88  }
89 
90 private:
91  std::vector<RefPtr<ILayer>> m_layerList;
92 };
93 
94 } // namespace nvneural
95 
96 #endif // NVNEURAL_LAYERLIST_H
Fundamental NvNeural data types are declared here.
Interface types needed by layer objects.
Standard implementation for IRefObject-derived objects.
Smart pointer class for tracking IRefObject instances.
ILayer is the base class for neural network layers.
Definition: LayerTypes.h:59
Simple implementation of ILayerList.
Definition: LayerList.h:45
LayerList(const std::vector< ILayer * > &layerList)
Initialize from a vector of raw pointers.
Definition: LayerList.h:50
LayerList(const std::vector< RefPtr< ILayer >> &layerList)
Initialize from a vector of RefPtr (copy ctor).
Definition: LayerList.h:60
size_t layerCount() const noexcept
Returns the number of layers in the collection.
Definition: LayerList.h:72
ILayer * getLayerByIndex(size_t layerIndex) const noexcept
Returns the Nth ILayer pointer in the collection.
Definition: LayerList.h:78
LayerList(std::vector< RefPtr< ILayer >> &&layerList)
Initialize from a vector of RefPtr (move ctor).
Definition: LayerList.h:66
Intrusive pointer using IRefObject's reference counting system.
Definition: RefPtr.h:46
Parameterized base class implementing common IRefObject operations.
Definition: RefObject.h:336