Fix build on big endian CPUs (#5617)

* Fix build on big endian CPUs

* Clang-tidy
This commit is contained in:
Philip Hyunsu Cho 2020-04-29 21:56:34 -07:00 committed by GitHub
parent b9649e7b8e
commit 8de7f1928e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View File

@ -9,6 +9,7 @@
#include <dmlc/base.h> #include <dmlc/base.h>
#include <dmlc/data.h> #include <dmlc/data.h>
#include <dmlc/serializer.h>
#include <rabit/rabit.h> #include <rabit/rabit.h>
#include <xgboost/base.h> #include <xgboost/base.h>
#include <xgboost/span.h> #include <xgboost/span.h>
@ -554,5 +555,21 @@ inline BatchSet<EllpackPage> DMatrix::GetBatches(const BatchParam& param) {
namespace dmlc { namespace dmlc {
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true); DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true);
namespace serializer {
template <>
struct Handler<xgboost::Entry> {
inline static void Write(Stream* strm, const xgboost::Entry& data) {
strm->Write(data.index);
strm->Write(data.fvalue);
} }
inline static bool Read(Stream* strm, xgboost::Entry* data) {
return strm->Read(&data->index) && strm->Read(&data->fvalue);
}
};
} // namespace serializer
} // namespace dmlc
#endif // XGBOOST_DATA_H_ #endif // XGBOOST_DATA_H_

View File

@ -37,7 +37,7 @@ template <typename T>
void SaveScalarField(dmlc::Stream *strm, const std::string &name, void SaveScalarField(dmlc::Stream *strm, const std::string &name,
xgboost::DataType type, const T &field) { xgboost::DataType type, const T &field) {
strm->Write(name); strm->Write(name);
strm->Write(type); strm->Write(static_cast<uint8_t>(type));
strm->Write(true); // is_scalar=True strm->Write(true); // is_scalar=True
strm->Write(field); strm->Write(field);
} }
@ -47,7 +47,7 @@ void SaveVectorField(dmlc::Stream *strm, const std::string &name,
xgboost::DataType type, std::pair<uint64_t, uint64_t> shape, xgboost::DataType type, std::pair<uint64_t, uint64_t> shape,
const std::vector<T>& field) { const std::vector<T>& field) {
strm->Write(name); strm->Write(name);
strm->Write(type); strm->Write(static_cast<uint8_t>(type));
strm->Write(false); // is_scalar=False strm->Write(false); // is_scalar=False
strm->Write(shape.first); strm->Write(shape.first);
strm->Write(shape.second); strm->Write(shape.second);
@ -71,7 +71,9 @@ void LoadScalarField(dmlc::Stream* strm, const std::string& expected_name,
CHECK(strm->Read(&name)) << invalid; CHECK(strm->Read(&name)) << invalid;
CHECK_EQ(name, expected_name) CHECK_EQ(name, expected_name)
<< invalid << " Expected field: " << expected_name << ", got: " << name; << invalid << " Expected field: " << expected_name << ", got: " << name;
CHECK(strm->Read(&type)) << invalid; uint8_t type_val;
CHECK(strm->Read(&type_val)) << invalid;
type = static_cast<xgboost::DataType>(type_val);
CHECK(type == expected_type) CHECK(type == expected_type)
<< invalid << "Expected field of type: " << static_cast<int>(expected_type) << ", " << invalid << "Expected field of type: " << static_cast<int>(expected_type) << ", "
<< "got field type: " << static_cast<int>(type); << "got field type: " << static_cast<int>(type);
@ -91,7 +93,9 @@ void LoadVectorField(dmlc::Stream* strm, const std::string& expected_name,
CHECK(strm->Read(&name)) << invalid; CHECK(strm->Read(&name)) << invalid;
CHECK_EQ(name, expected_name) CHECK_EQ(name, expected_name)
<< invalid << " Expected field: " << expected_name << ", got: " << name; << invalid << " Expected field: " << expected_name << ", got: " << name;
CHECK(strm->Read(&type)) << invalid; uint8_t type_val;
CHECK(strm->Read(&type_val)) << invalid;
type = static_cast<xgboost::DataType>(type_val);
CHECK(type == expected_type) CHECK(type == expected_type)
<< invalid << "Expected field of type: " << static_cast<int>(expected_type) << ", " << invalid << "Expected field of type: " << static_cast<int>(expected_type) << ", "
<< "got field type: " << static_cast<int>(type); << "got field type: " << static_cast<int>(type);