-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
7e477a2
commit 5620322
Showing
18 changed files
with
301 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function (find_prefetch_intrinsics) | ||
include(CheckCXXSourceCompiles) | ||
check_cxx_source_compiles(" | ||
#include <xmmintrin.h> | ||
int main() { | ||
char data = 0; | ||
const char* address = &data; | ||
_mm_prefetch(address, _MM_HINT_NTA); | ||
return 0; | ||
} | ||
" XGBOOST_MM_PREFETCH_PRESENT) | ||
check_cxx_source_compiles(" | ||
int main() { | ||
char data = 0; | ||
const char* address = &data; | ||
__builtin_prefetch(address, 0, 0); | ||
return 0; | ||
} | ||
" XGBOOST_BUILTIN_PREFETCH_PRESENT) | ||
set(XGBOOST_MM_PREFETCH_PRESENT ${XGBOOST_MM_PREFETCH_PRESENT} PARENT_SCOPE) | ||
set(XGBOOST_BUILTIN_PREFETCH_PRESENT ${XGBOOST_BUILTIN_PREFETCH_PRESENT} PARENT_SCOPE) | ||
endfunction (find_prefetch_intrinsics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@xgboost_VERSION_MAJOR@.@xgboost_VERSION_MINOR@.@xgboost_VERSION_PATCH@-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function (write_version) | ||
message(STATUS "xgboost VERSION: ${xgboost_VERSION}") | ||
configure_file( | ||
${xgboost_SOURCE_DIR}/cmake/build_config.h.in | ||
${xgboost_SOURCE_DIR}/include/xgboost/build_config.h @ONLY) | ||
configure_file( | ||
${xgboost_SOURCE_DIR}/cmake/Python_version.in | ||
${xgboost_SOURCE_DIR}/python-package/xgboost/VERSION | ||
) | ||
endfunction (write_version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/*! | ||
* Copyright 2019 by Contributors | ||
* \file build_config.h | ||
* | ||
* Generated from `cmake/build_config.h.in` by cmake. | ||
*/ | ||
#ifndef XGBOOST_BUILD_CONFIG_H_ | ||
#define XGBOOST_BUILD_CONFIG_H_ | ||
|
||
#cmakedefine XGBOOST_MM_PREFETCH_PRESENT | ||
#cmakedefine XGBOOST_BUILTIN_PREFETCH_PRESENT | ||
|
||
#define XGBOOST_VER_MAJOR @xgboost_VERSION_MAJOR@ | ||
#define XGBOOST_VER_MINOR @xgboost_VERSION_MINOR@ | ||
#define XGBOOST_VER_PATCH @xgboost_VERSION_PATCH@ | ||
|
||
#endif // XGBOOST_BUILD_CONFIG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*! | ||
* Copyright 2019 XGBoost contributors | ||
*/ | ||
#include <dmlc/io.h> | ||
|
||
#include <string> | ||
#include <tuple> | ||
#include <vector> | ||
|
||
#include "xgboost/logging.h" | ||
#include "xgboost/json.h" | ||
#include "version.h" | ||
|
||
namespace xgboost { | ||
|
||
const Version::TripletT Version::kInvalid {-1, -1, -1}; | ||
|
||
Version::TripletT Version::Load(Json const& in, bool check) { | ||
if (get<Object const>(in).find("version") == get<Object const>(in).cend()) { | ||
return kInvalid; | ||
} | ||
Integer::Int major {0}, minor {0}, patch {0}; | ||
try { | ||
auto const& j_version = get<Array const>(in["version"]); | ||
std::tie(major, minor, patch) = std::make_tuple( | ||
get<Integer const>(j_version.at(0)), | ||
get<Integer const>(j_version.at(1)), | ||
get<Integer const>(j_version.at(2))); | ||
} catch (dmlc::Error const& e) { | ||
LOG(FATAL) << "Invaid version format in loaded JSON object: " << in; | ||
} | ||
|
||
return std::make_tuple(major, minor, patch); | ||
} | ||
|
||
Version::TripletT Version::Load(dmlc::Stream* fi) { | ||
XGBoostVersionT major{0}, minor{0}, patch{0}; | ||
// This is only used in DMatrix serialization, so doesn't break model compability. | ||
std::string msg { "Incorrect version format found in binary file. " | ||
"Binary file from XGBoost < 1.0.0 is no longer supported. " | ||
"Please generate it again." }; | ||
std::string verstr { u8"version:" }, read; | ||
read.resize(verstr.size(), 0); | ||
|
||
CHECK_EQ(fi->Read(&read[0], verstr.size()), verstr.size()) << msg; | ||
if (verstr != read) { | ||
// read might contain `\0` that terminates the string. | ||
LOG(FATAL) << msg; | ||
} | ||
|
||
CHECK_EQ(fi->Read(&major, sizeof(major)), sizeof(major)) << msg; | ||
CHECK_EQ(fi->Read(&minor, sizeof(major)), sizeof(minor)) << msg; | ||
CHECK_EQ(fi->Read(&patch, sizeof(major)), sizeof(patch)) << msg; | ||
|
||
return std::make_tuple(major, minor, patch); | ||
} | ||
|
||
void Version::Save(Json* out) { | ||
Integer::Int major, minor, patch; | ||
std::tie(major, minor, patch)= Self(); | ||
(*out)["version"] = std::vector<Json>{Json(Integer{major}), | ||
Json(Integer{minor}), | ||
Json(Integer{patch})}; | ||
} | ||
|
||
void Version::Save(dmlc::Stream* fo) { | ||
XGBoostVersionT major, minor, patch; | ||
std::tie(major, minor, patch) = Self(); | ||
std::string verstr { u8"version:" }; | ||
fo->Write(&verstr[0], verstr.size()); | ||
fo->Write(&major, sizeof(major)); | ||
fo->Write(&minor, sizeof(minor)); | ||
fo->Write(&patch, sizeof(patch)); | ||
} | ||
|
||
std::string Version::String(TripletT const& version) { | ||
std::stringstream ss; | ||
ss << std::get<0>(version) << "." << get<1>(version) << "." << get<2>(version); | ||
return ss.str(); | ||
} | ||
|
||
Version::TripletT Version::Self() { | ||
return std::make_tuple(XGBOOST_VER_MAJOR, XGBOOST_VER_MINOR, XGBOOST_VER_PATCH); | ||
} | ||
|
||
bool Version::Same(TripletT const& triplet) { | ||
return triplet == Self(); | ||
} | ||
|
||
} // namespace xgboost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*! | ||
* Copyright 2019 XGBoost contributors | ||
*/ | ||
#ifndef XGBOOST_COMMON_VERSION_H_ | ||
#define XGBOOST_COMMON_VERSION_H_ | ||
|
||
#include <dmlc/io.h> | ||
#include <string> | ||
#include <tuple> | ||
|
||
#include "xgboost/base.h" | ||
|
||
namespace xgboost { | ||
class Json; | ||
// a static class for handling version info | ||
struct Version { | ||
using TripletT = std::tuple<XGBoostVersionT, XGBoostVersionT, XGBoostVersionT>; | ||
static const TripletT kInvalid; | ||
|
||
// Save/Load version info to Json document | ||
static TripletT Load(Json const& in, bool check = false); | ||
static void Save(Json* out); | ||
|
||
// Save/Load version info to dmlc::Stream | ||
static Version::TripletT Load(dmlc::Stream* fi); | ||
static void Save(dmlc::Stream* fo); | ||
|
||
static std::string String(TripletT const& version); | ||
static TripletT Self(); | ||
|
||
static bool Same(TripletT const& triplet); | ||
}; | ||
|
||
} // namespace xgboost | ||
#endif // XGBOOST_COMMON_VERSION_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.