LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
dummy.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_LAYER_DUMMY_HPP_INCLUDED
28 #define LBANN_LAYER_DUMMY_HPP_INCLUDED
29 
31 
32 namespace lbann {
33 
39 template <typename TensorDataType,
41  El::Device Dev = El::Device::CPU>
42 class dummy_layer : public data_type_layer<TensorDataType>
43 {
44 public:
46  using AbsDistMatrixType = El::AbstractDistMatrix<TensorDataType>;
47 
48  dummy_layer(lbann_comm* comm) : data_type_layer<TensorDataType>(comm)
49  {
51  this->m_error_signal = nullptr;
52  }
53  dummy_layer(const dummy_layer& other) : data_type_layer<TensorDataType>(other)
54  {
56  this->m_error_signal = nullptr;
57  }
58  dummy_layer* copy() const override { return new dummy_layer(*this); }
59 
63  void set_error_signal(std::unique_ptr<AbsDistMatrixType> signal);
64 
66 
68  template <typename ArchiveT>
69  void serialize(ArchiveT& ar);
70 
72 
73  std::string get_type() const override { return "dummy"; }
74  data_layout get_data_layout() const override { return T_layout; }
75  El::Device get_device_allocation() const override { return Dev; }
76  bool can_run_inplace() const override { return false; }
77  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
78 
79 #ifdef LBANN_HAS_ONNX
80  void fill_onnx_node(onnx::GraphProto& graph) const override {}
81 #endif // LBANN_HAS_ONNX
82 
83 protected:
85  void write_specific_proto(lbann_data::Layer& proto) const final;
86 
87  friend class cereal::access;
88  dummy_layer() : dummy_layer(nullptr) {}
89 
90  void fp_compute() override {}
91  void bp_compute() override;
92 
94  std::unique_ptr<AbsDistMatrixType> m_error_signal;
95 };
96 
97 #ifndef LBANN_DUMMY_LAYER_INSTANTIATE
98 #define PROTO_DEVICE(T, Device) \
99  extern template class dummy_layer<T, data_layout::DATA_PARALLEL, Device>; \
100  extern template class dummy_layer<T, data_layout::MODEL_PARALLEL, Device>
101 
103 #undef PROTO_DEVICE
104 #endif // LBANN_DUMMY_LAYER_INSTANTIATE
105 
106 } // namespace lbann
107 
108 #endif // LBANN_LAYER_DUMMY_HPP_INCLUDED
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
Definition: dummy.hpp:75
friend class cereal::access
Definition: dummy.hpp:87
std::unique_ptr< AbsDistMatrixType > m_error_signal
Definition: dummy.hpp:94
Placeholder layer with no child layers.
Definition: dummy.hpp:42
dummy_layer(lbann_comm *comm)
Definition: dummy.hpp:48
constexpr El::Device Device
int m_expected_num_child_layers
Expected number of child layers. A negative value indicates no limit.
Definition: layer.hpp:842
dummy_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
Definition: dummy.hpp:58
void serialize(ArchiveT &ar)
dummy_layer(const dummy_layer &other)
Definition: dummy.hpp:53
void fp_compute() override
Apply layer operation. Called by the &#39;forward_prop&#39; function. Given the input tensors, the output tensors are populated with computed values.
Definition: dummy.hpp:90
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
Definition: dummy.hpp:77
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
Definition: dummy.hpp:46
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
void set_error_signal(std::unique_ptr< AbsDistMatrixType > signal)
Set the error signal of this layer. Used for backpropagation testing purposes.
void write_specific_proto(lbann_data::Layer &proto) const final
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
Definition: dummy.hpp:74
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Definition: dummy.hpp:76
void bp_compute() override
Compute objective funciton gradients. Called by the &#39;back_prop&#39; function. Given the input...
std::string get_type() const override
Get the layer type&#39;s name.
Definition: dummy.hpp:73