LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
deconvolution.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_LAYERS_LEARNING_DECONVOLUTION_HPP_INCLUDED
28 #define LBANN_LAYERS_LEARNING_DECONVOLUTION_HPP_INCLUDED
29 
31 #include "lbann/utils/distconv.hpp"
32 
33 namespace lbann {
34 
35 #ifdef LBANN_HAS_DISTCONV
36 template <typename TensorDataType, data_layout Layout, El::Device Device>
37 class deconvolution_distconv_adapter
38  : public base_convolution_adapter<TensorDataType, Device>
39 {
40 public:
41  using TensorDevType =
42  typename base_convolution_adapter<TensorDataType, Device>::TensorDevType;
43 
44  deconvolution_distconv_adapter(Layer& layer)
45  : base_convolution_adapter<TensorDataType, Device>(layer)
46  {}
47  virtual ~deconvolution_distconv_adapter() = default;
48 
49  void setup_distributions(tensor_overlap_constraints& constraints) override;
50  void setup_layer(size_t workspace_capacity) override;
51  dc::Shape get_activations_local_shape(int index = 0) const override;
52 };
53 #endif // LBANN_HAS_DISTCONV
54 
65 template <typename TensorDataType, data_layout Layout, El::Device Device>
67  : public base_convolution_layer<TensorDataType, Device>
68 {
69  static_assert(Layout == data_layout::DATA_PARALLEL,
70  "deconvolution layer only supports DATA_PARALLEL");
71 
72 public:
73  deconvolution_layer(int num_data_dims,
74  int num_output_channels,
75  std::vector<int> conv_dims,
76  std::vector<int> pads,
77  std::vector<int> strides,
78  std::vector<int> dilations,
79  std::vector<int> output_pads,
80  int groups,
81  bool has_bias);
82 
83  deconvolution_layer* copy() const override
84  {
85  return new deconvolution_layer(*this);
86  }
87 
88  std::string get_type() const override { return "deconvolution"; }
89 
90  data_layout get_data_layout() const override { return Layout; }
91 
92  El::Device get_device_allocation() const override { return Device; }
93 
94  bool can_run_inplace() const override { return false; }
95 
96  int get_backprop_requirements() const override
97  {
99  }
100 
101  void setup_dims() override;
102 
104 
106  template <typename ArchiveT>
107  void serialize(ArchiveT& ar);
108 
110 
111 protected:
113  void write_specific_proto(lbann_data::Layer& proto) const final;
114 
115  friend class cereal::access;
117 
118  std::vector<int> get_kernel_dims() const override;
119  void fp_compute() override;
120  void bp_compute() override;
121 
122 #ifdef LBANN_HAS_DISTCONV
123  friend class deconvolution_distconv_adapter<TensorDataType, Layout, Device>;
124 
125 protected:
126  void setup_distconv_adapter() override;
127  bool is_distconv_supported() const override;
128 #endif // LBANN_HAS_DISTCONV
129 
130 private:
136  std::vector<int> m_output_pads;
137 };
138 
139 LBANN_DEFINE_LAYER_BUILDER(deconvolution);
140 
141 #ifndef LBANN_DECONVOLUTION_LAYER_INSTANTIATE
142 
143 #define PROTO_DEVICE(T, Device) \
144  extern template class deconvolution_layer<T, \
145  data_layout::DATA_PARALLEL, \
146  Device>;
147 
149 #undef PROTO_DEVICE
150 
151 #endif // LBANN_DECONVOLUTION_LAYER_INSTANTIATE
152 
153 } // namespace lbann
154 
155 #endif // LBANN_LAYERS_LEARNING_DECONVOLUTION_HPP_INCLUDED
std::vector< int > m_output_pads
Padding for output tensor.
Convolution transpose.
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
void serialize(std::ostream &os, google::protobuf::Message const &msg)
Serialize the protobuf message to a stream.
constexpr El::Device Device
::distconv::tensor::Shape Shape
std::string get_type() const override
Get the layer type&#39;s name.
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
deconvolution_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
LBANN_DEFINE_LAYER_BUILDER(elu)
Computation kernels for convolution and deconvolution layers.