LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
abs.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_OPERATORS_MATH_ABS_HPP_INCLUDED
28 #define LBANN_OPERATORS_MATH_ABS_HPP_INCLUDED
29 
30 #include "lbann_config.hpp"
31 
35 
36 #include "lbann/proto/operators.pb.h"
37 
38 #include <h2/meta/Core.hpp>
39 
40 #include <google/protobuf/message.h>
41 
42 namespace lbann {
43 
50 template <typename DataT, El::Device D>
51 class AbsOperator final
52  : public Cloneable<AbsOperator<DataT, D>,
53  ElementwiseOperator<DataT, El::Base<DataT>, D>>
54 {
56 
60 
61  using LocalInputTensorType = typename BaseType::LocalInputTensorType;
62  using LocalOutputTensorType = typename BaseType::LocalOutputTensorType;
64  typename BaseType::ConstLocalInputTensorType;
66  typename BaseType::ConstLocalOutputTensorType;
67 
69 
70 public:
72 
74  AbsOperator() = default;
75  AbsOperator(AbsOperator&&) = default;
76  AbsOperator(AbsOperator const&) = default;
77  AbsOperator& operator=(AbsOperator&&) = default;
78  AbsOperator& operator=(AbsOperator const&) = default;
79  ~AbsOperator() = default;
80 
82 
83 
85  std::string get_type() const final { return "abs"; }
86  int get_backprop_requirements() const final
87  {
89  }
90 
92 
93 
95  template <typename ArchiveT>
96  void serialize(ArchiveT& ar)
97  {
98  using OperatorType = ElementwiseOperator<DataT, El::Base<DataT>, D>;
99  ar(::cereal::make_nvp("DataTypeOperator",
100  ::cereal::base_class<OperatorType>(this)));
101  }
102 
104 
105 private:
107  virtual void
108  fp_compute_local(std::vector<ConstLocalInputTensorType> input,
109  std::vector<LocalOutputTensorType> output) const final;
110 
112  void bp_compute_local(
113  std::vector<ConstLocalInputTensorType> input,
114  std::vector<ConstLocalOutputTensorType> gradient_wrt_output,
115  std::vector<LocalInputTensorType> gradient_wrt_input) const final;
116 
117  void set_proto_params(lbann_data::Operator& msg) const final
118  {
119  msg.mutable_parameters()->PackFrom(lbann_data::AbsOperator{});
120  }
121 
122  void do_fill_description(description& desc) const final {}
123 }; // class AbsOperator
124 
125 #ifndef LBANN_ABS_OPERATOR_INSTANTIATE
126 #define PROTO_DEVICE(T, D) extern template class AbsOperator<T, D>
128 #undef PROTO_DEVICE
129 #endif // LBANN_ABS_OPERATOR_INSTANTIATE
130 
131 } // namespace lbann
132 
133 #endif // LBANN_OPERATORS_MATH_ABS_HPP_INCLUDED
Element-wise specific tensor operation sub-class.
Inject polymorphic clone functions into hierarchies.
Definition: cloneable.hpp:94
typename BaseType::LocalInputTensorType LocalInputTensorType
Definition: abs.hpp:61
typename BaseType::ConstLocalOutputTensorType ConstLocalOutputTensorType
Definition: abs.hpp:66
Entrywise absolute value.
Definition: abs.hpp:51
typename BaseType::LocalOutputTensorType LocalOutputTensorType
Definition: abs.hpp:62
Generates nicely formatted description messages.
Definition: description.hpp:49
~AbsOperator()=default
void bp_compute_local(std::vector< ConstLocalInputTensorType > input, std::vector< ConstLocalOutputTensorType > gradient_wrt_output, std::vector< LocalInputTensorType > gradient_wrt_input) const final
Local backward compute function.
void set_proto_params(lbann_data::Operator &msg) const final
Definition: abs.hpp:117
virtual void fp_compute_local(std::vector< ConstLocalInputTensorType > input, std::vector< LocalOutputTensorType > output) const final
Local forward compute function.
void serialize(ArchiveT &ar)
Definition: abs.hpp:96
int get_backprop_requirements() const final
Definition: abs.hpp:86
AbsOperator & operator=(AbsOperator &&)=default
std::string get_type() const final
Definition: abs.hpp:85
AbsOperator()=default
void do_fill_description(description &desc) const final
Definition: abs.hpp:122
typename BaseType::ConstLocalInputTensorType ConstLocalInputTensorType
Definition: abs.hpp:64