-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
Dispatcher for template parameters of BuildHist Kernels #8259
Dispatcher for template parameters of BuildHist Kernels #8259
Conversation
Merge the last changes
…dhist/colwisebuildhist
…n wise buiilhist.
Keeping my master branch up to date
Does |
I don't think so.
Did I catch your idea correctly? |
More specifically GHistBuildingManager<any_missing>::DispatchAndExecute(
{first_page, read_by_column || force_read_by_column, bin_type_size},
[&](auto t) {
using BuildingManager = decltype(t);
BuildHistDispatch<BuildingManager>(gpair, row_indices, gmat, hist);
}); |
You are right, this part is quite similar to
to define Do you see something here, that I have missed? |
Here is how we can instantiate many booleans into template functions without writing too much code: In your case you have the enum as well, so you can wrap SomeFunction inside the dispatcher for this enum. #include <iostream>
#include <variant>
std::variant<std::false_type,std::true_type> to_variant(bool b)
{
if(b){
return std::true_type{};
}else{
return std::false_type{};
}
}
template <bool is_missing, bool something_else>
void SomeFunction(){
std::cout << is_missing << std::endl;
std::cout << something_else << std::endl;
}
int main()
{
bool runtime_a = true;
bool runtime_b = false;
std::visit([](auto a, auto b) {
SomeFunction<a, b>();
}, to_variant(runtime_a), to_variant(runtime_b));
} Given that we don't have C++17 I leave it up to you what you want to do. |
Got it! The solution based on |
@RAMitchell What is your decision about this PR? |
Hi @trivialfis, |
Merging this, since all CPU tests passed. |
Hi, I continue working on optimizations of histogram building. In this PR I suggest to refactor dispatching of runtime flags into the template parameters.
Currently histogram building functions require 3-4 template parameters. In the next optimization step few more template parameters will required. It will make template parameters list not a good looking. Moreover it will require more dispatcher functions.
For this reasons, I suggest to use a special dispatcher class, being described in this PR.