LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
layers/transform/weights.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_WEIGHTS_HPP_INCLUDED
28 #define LBANN_LAYER_WEIGHTS_HPP_INCLUDED
29 
31 
32 namespace lbann {
33 
38 template <typename TensorDataType,
40  El::Device Device = El::Device::CPU>
41 class weights_layer : public data_type_layer<TensorDataType>
42 {
43 
44 public:
46 
49  using MatType = El::Matrix<TensorDataType, Device>;
50 
53 
55 
56 public:
57  weights_layer(std::vector<El::Int> dims = {});
58  weights_layer(const weights_layer& other) = default;
59  weights_layer& operator=(const weights_layer& other) = default;
60  weights_layer* copy() const override;
61 
63 
65  template <typename ArchiveT>
66  void serialize(ArchiveT& ar);
67 
69 
70  std::string get_type() const override;
71  data_layout get_data_layout() const override;
72  El::Device get_device_allocation() const override;
73  bool can_run_inplace() const override { return false; }
74  int get_backprop_requirements() const override { return ERROR_SIGNALS | WEIGHTS; }
75 
76 protected:
78  void write_specific_proto(lbann_data::Layer& proto) const final;
79 
80  void setup_data(size_t max_mini_batch_size) override;
81 
82  void fp_compute() override;
83  void bp_compute() override;
84 };
85 
86 // Builder function
87 
88 // Explicit template instantiation
89 #ifndef LBANN_WEIGHTS_LAYER_INSTANTIATE
90 #define PROTO_DEVICE(T, Device) \
91  extern template class weights_layer<T, data_layout::DATA_PARALLEL, Device>; \
92  extern template class weights_layer<T, data_layout::MODEL_PARALLEL, Device>
94 #undef PROTO_DEVICE
95 #endif // LBANN_WEIGHTS_LAYER_INSTANTIATE
96 
97 } // namespace lbann
98 
99 #endif // LBANN_LAYER_WEIGHTS_HPP_INCLUDED
weights_layer(std::vector< El::Int > dims={})
weights_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Output a weights tensor.
constexpr El::Device Device
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
std::string get_type() const override
Get the layer type&#39;s name.
void write_specific_proto(lbann_data::Layer &proto) const final
void bp_compute() override
Compute objective funciton gradients. Called by the &#39;back_prop&#39; function. Given the input...
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
El::Matrix< TensorDataType, Device > MatType
The concrete local matrix type used by this object.
weights_layer & operator=(const weights_layer &other)=default
void setup_data(size_t max_mini_batch_size) override
Setup layer data. Called by the &#39;setup&#39; function. Memory is allocated for distributed matrices...
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
void serialize(ArchiveT &ar)
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.
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...