-
Notifications
You must be signed in to change notification settings - Fork 236
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
Limit Tuning by Time #1997
Limit Tuning by Time #1997
Conversation
@atamazov As discussed, here is the PR which limits tuning by time. |
src/generic_search.cpp
Outdated
|
||
std::size_t GetTuningIterationsMax() | ||
{ | ||
return Value(MIOPEN_DEBUG_TUNING_ITERATIONS_MAX{}, std::numeric_limits<std::size_t>::max()); | ||
} | ||
|
||
std::chrono::milliseconds GetTuningTimeMax() | ||
{ | ||
const auto fallback = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be static as well? It's not used in non-static context. Or you could wrap the calculation of res
value in a lambda.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/include/miopen/mt_queue.hpp
Outdated
{ | ||
std::unique_lock<std::mutex> lock(mutex); | ||
cond_var.wait(lock, [&] { return !queue.empty(); }); | ||
return queue.front(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't reference get messed up on push? This should probably return by value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since its a queue, the push would happen at the other end of the underlying container. The object has only one consumer so peeking at the front with a reference saves the copy which a return by value would entail. Therefore, the semantics are to get a reference to the front, use the object and once you are done, you pop it off the queue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach inherently relies on the implementation of std::queue not reallocating its internal container and invalidating the reference. And it probably can. Also it may get changed in the future. Thus even if safe right now this is a liability. I still suggest returning by value. Combining this with pop in a single method would remove one mutex lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I am talking about: https://stackoverflow.com/a/16075550
@JehandadKhan How could randomization increase the chances of finding an optima? |
@averinevg When there is a limited time budget, then randomizing the search space is required. If the search space is traversed in order ( as is currently the case) then a time budget would limit the parts of space searched. |
@JehandadKhan
Discussed with @atamazov. At this stage I have no objection about randomization. |
src/include/miopen/mt_queue.hpp
Outdated
{ | ||
std::unique_lock<std::mutex> lock(mutex); | ||
cond_var.wait(lock, [&] { return !queue.empty(); }); | ||
return queue.front(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach inherently relies on the implementation of std::queue not reallocating its internal container and invalidating the reference. And it probably can. Also it may get changed in the future. Thus even if safe right now this is a liability. I still suggest returning by value. Combining this with pop in a single method would remove one mutex lock.
@DrizztDoUrden and @averinevg I have addressed your reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add one change, but this is safe to merge right now.
{ | ||
std::unique_lock<std::mutex> lock(mutex); | ||
cond_var.wait(lock, [&] { return !queue.empty(); }); | ||
T ret = queue.front(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T ret = queue.front(); | |
T ret = std::move(queue.front()); |
Wouldn't save much time (relatively speaking) in generic search, but who knows where else this may get used.
@averinevg could you please resolve the conflict? It is caused by merging #2009 first. |
@junliume Merge conflict has been resolved |
This PR makes updates to the search algorithm in MIOpen:
MIOPEN_TUNING_TIME_MS_MAX
) which sets the number of milliseconds MIOpen can spend to tune each solver.MIOPEN_DEBUG_PERFDB_OVERRIDE
)