LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
serialize_half.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 #pragma once
27 #ifndef LBANN_UTILS_SERIALIZATION_SERIALIZE_HALF_HPP_INCLUDED
28 #define LBANN_UTILS_SERIALIZATION_SERIALIZE_HALF_HPP_INCLUDED
29 
36 #include "lbann_config.hpp"
37 
38 // Half-precision support comes from here:
39 #include <El.hpp>
40 
41 #include "cereal_utils.hpp"
42 
47 namespace cereal {
48 #ifdef LBANN_HAS_HALF
49 #ifdef LBANN_HAS_GPU_FP16
50 
52 
55 template <typename OutputArchiveT>
56 void save(OutputArchiveT& archive, __half const& value)
57 {
58  float x = value;
59  archive(x);
60 }
61 
63 template <typename InputArchiveT>
64 void load(InputArchiveT& archive, __half& value)
65 {
66  float x = 0.f;
67  archive(x);
68  value = x;
69 }
70 
72 #ifdef LBANN_HAS_CEREAL_BINARY_ARCHIVES
73 
74 
77 void save(BinaryOutputArchive&, __half const&);
78 
80 void load(BinaryInputArchive&, __half&);
81 
83 #endif // LBANN_HAS_CEREAL_BINARY_ARCHIVES
84 #endif // LBANN_HAS_GPU_FP16
85 
86 #ifdef LBANN_HAS_CEREAL_XML_ARCHIVES
87 
88 
90 // Remove the default definitions from Cereal
91 inline void save(XMLOutputArchive&, half_float::half const&) = delete;
92 inline void load(XMLInputArchive&, half_float::half&) = delete;
93 
95 float save_minimal(XMLOutputArchive const&, half_float::half const&) noexcept;
96 
98 void load_minimal(XMLInputArchive const&,
99  half_float::half&,
100  float const&) noexcept;
101 
103 #endif // LBANN_HAS_CEREAL_XML_ARCHIVES
104 #endif // LBANN_HAS_HALF
105 } // namespace cereal
106 
107 #endif // LBANN_UTILS_SERIALIZATION_SERIALIZE_HALF_HPP_INCLUDED
void load(std::string const &pbuf_filename, google::protobuf::Message &msg)
Fill the protobuf message from a binary file.
void save(ArchiveT &ar, ::El::AbstractMatrix< T > const &mat)
Save a matrix to a text-based archive.