LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
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_LAYER_ACTIVATION_RELU_IMPL_HPP_INCLUDED
28 #define LBANN_LAYER_ACTIVATION_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>
39 void relu_layer<T, L, D>::write_specific_proto(lbann_data::Layer& proto) const
40 {
41  proto.set_datatype(proto::ProtoDataType<T>);
42  proto.mutable_relu();
43 }
44 
45 #ifdef LBANN_HAS_DISTCONV
46 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
47 relu_distconv_adapter<TensorDataType, T_layout, Dev>&
49 {
50  return const_cast<relu_distconv_adapter<TensorDataType, T_layout, Dev>&>(
51  static_cast<const relu_layer<TensorDataType, T_layout, Dev>&>(*this)
52  .get_distconv_adapter());
53 }
54 
55 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
56 const relu_distconv_adapter<TensorDataType, T_layout, Dev>&
58 {
59  return dynamic_cast<
60  const relu_distconv_adapter<TensorDataType, T_layout, Dev>&>(
62 }
63 
64 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
65 void relu_distconv_adapter<TensorDataType, T_layout, Dev>::setup_distributions(
66  tensor_overlap_constraints& constraints)
67 {
69 
70  auto& x = this->get_prev_activations_dist();
71  auto& y = this->get_activations_dist();
72  auto& dx = this->get_error_signals_dist();
73  auto& dy = this->get_prev_error_signals_dist();
74 
75  // x == dx
76  constraints.mark_equivalent(x, dx);
77  // y == dy
78  constraints.mark_equivalent(y, dy);
79 }
80 
81 template <typename TensorDataType, data_layout T_layout, El::Device Dev>
82 void relu_distconv_adapter<TensorDataType, T_layout, Dev>::setup_layer(
83  size_t workspace_capacity)
84 {
85  m_relu = std::make_unique<dc::ReLU>(dc::get_backend());
86  m_relu->setup(this->get_prev_activations(),
87  this->get_activations(),
88  this->get_error_signals(),
89  this->get_prev_error_signals());
90 }
91 #endif // LBANN_HAS_DISTCONV
92 
93 } // namespace lbann
94 
95 #endif // LBANN_LAYER_ACTIVATION_RELU_IMPL_HPP_INCLUDED
void write_specific_proto(lbann_data::Layer &proto) const final
Definition: relu_impl.hpp:39
virtual void setup_distributions(tensor_overlap_constraints &constraints)
void mark_equivalent(dc::Dist &d1, dc::Dist &d2)
Rectified linear unit.
Definition: relu.hpp:69