LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
categorical_random.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_CATEGORICAL_RANDOM_HPP_INCLUDED
28 #define LBANN_LAYER_CATEGORICAL_RANDOM_HPP_INCLUDED
29 
31 #include "lbann/models/model.hpp"
32 #include "lbann/utils/random.hpp"
33 
34 namespace lbann {
35 
44 template <typename TensorDataType,
46  El::Device Dev = El::Device::CPU>
47 class categorical_random_layer : public data_type_layer<TensorDataType>
48 {
49  static_assert(Dev == El::Device::CPU,
50  "categorical random layer currently only supports CPU");
51  static_assert(T_layout == data_layout::DATA_PARALLEL,
52  "categorical random layer currently only "
53  "supports DATA_PARALLEL");
54 
55 public:
57  : data_type_layer<TensorDataType>(comm)
58  {}
59  categorical_random_layer* copy() const override
60  {
61  return new categorical_random_layer(*this);
62  }
63 
65 
67  template <typename ArchiveT>
68  void serialize(ArchiveT& ar);
69 
71 
72  std::string get_type() const override { return "categorical random"; }
73  data_layout get_data_layout() const override { return T_layout; }
74  El::Device get_device_allocation() const override { return Dev; }
75  bool can_run_inplace() const override { return false; }
76  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
77 
78 protected:
80  void write_specific_proto(lbann_data::Layer& proto) const final;
81 
82  friend class cereal::access;
84 
85  void fp_compute() override;
86 };
87 
88 #ifndef LBANN_CATEGORICAL_RANDOM_LAYER_INSTANTIATE
89 
90 #define PROTO(T) \
91  extern template class categorical_random_layer<T, \
92  data_layout::DATA_PARALLEL, \
93  El::Device::CPU>
94 
95 #define LBANN_INSTANTIATE_CPU_HALF
97 #undef PROTO
98 #undef LBANN_INSTANTIATE_CPU_HALF
99 
100 #endif // LBANN_CATEGORICAL_RANDOM_LAYER_INSTANTIATE
101 
102 } // namespace lbann
103 
104 #endif // LBANN_LAYER_CATEGORICAL_RANDOM_HPP_INCLUDED
categorical_random_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
Random categorical outputs.
void write_specific_proto(lbann_data::Layer &proto) const final
void serialize(ArchiveT &ar)
constexpr El::Device Device
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
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.
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.
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...