LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
dft_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_LAYERS_MATH_DFT_ABS_HPP_INCLUDED
28 #define LBANN_LAYERS_MATH_DFT_ABS_HPP_INCLUDED
29 
32 #include "lbann/proto/layers.pb.h"
33 #include "lbann_config.hpp"
34 
35 // This layer is only supported if LBANN has FFTW support.
36 #ifdef LBANN_HAS_FFTW
37 
38 namespace lbann {
39 
40 // Forward declaration of FFT stuff
41 template <typename T, El::Device D>
42 class dft_abs_impl;
43 class lbann_comm;
44 
68 template <typename TensorDataType, El::Device Device>
69 class dft_abs_layer : public data_type_layer<TensorDataType>
70 {
71  static const auto Layout = data_layout::DATA_PARALLEL;
72 
73 public:
74  dft_abs_layer(lbann_comm* const comm);
75  ~dft_abs_layer();
76  dft_abs_layer* copy() const override { return new dft_abs_layer(*this); }
77 
79 
81  template <typename ArchiveT>
82  void serialize(ArchiveT& ar);
83 
85 
86  std::string get_type() const override { return "DFT Abs"; }
87  data_layout get_data_layout() const override { return Layout; }
88  El::Device get_device_allocation() const override { return Device; }
89  bool can_run_inplace() const override { return false; }
90  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
91 
92  description get_description() const override
93  {
95  }
96 
97 protected:
99  void write_specific_proto(lbann_data::Layer& proto) const final;
100 
101  friend class cereal::access;
102  dft_abs_layer() : dft_abs_layer(nullptr) {}
103 
104  dft_abs_layer(dft_abs_layer const&);
105  void setup_dims() override;
106  void fp_compute() override;
107  void bp_compute() override;
108 
109 private:
110  using impl_type = dft_abs_impl<TensorDataType, Device>;
111  std::unique_ptr<impl_type> pimpl_;
112 }; // class dft_abs_layer
113 
114 template <typename T, El::Device D>
115 void dft_abs_layer<T, D>::write_specific_proto(lbann_data::Layer& proto) const
116 {
117  proto.set_datatype(proto::ProtoDataType<T>);
118  proto.mutable_dft_abs();
119 }
120 
121 #ifndef LBANN_DFT_ABS_LAYER_INSTANTIATE
122 
123 #ifdef LBANN_HAS_FFTW_FLOAT
124 extern template class dft_abs_layer<float, El::Device::CPU>;
125 #endif // LBANN_HAS_FFTW_FLOAT
126 #ifdef LBANN_HAS_FFTW_DOUBLE
127 extern template class dft_abs_layer<double, El::Device::CPU>;
128 #endif // LBANN_HAS_FFTW_DOUBLE
129 
130 #ifdef LBANN_HAS_GPU
131 // cuFFT always supports both types.
132 extern template class dft_abs_layer<float, El::Device::GPU>;
133 extern template class dft_abs_layer<double, El::Device::GPU>;
134 #endif // LBANN_HAS_GPU
135 
136 #endif // LBANN_DFT_ABS_LAYER_INSTANTIATE
137 
138 } // namespace lbann
139 #endif // LBANN_HAS_FFTW
140 #endif // LBANN_LAYERS_MATH_DFT_ABS_HPP_INCLUDED
void serialize(std::ostream &os, google::protobuf::Message const &msg)
Serialize the protobuf message to a stream.
virtual description get_description() const
Human-readable description.
constexpr El::Device Device
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218