Merged
Conversation
|
|
||
| detail::optimizer_barrier(); | ||
| (*this)(chronometer(model, plan.iterations_per_sample)); | ||
| detail::optimizer_barrier(); |
Contributor
There was a problem hiding this comment.
I would suggest putting the optimizer_barrier around the function call to the concrete benchmark, instead of the whole measurement. That way we can also use the return value for the deoptimization, which would make the trick compatible with MSVC and with what the documentation suggests.
template <typename T>
void deoptimize_value(T&& x) {
keep_memory(&x);
}
template <typename Fn, typename... Args>
auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same<void, std::result_of_t<Fn(Args...)>>{}> {
deoptimize_value(std::forward<Fn>(fn) (std::forward<Args>(args...)));
}
template <typename Fn, typename... Args>
auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same<void, std::result_of_t<Fn(Args...)>>{}> {
std::forward<Fn>(fn) (std::forward<Args>(args...));
// maybe call optimizer_barrier() ??
}And then in chronometer::measure:
template <typename Fun>
void measure(Fun&& fun, std::false_type) {
measure([&fun](int) { return fun(); }); // added return !
}
template <typename Fun>
void measure(Fun&& fun, std::true_type) {
impl->start();
for(int i = 0; i < k; ++i)
deoptimized_invoke(fun, i);
impl->finish();
}I did not try the code and it is C++14, but you get the idea... What do you think?
Contributor
|
Cool! In general I like the approach and the technique. Only thing is I am not sure about what is the best place and way to put the barrier. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds two primitives for a tiny bit of control over the optimizer.
keep_memory(p);prevents optimization of*pwrites that precede it and of*preads that follow it. This is the "escape" mentioned in #51.keep_memory();does the same for all memory. It is currently not available for MSVC (any help with that is appreciated). This is the "clobber" mentioned in #51.