LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
builder_macros.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 #ifndef LBANN_INCLUDE_LBANN_OPERATORS_BUILDER_MACROS_HPP_INCLUDED
27 #define LBANN_INCLUDE_LBANN_OPERATORS_BUILDER_MACROS_HPP_INCLUDED
28 
31 
32 #include "lbann/proto/operators.pb.h"
33 
34 #include <memory>
35 
36 // Forward declaration
37 namespace lbann_data {
38 class Operator;
39 } // namespace lbann_data
40 
41 namespace lbann {
42 namespace details {
43 
44 template <typename InputT, typename OutputT, El::Device D>
45 void AssertConsistentTypeParameters(lbann_data::Operator const& op)
46 {
47  LBANN_ASSERT(proto::ProtoDataType<InputT> == op.input_datatype());
48  LBANN_ASSERT(proto::ProtoDataType<OutputT> == op.output_datatype());
49  LBANN_ASSERT(proto::ProtoDevice<D> ==
50  proto::resolve_default_device(op.device_allocation()));
51 }
52 
53 } // namespace details
54 } // namespace lbann
55 
60 #define LBANN_DECLARE_OPERATOR_BUILDER(OP_NAME) \
61  template <typename DataT, El::Device D> \
62  std::unique_ptr<Operator<DataT, DataT, D>> build_##OP_NAME##_operator( \
63  lbann_data::Operator const& op)
64 
72 #define LBANN_DEFINE_OPERATOR_BUILDER(OP_LOWER, OP_NAME) \
73  template <typename DataT, El::Device D> \
74  std::unique_ptr<lbann::Operator<DataT, DataT, D>> \
75  lbann::build_##OP_LOWER##_operator(lbann_data::Operator const& op) \
76  { \
77  details::AssertConsistentTypeParameters<DataT, DataT, D>(op); \
78  return std::make_unique<OP_NAME##Operator<DataT, D>>(); \
79  }
80 
84 #define LBANN_SINGLE_TYPE_OPERATOR_BUILDER_ETI(OPERATOR_NAME, T, D) \
85  template std::unique_ptr<lbann::Operator<T, T, D>> \
86  lbann::build_##OPERATOR_NAME##_operator<T, D>(lbann_data::Operator const&)
87 
88 #endif // LBANN_INCLUDE_LBANN_OPERATORS_BUILDER_MACROS_HPP_INCLUDED
void AssertConsistentTypeParameters(lbann_data::Operator const &op)
constexpr lbann_data::DeviceAllocation resolve_default_device(lbann_data::DeviceAllocation in)
#define LBANN_ASSERT(cond)
Definition: exception.hpp:97