LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
optimizer_common.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 OPTIMIZERS_UNIT_TEST_OPTIMIZER_COMMON_HPP_
27 #define OPTIMIZERS_UNIT_TEST_OPTIMIZER_COMMON_HPP_
28 
29 // Some common includes
30 #include <h2/meta/Core.hpp>
31 #include <h2/meta/TypeList.hpp>
32 #include <h2/patterns/multimethods/SwitchDispatcher.hpp>
33 #include <lbann/base.hpp>
35 #include <lbann_config.hpp>
36 
37 // This header should only be used in the unit testing code, so this
38 // is fine.
39 using namespace h2::meta;
40 
41 // Get the description out as a string. Useful for comparing objects
42 // that might not expose accessor functions for all metadata.
43 template <typename ObjectType>
44 std::string desc_string(ObjectType const& opt)
45 {
46  std::ostringstream desc;
47  desc << opt.get_description();
48  return desc.str();
49 }
50 
51 // Simple groups of Output/Input archive types. The car is the output
52 // archive, the cadr is the input archive. Accessor metafunctions are
53 // defined below.
54 
55 using FpTypes = TL<float,
56  double
57 #ifdef LBANN_HAS_HALF
58  ,
59  lbann::cpu_fp16
60 #ifdef LBANN_HAS_GPU_FP16
61  ,
62  lbann::fp16
63 #endif // LBANN_HAS_GPU_FP16
64 #endif // LBANN_HAS_HALF
65  >;
66 
67 #ifdef LBANN_HAS_CEREAL_BINARY_ARCHIVES
68 template <typename T>
69 using BinaryArchiveTypeBundle =
70  TL<T, cereal::BinaryOutputArchive, cereal::BinaryInputArchive>;
71 using BinaryArchiveTypes = tlist::ExpandTL<BinaryArchiveTypeBundle, FpTypes>;
72 #else
73 using BinaryArchiveTypes = tlist::Empty;
74 #endif // LBANN_HAS_CEREAL_BINARY_ARCHIVES
75 
76 #ifdef LBANN_HAS_CEREAL_XML_ARCHIVES
77 template <typename T>
78 using XMLArchiveTypeBundle =
79  TL<T, cereal::XMLOutputArchive, cereal::XMLInputArchive>;
80 using XMLArchiveTypes = tlist::ExpandTL<XMLArchiveTypeBundle, FpTypes>;
81 #else
82 using XMLArchiveTypes = tlist::Empty;
83 #endif // LBANN_HAS_CEREAL_XML_ARCHIVES
84 
85 using AllArchiveTypes = tlist::Append<BinaryArchiveTypes, XMLArchiveTypes>;
86 
87 #endif // OPTIMIZERS_UNIT_TEST_OPTIMIZER_COMMON_HPP_
tlist::Empty BinaryArchiveTypes
std::string desc_string(ObjectType const &opt)
TL< float, double > FpTypes
tlist::Append< BinaryArchiveTypes, XMLArchiveTypes > AllArchiveTypes
tlist::Empty XMLArchiveTypes