LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
permute.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_TRANSFORM_PERMUTE_HPP_INCLUDED
28 #define LBANN_LAYERS_TRANSFORM_PERMUTE_HPP_INCLUDED
29 
30 #include "lbann/base.hpp"
32 
33 namespace lbann {
34 
48 template <typename T>
49 class PermuteLayer final : public data_type_layer<T>
50 {
51 public:
53 
55  PermuteLayer(std::vector<int> const& axes);
56  PermuteLayer(PermuteLayer const& other);
57  PermuteLayer& operator=(PermuteLayer const& other);
58  PermuteLayer(PermuteLayer&& other) = default;
59  PermuteLayer& operator=(PermuteLayer&& other) = default;
60  ~PermuteLayer();
61 
62  PermuteLayer* copy() const final;
63  void swap(PermuteLayer& other);
64 
66 
67 
69  template <typename ArchiveT>
70  void serialize(ArchiveT& ar);
71 
73 
74  std::string get_type() const final;
75  data_layout get_data_layout() const final;
76  El::Device get_device_allocation() const final;
77  bool can_run_inplace() const override { return false; }
78  int get_backprop_requirements() const override { return ERROR_SIGNALS; }
79  description get_description() const final;
80 
81 protected:
82  friend class cereal::access;
83  PermuteLayer();
84 
85  void setup_dims() final;
86  void fp_compute() final;
87  void bp_compute() final;
88 
89  void write_specific_proto(lbann_data::Layer& proto) const final;
90 
91 private:
92  class PermuteImpl;
93  std::unique_ptr<PermuteImpl> m_impl;
94 };
95 
96 #if defined(LBANN_HAS_TENSOR_PERMUTE)
97 // No member of this class will actually be instantiated unless LBANN
98 // is built with support for a tensor permute backend.
99 
100 #ifndef LBANN_PERMUTE_LAYER_INSTANTIATE
101 #define PROTO(T) extern template class PermuteLayer<T>
102 #define LBANN_INSTANTIATE_GPU_HALF
104 #undef PROTO
105 #endif // LBANN_PERMUTE_LAYER_INSTANTIATE
106 
107 #endif // LBANN_HAS_TENSOR_PERMUTE
108 
109 } // namespace lbann
110 #endif // LBANN_LAYERS_TRANSFORM_PERMUTE_HPP_INCLUDED
friend class cereal::access
Definition: permute.hpp:82
void swap(PermuteLayer &other)
void bp_compute() final
Compute objective funciton gradients. Called by the &#39;back_prop&#39; function. Given the input...
El::Device get_device_allocation() const final
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
void setup_dims() final
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.
void write_specific_proto(lbann_data::Layer &proto) const final
Add layer specific data to prototext.
description get_description() const final
Human-readable description.
std::unique_ptr< PermuteImpl > m_impl
Definition: permute.hpp:92
Neural network tensor operation.
Definition: layer.hpp:285
Generates nicely formatted description messages.
Definition: description.hpp:49
data_layout get_data_layout() const final
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
Definition: permute.hpp:78
constexpr El::Device Device
void fp_compute() final
Apply layer operation. Called by the &#39;forward_prop&#39; function. Given the input tensors, the output tensors are populated with computed values.
void serialize(ArchiveT &ar)
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
PermuteLayer * copy() const final
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
PermuteLayer & operator=(PermuteLayer const &other)
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Definition: permute.hpp:77
Permute the indices of a tensor.
Definition: permute.hpp:49
std::string get_type() const final
Get the layer type&#39;s name.