LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
argmin.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_MISC_ARGMIN_HPP_INCLUDED
28 #define LBANN_LAYERS_MISC_ARGMIN_HPP_INCLUDED
29 
31 
32 namespace lbann {
33 
39 template <typename TensorDataType, data_layout Layout, El::Device Device>
40 class argmin_layer : public data_type_layer<TensorDataType>
41 {
42  static_assert(Layout == data_layout::DATA_PARALLEL,
43  "argmin layer only supports data parallel layout");
44  static_assert(Device == El::Device::CPU, "argmin layer only supports CPU");
45 
46 public:
47  argmin_layer(lbann_comm* comm) : data_type_layer<TensorDataType>(comm) {}
48  argmin_layer* copy() const override { return new argmin_layer(*this); }
49 
51 
53  template <typename ArchiveT>
54  void serialize(ArchiveT& ar);
55 
57 
58  std::string get_type() const override { return "argmin"; }
59  data_layout get_data_layout() const override { return Layout; }
60  El::Device get_device_allocation() const override { return Device; }
61  bool can_run_inplace() const override { return false; }
62  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
63 
64 protected:
66  void write_specific_proto(lbann_data::Layer& proto) const final;
67 
68  friend class cereal::access;
69  argmin_layer() : argmin_layer(nullptr) {}
70 
71  void setup_dims() override;
72 
73  void fp_compute() override;
74 };
75 
76 #ifndef LBANN_ARGMIN_LAYER_INSTANTIATE
77 #define PROTO(T) \
78  extern template class argmin_layer<T, \
79  data_layout::DATA_PARALLEL, \
80  El::Device::CPU>
81 
82 #define LBANN_INSTANTIATE_CPU_HALF
84 #undef PROTO
85 #undef LBANN_INSTANTIATE_CPU_HALF
86 #endif // LBANN_ARGMIN_LAYER_INSTANTIATE
87 } // namespace lbann
88 
89 #endif // LBANN_LAYERS_MISC_ARGMIN_HPP_INCLUDED
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.
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.
std::string get_type() const override
Get the layer type&#39;s name.
Definition: argmin.hpp:58
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Definition: argmin.hpp:61
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: argmin.hpp:59
void serialize(ArchiveT &ar)
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 ...
Definition: argmin.hpp:60
void write_specific_proto(lbann_data::Layer &proto) const final
argmin_layer(lbann_comm *comm)
Definition: argmin.hpp:47
Get index of minimum-value tensor entry.
Definition: argmin.hpp:40
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
friend class cereal::access
Definition: argmin.hpp:68
argmin_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
Definition: argmin.hpp:48
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
Definition: argmin.hpp:62