Repository navigation
Optimize matrix_cl constructors - #1421
Conversation
|
(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 1.0) |
syclik
left a comment
There was a problem hiding this comment.
This still needs work:
- the implementation is buggy. That needs to be fixed.
- the PR needs more careful doc. The design relies on side-effects; these aren't appropriately documented in the PR. The PR just needs to accurately describe what the side-effects are so when this PR is merged, we know how this is affecting other parts of the code.
|
@t4c1, want to video chat sometime today or tomorrow? @SteveBronder, you free too? I'd like to discuss:
Thanks for starting a new thread. I'll respond there for discussion about "side effects." |
|
Also... mind fixing the code conflict? We can't move on this PR until that's taken care of too. |
|
That conflict is due to a refactor PR #1407 being reverted because of a bug. After that is fixed and refactor gets back into develop this conflict should go away. We can do a chat tommorow. I have time between 8h and 15h CET. |
|
Ah. I don't think I'm going to be able to make those times tomorrow. (I'm in eastern time zone... if I interpreted the times correctly, that's 2am-9am). Usually, I'd be able to make 14h CET, but tomorrow I have an early meeting. Friday? |
|
I could do Friday 14-15 CET |
|
Me too. |
|
Friday 14h CET it is! |
|
Awesome. Talk to you tomorrow! I'm sending conference info via a Discourse pm. |
|
Ack sorry, I don't understand the concept of time zones and thought this was at 9 AM EST. Was going to ask why we don't just use a shared pointer here instead of the callback. Since then we can keep track of reference counts and it automatically deletes when there are zero references. Little bulky but very clean |
|
I just got off a video call with @t4c1. This is neat! Some things that happened:
Overall, the state of the code is nearly there. What is required prior to merging is an update on the documentation so it's clear why this deviates from a standard pattern. That should also include the required documentation on functions mentioning their requirements on memory persistence so it's clear to the next reader what's happening. Thanks, @t4c1! |
|
@SteveBronder If we used shared pointer (or any other smart pointer) an store it in the |
|
idt you even need to store it though since the shared_ptr is not deleted until it's reference count goes to zero no? You could just make one, pass it into That sounds right? I'll mess with this later to see if it works |
|
Reference count for the shared ponter is the same thing as the number of shared pointer objects that hold the same pointer. So if we create shared pointer in constructor and don't store it as a member variable that shared ponter will go out of scope when the constructor returns and the memory will be deleted. This is not what we want. |
|
@t4c1, this has conflicts that has to be resolved. (Sorry -- I didn't realize you added the doc; adding commits alone does not notify reviewers.) |
| * matrices on the OpenCL device. Each matrix is flattened into one column | ||
| * of the resulting matrix_cl. | ||
| * of the resulting matrix_cl. If a lvalue is passed to this constructor the | ||
| * caller must make sure that the vector does not go out of scope before |
There was a problem hiding this comment.
@t4c1, first off, thank you for adding information that there is a requirement on the caller to handle memory.
The documentation isn't quite there yet. It's not clear from reading this when "copying is complete." If I'm trying to understand the requirements on memory management, it would help to be more precise about what this means.
There was a problem hiding this comment.
Hopefully it is clear now.
# Conflicts: # stan/math/opencl/copy.hpp # stan/math/opencl/matrix_cl.hpp
# Conflicts: # stan/math/opencl/copy.hpp # stan/math/opencl/matrix_cl.hpp
|
(stat_comp_benchmarks/benchmarks/gp_pois_regr/gp_pois_regr.stan, 1.0) |
|
@syclik This is now ready for review. |
syclik
left a comment
There was a problem hiding this comment.
Thanks, @t4c1. Sorry for the delay... I think it's good enough for now. The doc is still a little tough for a client to understand exactly what they're supposed to do, but I think it leaves enough hints for this to be parseable and understandable, and that's what we want.
The blocking comments were resolved. Everything's good to go now.
|
@SteveBronder, I "dismissed" your review on the PR. @t4c1 went through and addressed all the comments and I checked it over. There was one outstanding question that was in your court, but since it went unanswered, I think it's fine. |
|
Sorry, I stopped responding because I'm uncertain whether this is good or not. If your both comfortable with it then I'm fine with abstaining |
|
I've also been pretty busy at work and a lot of the stuff in this PR was unclear and I didn't have time to meaningfully look at it |
|
It’s all good. The important things are:
As with most implementations, we’re not looking for the perfect solution. Things change and hopefully we know enough to fix it if it needs to change in the future. |
Summary
Added separate constructor to
matrix_clthat accepts Eigen Map.When constructing
matrix_clfrom rvalue it is moved to heap and deleted after the copy is done.To achieve that some trait metaprograms were added to
is_eigen.hpp.Tests
None. These are just optimizations that do not change interface.
Side Effects
None.
Checklist
Math issue Optimize matrix_cl constructors #1420
Copyright holder: Tadej Ciglarič
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit)make test-headers)make doxygen)make cpplint)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested