Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the use of memset() in CPU 'hist' algorithm #5579

Closed
hcho3 opened this issue Apr 21, 2020 · 0 comments · Fixed by #6003
Closed

Remove the use of memset() in CPU 'hist' algorithm #5579

hcho3 opened this issue Apr 21, 2020 · 0 comments · Fixed by #6003

Comments

@hcho3
Copy link
Collaborator

hcho3 commented Apr 21, 2020

The use of memset() to initialize an array of structures is forbidden by CRAN. For now, we use XGBOOST_STRICT_R_MODE macro to selectively disable memset():

void InitilizeHistByZeroes(GHistRow hist, size_t begin, size_t end) {
#if defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
std::fill(hist.begin() + begin, hist.begin() + end, tree::GradStats());
#else // defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
memset(hist.data() + begin, '\0', (end-begin)*sizeof(tree::GradStats));
#endif // defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
}

We should simplify the code by using std::fill() for all use cases, not just when XGBoost is compiled to use with R.

TODO. Run benchmark and measure performance impact of replacing memset() with std::fill().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant