LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
openmp.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_UTILS_DNN_LIB_OPENMP_HPP
28 #define LBANN_UTILS_DNN_LIB_OPENMP_HPP
29 
33 
34 #include <h2/meta/Core.hpp>
35 #include <h2/meta/TypeList.hpp>
36 
37 namespace lbann {
38 
44 {
45  static constexpr auto device = El::Device::CPU;
46 
50  struct unnecessary
51  {
52  };
53 
54  template <typename T>
55  static auto data_type()
56  {
57  return unnecessary{};
58  }
59 
61  {
62  public:
65 
67  static constexpr auto device = backend_type::device;
68 
71 
74 
77 
78  public:
80 
82  TensorDescriptor() = default;
84  ~TensorDescriptor() noexcept = default;
86  TensorDescriptor(TensorDescriptor const&) = default;
90  TensorDescriptor& operator=(TensorDescriptor const&) = default;
92  TensorDescriptor& operator=(TensorDescriptor&&) = default;
93 
95  void swap(TensorDescriptor& other) {}
98 
100  dnnTensorDescriptor_t release() noexcept { return {}; }
101 
103  dnnTensorDescriptor_t get() const noexcept { return {}; }
104 
106  operator dnnTensorDescriptor_t() const noexcept { return this->get(); }
107 
112  void create() noexcept {}
113 
118  template <typename DimT>
119  void
120  set(dnnDataType_t, std::vector<DimT> const&, std::vector<DimT> const& = {})
121  {}
122 
127  template <typename... IntTs>
128  void set(dnnDataType_t, IntTs...)
129  {}
130 #if !(defined LBANN_HAS_CUDNN)
131  // This function is required for API compatibility.
132  void set(dnnDataType_t /*data_type*/,
133  dnnTensorFormat_t /*format*/,
134  std::vector<int> const& /*dims*/)
135  {}
136 #endif // !LBANN_HAS_CUDNN
137 
138  }; // class TensorDescriptor
139 
140  template <typename DataT, typename ScalarT>
141  static void softmax_forward(ScalarT const& alpha_in,
142  TensorDescriptor const& xDesc,
143  El::Matrix<DataT, device> const& x,
144  ScalarT const& beta_in,
145  TensorDescriptor const& yDesc,
146  El::Matrix<DataT, device>& y,
147  El::SyncInfo<device> const& si,
148  softmax_mode mode,
150 
151  template <typename DataT, typename ScalarT>
152  static void logsoftmax_forward(ScalarT const& alpha_in,
153  TensorDescriptor const& xDesc,
154  El::Matrix<DataT, device> const& x,
155  ScalarT const& beta_in,
156  TensorDescriptor const& yDesc,
157  El::Matrix<DataT, device>& y,
158  El::SyncInfo<device> const& si,
159  softmax_mode mode)
160  {
161  LBANN_ERROR("Not yet implemented.");
162  }
163 
164  template <typename DataT, typename ScalarT>
165  static void softmax_backward(ScalarT const& alpha_in,
166  TensorDescriptor const& yDesc,
167  El::Matrix<DataT, device> const& y,
168  TensorDescriptor const& dyDesc,
169  El::Matrix<DataT, device> const& dy,
170  ScalarT const& beta_in,
171  TensorDescriptor const& dxDesc,
172  El::Matrix<DataT, device>& dx,
173  El::SyncInfo<device> const& si,
174  softmax_mode mode,
176 
177  template <typename DataT, typename ScalarT>
178  static void logsoftmax_backward(ScalarT const& alpha_in,
179  TensorDescriptor const& yDesc,
180  El::Matrix<DataT, device> const& y,
181  TensorDescriptor const& dyDesc,
182  El::Matrix<DataT, device> const& dy,
183  ScalarT const& beta_in,
184  TensorDescriptor const& dxDesc,
185  El::Matrix<DataT, device>& dx,
186  El::SyncInfo<device> const& si,
187  softmax_mode mode,
189  {
190  LBANN_ERROR("Not yet implemented.");
191  }
192 
193 }; // struct openmp_backend
194 
195 } // namespace lbann
196 #endif // LBANN_UTILS_DNN_LIB_OPENMP_HPP
DNN library backend for hand-rolled, OMP-based implementations.
Definition: openmp.hpp:43
static void softmax_forward(ScalarT const &alpha_in, TensorDescriptor const &xDesc, El::Matrix< DataT, device > const &x, ScalarT const &beta_in, TensorDescriptor const &yDesc, El::Matrix< DataT, device > &y, El::SyncInfo< device > const &si, softmax_mode mode, softmax_alg alg=softmax_alg::ACCURATE)
static auto data_type()
Definition: openmp.hpp:55
#define LBANN_ERROR(...)
Definition: exception.hpp:37
dnnTensorDescriptor_t release() noexcept
Return DNN library object and release ownership.
Definition: openmp.hpp:100
void reset(dnnTensorDescriptor_t)
Take ownership of DNN library object.
Definition: openmp.hpp:97
softmax_alg
Internal LBANN names for supported softmax algorithms.
Definition: dnn_enums.hpp:110
static void logsoftmax_forward(ScalarT const &alpha_in, TensorDescriptor const &xDesc, El::Matrix< DataT, device > const &x, ScalarT const &beta_in, TensorDescriptor const &yDesc, El::Matrix< DataT, device > &y, El::SyncInfo< device > const &si, softmax_mode mode)
Definition: openmp.hpp:152
static void softmax_backward(ScalarT const &alpha_in, TensorDescriptor const &yDesc, El::Matrix< DataT, device > const &y, TensorDescriptor const &dyDesc, El::Matrix< DataT, device > const &dy, ScalarT const &beta_in, TensorDescriptor const &dxDesc, El::Matrix< DataT, device > &dx, El::SyncInfo< device > const &si, softmax_mode mode, softmax_alg alg=softmax_alg::ACCURATE)
static void logsoftmax_backward(ScalarT const &alpha_in, TensorDescriptor const &yDesc, El::Matrix< DataT, device > const &y, TensorDescriptor const &dyDesc, El::Matrix< DataT, device > const &dy, ScalarT const &beta_in, TensorDescriptor const &dxDesc, El::Matrix< DataT, device > &dx, El::SyncInfo< device > const &si, softmax_mode mode, softmax_alg alg=softmax_alg::ACCURATE)
Definition: openmp.hpp:178
void create() noexcept
Create DNN library object.
Definition: openmp.hpp:112
softmax_mode
Which tensor dimensions to apply softmax over.
Definition: dnn_enums.hpp:87
static constexpr auto device
Definition: openmp.hpp:45