LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
leaky_relu_impl.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_ACTIVATIONS_LEAKY_RELU_IMPL_HPP_INCLUDED
28 #define LBANN_LAYERS_ACTIVATIONS_LEAKY_RELU_IMPL_HPP_INCLUDED
29 
31 
32 #ifdef LBANN_HAS_DISTCONV
34 #endif // LBANN_HAS_DISTCONV
35 
36 namespace lbann {
37 
38 template <typename T, data_layout L, El::Device D>
40  lbann_data::Layer& proto) const
41 {
42  proto.set_datatype(proto::ProtoDataType<T>);
43  auto* msg = proto.mutable_leaky_relu();
44  msg->set_negative_slope(m_negative_slope);
45 }
46 
47 #ifdef LBANN_HAS_DISTCONV
48 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
49 leaky_relu_distconv_adapter<TensorDataType, T_layout, Dev>&
51 {
52  return const_cast<
53  leaky_relu_distconv_adapter<TensorDataType, T_layout, Dev>&>(
54  static_cast<const leaky_relu_layer<TensorDataType, T_layout, Dev>&>(*this)
55  .get_distconv_adapter());
56 }
57 
58 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
59 const leaky_relu_distconv_adapter<TensorDataType, T_layout, Dev>&
61 {
62  return dynamic_cast<
63  const leaky_relu_distconv_adapter<TensorDataType, T_layout, Dev>&>(
65 }
66 
67 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
68 void leaky_relu_distconv_adapter<TensorDataType, T_layout, Dev>::
69  setup_distributions(tensor_overlap_constraints& constraints)
70 {
72 
73  auto& x = this->get_prev_activations_dist();
74  auto& y = this->get_activations_dist();
75  auto& dx = this->get_error_signals_dist();
76  auto& dy = this->get_prev_error_signals_dist();
77 
78  // x == y
79  constraints.mark_equivalent(x, y);
80  // x == dx
81  constraints.mark_equivalent(x, dx);
82  // dx == dy
83  constraints.mark_equivalent(dx, dy);
84 }
85 
86 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
87 void leaky_relu_distconv_adapter<TensorDataType, T_layout, Dev>::setup_layer(
88  size_t workspace_capacity)
89 {
90  m_leaky_relu = std::make_unique<dc::LeakyReLU>(dc::get_backend());
91 }
92 #endif // LBANN_HAS_DISTCONV
93 
94 } // namespace lbann
95 
96 #endif // LBANN_LAYERS_ACTIVATIONS_LEAKY_RELU_IMPL_HPP_INCLUDED
virtual void setup_distributions(tensor_overlap_constraints &constraints)
void mark_equivalent(dc::Dist &d1, dc::Dist &d2)
void write_specific_proto(lbann_data::Layer &proto) const final