Introduce initialization and free of abstract vector types - #252
Introduce initialization and free of abstract vector types#252gloopydoop wants to merge 14 commits into
Conversation
… every copy, but this seems expensive. So intent is changed
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Hej @gloopydoop! I went through your PR and the suggestions you have made and I have created new branch with my proposition that essentially follows your proposition, but streamlines some of the implementation details. The current implementation passes all our CPU tests. I do not have access to a GPU so I do not know if something breaks if we actually hook it up to a GPU. Maybe @gloopydoop can try this with neko? Check out the I'm not claiming that my implementation is better, especially since it is more intrusive that @gloopydoop 's, but I put it out there as a basis for discussion on how to proceed in this regard. @loiseaujc : You should take a look and add your 5 cents so that we can move forward. The changes and logic of the alterations for my version are the following:
|
This PR introduces an overwritable
initandfreeprocedure for the abstract vector type.The intention is for abstract vectors which may require sophisticated initialization and destruction, and is primarily focused towards supporting GPUs and is specifically related to the codes neko and neko-top. The following is a list of the major changes:
Many complex objects in neko require initialization and freeing subroutines (I think this is quite common in general). This is particularly important for our code when we run on GPUs. For us, a field is a rather complex object. It contains standard arrays when running on CPUs but when one runs on GPUs it contains pointers to the memory on device, functionality to copy between host and device etc. So the first major edit was to introduce an
initand afreeto theabstract_vector. By default this does nothing, and so the user doesn't have to prescribe two extra subroutines. However, these subroutines can be overridden if the user desires.An unfortunate consequence of allocating with
allocate(X, source=Y)is that the device pointers are copied across. So this would mean X and Y technically share the same data on the GPU. So most of these were replaced withallocate(X, mold=Y); call X%init(); call copy(X, Y).A handful of
X = Ywere replaced bycopy(X, Y).This was maybe the most intrusive... There were a number of subroutines, ie, copy, which had
intent(out)forX. In principal, this should give us a freshX, so it would require anX%free(); X%init()on entry. However, since this was used so extensively I felt it would be very costly to constantly break down and rebuild device pointers for every copy so I changed tointent(inout).For a test usage case please see ExtremeFLOW/neko-top#195.