-
Notifications
You must be signed in to change notification settings - Fork 85
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
Feature: Smart STK Field Types #1209
Conversation
Also I'm not really a fan of |
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.
Overall I like it, I think it would reduce the programmer burden for most use-cases.
There could be some corner cases where the local lifetime includes multiple GPU kernels, and perhaps you want or don't want syncs/modifies for each kernel. But those cases could be handled the old way.
I do like 'MODE' better than SCOPE, as you note.
I'm a little worried about the potential cost of wrapping/forwarding functions like get() etc. Perhaps no runtime cost, but perhaps that increases the cost? I guess we would need to measure performance of that. |
@alanw0 yes that is a good point. We should probably in-line them no matter what just to be safe. |
@alanw0 I've looked into that. I am a little torn. Since this is c++ the Is there another reason to use |
I think your current changes fix it. I was thinking that FieldBase would take care of the difference between ScalarField, ScalarIntField, VectorField, etc. But your change does that also. |
Eh I'm seeing this in the latest device build:
Considering refactoring and doing three separate classes for the memspace rather than SFINAE'ing the ctor and dtor to suppress this warning. I'm not really sure what is special about this case vs the base unit tests I created. Perhaps I just missed the warnings for those in the sea of outputs. |
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.
Yeah, I think it looks good. It is at least ready for further testing in nalu-wind.
I'm still slightly worried about wrapping the potentially tight-loop methods like get and others, but I think this is worth putting in and see how it does.
Overview
This feature is to create a
SmartFieldRef<MEMSPACE, SCOPE>
type that will automatically call the appropriate field modifies and syncs based on the memspace (i.eHOST
orDEVICE
) and the scopes (READ
,WRITE
andREAD_WRITE
).Technical Details
The crux of this method comes from my discussions with the Kokkos team about how data is generated on device in a
Kokkos::parallel_for
. It turns out that the copy constructor and thus it's associated destructor are called on host for the lambda capture.The entire lambda/functor is then essentially memcopied to device, and so the copy ctor and dtor don't actually get called on device. So my thought is we can embed the host functions for field sync and modify inside the these functions, and exploit them as part of every lambda capture.
This moves
sync_to_*
andmodified_on_*
to the closest possible usage for every field that is wrapped in one of theseSmartFieldRef
objects, and ensures that the sync-then-modify programming model is satisfied.State of Tests on Device
The current tests work on CUDA, and I am working on adding more. Still need to write the host tests.
TODO (Utterly too verbose)
There are a few comments in there on things I would like to handle that this doesn't currently handle. Here is the list to look for in the code:
READ
types are const correct to the point where a user is unable to modify field values throughoperator()
andget()
. I also want a clear error message when this is violated. Currently I am thinking partial template specialization and making non-const return types throw a message instead of trying to access the fields.FieldManager
class as the main way of retrieving fields going forward.stk::mesh::NgpFieldBase::value_type
rather than having to specify this at each usage. Staying at<SPACE, SCOPE, T>
is not a deal breaker, but it bugs me. I would love to only have to specify theSPACE
andSCOPE
.Along those lines, an alternative formulation could look like:
This would allow for automatic template deduction of the
stk::mesh::NgpFieldBase::value_type
, but then the only way I can think to ensure theREAD
scopes are appropriatelyconst
do it would be with anif
statement inget
andoperator()
which feels like a terrible idea.Follow on PR would be to liberally apply this in the code.