LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
elu.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_ACTIVATIONS_ELU_HPP_INCLUDED
28 #define LBANN_LAYERS_ACTIVATIONS_ELU_HPP_INCLUDED
29 
31 #include "lbann/layers/layer.hpp"
33 #include "lbann/proto/layers.pb.h"
34 
35 namespace lbann {
36 
52 template <typename TensorDataType, data_layout Layout, El::Device Device>
53 class elu_layer : public data_type_layer<TensorDataType>
54 {
55 public:
56  elu_layer() : elu_layer(nullptr, El::To<TensorDataType>(1)) {}
57  elu_layer(lbann_comm* comm, TensorDataType alpha = El::To<TensorDataType>(1))
58  : data_type_layer<TensorDataType>(comm), m_alpha(alpha)
59  {}
60  elu_layer* copy() const override { return new elu_layer(*this); }
61  std::string get_type() const override { return "ELU"; }
62  data_layout get_data_layout() const override { return Layout; }
63  El::Device get_device_allocation() const override { return Device; }
64  bool can_run_inplace() const override { return true; }
65  int get_backprop_requirements() const override
66  {
68  }
69 
70  description get_description() const override
71  {
73  desc.add("alpha", m_alpha);
74  return desc;
75  }
76 
78 
80  template <typename ArchiveT>
81  void serialize(ArchiveT& ar);
82 
84 
85 protected:
87  void write_specific_proto(lbann_data::Layer& proto) const final;
88 
89  void setup_dims() override
90  {
92  this->set_output_dims(this->get_input_dims());
93  }
94  void fp_compute() override;
95  void bp_compute() override;
96 
97 private:
99  TensorDataType m_alpha;
100 };
101 
102 template <typename T, data_layout L, El::Device D>
103 void elu_layer<T, L, D>::write_specific_proto(lbann_data::Layer& proto) const
104 {
105  proto.set_datatype(proto::ProtoDataType<T>);
106  auto* msg = proto.mutable_elu();
107  msg->set_alpha(m_alpha);
108 }
109 
110 #ifndef LBANN_ELU_LAYER_INSTANTIATE
111 #define PROTO_DEVICE(T, Device) \
112  extern template class elu_layer<T, data_layout::DATA_PARALLEL, Device>; \
113  extern template class elu_layer<T, data_layout::MODEL_PARALLEL, Device>
114 
116 #undef PROTO_DEVICE
117 #endif // LBANN_ELU_LAYER_INSTANTIATE
118 
119 } // namespace lbann
120 
121 #endif // LBANN_LAYERS_ACTIVATIONS_ELU_HPP_INCLUDED
virtual void setup_dims()
Setup tensor dimensions Called by the &#39;setup&#39; function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
std::string get_type() const override
Get the layer type&#39;s name.
Definition: elu.hpp:61
void bp_compute() override
Compute objective funciton gradients. Called by the &#39;back_prop&#39; function. Given the input...
std::vector< int > get_input_dims(size_t input_index=0) const
Get input tensor dimensions.
Generates nicely formatted description messages.
Definition: description.hpp:49
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: elu.hpp:63
virtual description get_description() const
Human-readable description.
constexpr El::Device Device
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.
elu_layer(lbann_comm *comm, TensorDataType alpha=El::To< TensorDataType >(1))
Definition: elu.hpp:57
void set_output_dims(std::vector< int > dims, size_t output_index=0)
Set output tensor dimensions.
void setup_dims() override
Setup tensor dimensions Called by the &#39;setup&#39; function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
Definition: elu.hpp:89
Exponential linear unit.
Definition: elu.hpp:53
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
void write_specific_proto(lbann_data::Layer &proto) const final
Definition: elu.hpp:103
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
Definition: elu.hpp:65
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: elu.hpp:62
description get_description() const override
Human-readable description.
Definition: elu.hpp:70
void serialize(ArchiveT &ar)
elu_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
Definition: elu.hpp:60
TensorDataType m_alpha
Definition: elu.hpp:99
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Definition: elu.hpp:64