LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
uniform_hash.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_UNIFORM_HASH_HPP_INCLUDED
28 #define LBANN_LAYERS_MISC_UNIFORM_HASH_HPP_INCLUDED
29 
32 #include "lbann/proto/layers.pb.h"
33 
34 namespace lbann {
35 
42 template <typename TensorDataType, data_layout Layout, El::Device Device>
43 class uniform_hash_layer : public data_type_layer<TensorDataType>
44 {
45 #ifdef LBANN_HAS_GPU
46  static_assert(Device == El::Device::GPU,
47  "uniform_hash_layer only supports GPU");
48 #else
49  static_assert(Device != El::Device::CPU,
50  "uniform_hash_layer only supports GPU");
51 #endif // LBANN_HAS_GPU
52 
53 public:
55 
56  uniform_hash_layer(const uniform_hash_layer& other) = default;
57  uniform_hash_layer& operator=(const uniform_hash_layer& other) = default;
58  uniform_hash_layer* copy() const override;
59 
61 
63  template <typename ArchiveT>
64  void serialize(ArchiveT& ar);
65 
67 
68  std::string get_type() const override;
69  data_layout get_data_layout() const override;
70  El::Device get_device_allocation() const override;
71  bool can_run_inplace() const override { return false; }
72  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
73 
74 protected:
76  void write_specific_proto(lbann_data::Layer& proto) const final;
77 
78  friend class cereal::access;
80 
81  void setup_dims() override;
82 
83  void fp_compute() override;
84 };
85 
86 template <typename T, data_layout L, El::Device D>
88  lbann_data::Layer& proto) const
89 {
90  proto.set_datatype(proto::ProtoDataType<T>);
91  proto.mutable_uniform_hash();
92 }
93 
94 #ifdef LBANN_HAS_GPU
95 #ifndef LBANN_UNIFORM_HASH_LAYER_INSTANTIATE
96 #define PROTO(T) \
97  extern template class uniform_hash_layer<T, \
98  data_layout::DATA_PARALLEL, \
99  El::Device::GPU>; \
100  extern template class uniform_hash_layer<T, \
101  data_layout::MODEL_PARALLEL, \
102  El::Device::GPU>
104 #undef PROTO
105 #endif // LBANN_UNIFORM_HASH_LAYER_INSTANTIATE
106 #endif // LBANN_HAS_GPU
107 
108 } // namespace lbann
109 
110 #endif // LBANN_LAYERS_MISC_UNIFORM_HASH_HPP_INCLUDED
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
friend class cereal::access
void serialize(ArchiveT &ar)
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
uniform_hash_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
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.
void write_specific_proto(lbann_data::Layer &proto) const final
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
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.
constexpr El::Device Device
uniform_hash_layer & operator=(const uniform_hash_layer &other)=default
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
Apply a hash function to get uniformly distributed values.