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
Clear read/write event for the global matrix_cls #857
Comments
@t4c1 could we add a template like |
I don't understand this second part of the suggestion. But not setting events will cause wrong results on any async platform unless we set async flag to false. |
So if we had something like template <typename T, bool TrackEvents = true>
class matrix_cl<T, TrackEvents, require_arithmetic_t<T>> : public matrix_cl_base Then for add_read/write_event we could just do inline void add_read_event(cl::Event new_event) const {
if (TrackEvents) {
this->read_events_.push_back(new_event);
}
} So in the model constructor we would make matrix_cl<double, false> X_opencl_ // ... We know the data in a model is immutable so we don't need to track write events (though we should wait for the first transfer) and idt we care about keeping track of where they are being read from do we? |
That seems a bit complicated and dangerous. If we ever write to such a matrix we will likely get wrong results somewhere. Regularly cleaning up events by calling |
I agree with Tadej that this adding a few waits is simpler. |
I'm cool with whatever works! If the data is used in the reverse pass should we do this by adding a |
No need to complicate. We just need |
We should add a
matrix.wait_for_read_write_events()
for all data matrix_cls in the log_prob_impl.Right now, a kernel call to a data matrix adds a read event to the read event vector: https://github.com/stan-dev/math/blob/develop/stan/math/opencl/matrix_cl.hpp#L50
These are never cleared between log_prob_impl calls which means the events add on, causing a rising memory consumption over time.
Adding
matrix.wait_for_read_write_events()
for all data matrices in log_prob_impl will clear these vectors.The text was updated successfully, but these errors were encountered: