Add a vector class to GridKit#418
Conversation
PhilipFackler
left a comment
There was a problem hiding this comment.
For an all-in-one solution like this, I would prefer some revisions as explained in my line comments. None of those is a deal-breaker if this is meant only for "advanced" use-cases, but I still think it would be helpful.
| * you are doing. | ||
| */ | ||
| template <typename ScalarT, typename IdxT> | ||
| int Vector<ScalarT, IdxT>::setData(ScalarT* data, memory::MemorySpace memspace) |
There was a problem hiding this comment.
This would make more sense as part of a constructor. An instance should be constructed with ownership and data (if non-owning) for host and device respectively. Ownership should not be allowed to change. And I think the data you're wrapping in the non-owning case shouldn't be allowed to change either. This function wouldn't exist in that case.
There was a problem hiding this comment.
I agree, changing ownership after construction is looking for trouble.
This method was experimental and should not be a part of the vector class.
There was a problem hiding this comment.
This method was used to get a vector from a multivector. Better solution is to construct non-data-owning vector object instead, or create a separate VectorView object as @lukelowry suggested.
There was a problem hiding this comment.
I restricted this function to be able to operate only on vectors with data not allocated. Intended use would be:
Vector v(n)
...
double* data = new double[n];
...
v.setData(data);The danger is still that user needs to set data that matches the vector size. This is a makeshift solution to create vector views for now.
There was a problem hiding this comment.
This is why I think it should be part of the constructor.
Vector v;
...
double* data = new double[n];
...
v = Vector(n, data);
All of your suggestions are spot on and should be incorporated before this PR is merged. |
lukelowry
left a comment
There was a problem hiding this comment.
I think we need a zombie approach if we do merge this implementation. We should take the best parts of this and graft them onto a more scalable implementation that can isolate the Component in memory (is "closure" the right word here?).
| switch (memspace) | ||
| { | ||
| case HOST: | ||
| setHostUpdated(true); | ||
| setDeviceUpdated(false); | ||
| break; | ||
| case DEVICE: | ||
| setHostUpdated(false); | ||
| setDeviceUpdated(true); | ||
| break; | ||
| } |
There was a problem hiding this comment.
What if the memspace not passed to the function had already been tagged as updated?
There was a problem hiding this comment.
It will be tagged as out of date. This is desired behavior.
nkoukpaizan
left a comment
There was a problem hiding this comment.
A few minor comments.
I'm not convinced the class in GridKit needs to mirror Re::Solve, and I tend to prefer solutions that are driven by the application needs first, but I'm willing to see what happens when we try to use this in GridKit.
| #include <GridKit/LinearAlgebra/MemoryUtils.hpp> | ||
| // #include <resolve/vector/Vector.hpp> | ||
| // #include <resolve/vector/VectorHandler.hpp> | ||
| // #include <resolve/workspace/LinAlgWorkspace.hpp> |
There was a problem hiding this comment.
I recommend removing references to resolve, even if commented.
| result += test.setToConst(50); | ||
| } | ||
|
|
||
| #ifdef GRIDKIT_USE_GPU |
There was a problem hiding this comment.
I don't recall that we've defined this yet. Now may be a good time. Need to clarify GRIDKIT_ENAGLE_ vs GRIDKIT_USE_ if we choose to differentiate between CMake options and pre-cprocessor directives.
There was a problem hiding this comment.
I would use the same names for both.
| result += test.setData(50); | ||
|
|
||
| result += test.copyFromExternal(50); | ||
| // result += test.copyToExternal(50); |
There was a problem hiding this comment.
Why is this test commented out?
shakedregev
left a comment
There was a problem hiding this comment.
Address the comment and clarify that this is ready for testing.
Description
Add vector class to GridKit to replace
std::vectorand provide portable data management.Proposed changes
The
LinearAlgebra::Vectorclass was ported from Re::Solve. It has basic initialization and data management functionality. I can be use as a vector, multivector or vector view class.Checklist
-Wall -Wpedantic -Wconversion -Wextra.Further comments
The multivector capability in this class should replace
DenseMatrixobject in GridKit.