[Breaking] Add global versioning. (#4936)
* Use CMake config file for representing version. * Generate c and Python version file with CMake. The generated file is written into source tree. But unless XGBoost upgrades its version, there will be no actual modification. This retains compatibility with Makefiles for R. * Add XGBoost version the DMatrix binaries. * Simplify prefetch detection in CMakeLists.txt
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
#include <xgboost/data.h>
|
||||
#include <xgboost/logging.h>
|
||||
#include <xgboost/build_config.h>
|
||||
#include <dmlc/registry.h>
|
||||
#include <cstring>
|
||||
|
||||
@@ -11,6 +12,7 @@
|
||||
#include "./simple_dmatrix.h"
|
||||
#include "./simple_csr_source.h"
|
||||
#include "../common/io.h"
|
||||
#include "../common/version.h"
|
||||
#include "../common/group_data.h"
|
||||
|
||||
#if DMLC_ENABLE_STD_THREAD
|
||||
@@ -34,8 +36,7 @@ void MetaInfo::Clear() {
|
||||
}
|
||||
|
||||
void MetaInfo::SaveBinary(dmlc::Stream *fo) const {
|
||||
int32_t version = kVersion;
|
||||
fo->Write(&version, sizeof(version));
|
||||
Version::Save(fo);
|
||||
fo->Write(&num_row_, sizeof(num_row_));
|
||||
fo->Write(&num_col_, sizeof(num_col_));
|
||||
fo->Write(&num_nonzero_, sizeof(num_nonzero_));
|
||||
@@ -47,19 +48,21 @@ void MetaInfo::SaveBinary(dmlc::Stream *fo) const {
|
||||
}
|
||||
|
||||
void MetaInfo::LoadBinary(dmlc::Stream *fi) {
|
||||
int version;
|
||||
CHECK(fi->Read(&version, sizeof(version)) == sizeof(version)) << "MetaInfo: invalid version";
|
||||
CHECK(version >= 1 && version <= kVersion) << "MetaInfo: unsupported file version";
|
||||
auto version = Version::Load(fi);
|
||||
auto major = std::get<0>(version);
|
||||
// MetaInfo is saved in `SparsePageSource'. So the version in MetaInfo represents the
|
||||
// version of DMatrix.
|
||||
CHECK_EQ(major, 1) << "Binary DMatrix generated by XGBoost: "
|
||||
<< Version::String(version) << " is no longer supported. "
|
||||
<< "Please process and save your data in current version: "
|
||||
<< Version::String(Version::Self()) << " again.";
|
||||
CHECK(fi->Read(&num_row_, sizeof(num_row_)) == sizeof(num_row_)) << "MetaInfo: invalid format";
|
||||
CHECK(fi->Read(&num_col_, sizeof(num_col_)) == sizeof(num_col_)) << "MetaInfo: invalid format";
|
||||
CHECK(fi->Read(&num_nonzero_, sizeof(num_nonzero_)) == sizeof(num_nonzero_))
|
||||
<< "MetaInfo: invalid format";
|
||||
CHECK(fi->Read(&labels_.HostVector())) << "MetaInfo: invalid format";
|
||||
CHECK(fi->Read(&group_ptr_)) << "MetaInfo: invalid format";
|
||||
if (version == kVersionWithQid) {
|
||||
std::vector<uint64_t> qids;
|
||||
CHECK(fi->Read(&qids)) << "MetaInfo: invalid format";
|
||||
}
|
||||
|
||||
CHECK(fi->Read(&weights_.HostVector())) << "MetaInfo: invalid format";
|
||||
CHECK(fi->Read(&root_index_)) << "MetaInfo: invalid format";
|
||||
CHECK(fi->Read(&base_margin_.HostVector())) << "MetaInfo: invalid format";
|
||||
|
||||
Reference in New Issue
Block a user