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 Request] KOKKOS fix rigid #1624
Comments
This will be super useful! |
I would like to take a look because I am interested in it myself but I would have to bother @stanmoore1 a lot with Kokkos-related questions, since porting a complicated fix like rigid seems to be a lot harder than porting a pair style. |
This sounds great, thank you. As you say, it doesn't look trivial. We would be interested in fix rigid. |
I'm happy to answer questions about Kokkos. |
OK, I will take a look at it. Unfortunately, I am more interested in rigid/small but I'll see what I can do for either. I think rigid/small would be more suitable for GPUs and the like because it seems more similar to what Hoomd-Blue does. |
@Pakketeretet2 yes a simple port is fine, i.e. just thread over loops of atoms. After we have a port then we'll worry about performance, I can do some tuning. I used c++11 lambdas extensively in #1650 and it made porting easier since I didn't have to mess with functors or tags. |
OK, since fix propel/self is pretty much done from a programming point of view I have started with this now. |
Great, feel free to ping me either here on Github or via email if you have questions. |
Will do. For a second I couldn't find the lambdas anywhere but I found them. They look nicer than C++11 lambdas so they were hard to spot. :) |
The latest changes with minimize seem to cause linking problems with clang on my laptop, but it might be something dumb on my part. I'll look into it more tomorrow. |
You are building LAMMPS with cmake, right?
|
Yup, that must have been it. I figured it was something like this but
didn't know where to find the CMake files. Thanks!
…On Wed, Sep 11, 2019 at 10:23 PM Axel Kohlmeyer ***@***.***> wrote:
The latest changes with minimize seem to cause linking problems with clang
on my laptop, but it might be something dumb on my part. I'll look into it
more tomorrow.
You are building LAMMPS with cmake, right?
There is a small adjustment needed:
$ git diff
diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake
index 0e5bf70a4..cc1e05162 100644
--- a/cmake/Modules/Packages/KOKKOS.cmake
+++ b/cmake/Modules/Packages/KOKKOS.cmake
@@ -17,6 +17,8 @@ if(PKG_KOKKOS)
${KOKKOS_PKG_SOURCES_DIR}/atom_vec_kokkos.cpp
${KOKKOS_PKG_SOURCES_DIR}/comm_kokkos.cpp
${KOKKOS_PKG_SOURCES_DIR}/comm_tiled_kokkos.cpp
+ ${KOKKOS_PKG_SOURCES_DIR}/min_kokkos.cpp
+ ${KOKKOS_PKG_SOURCES_DIR}/min_linesearch_kokkos.cpp
${KOKKOS_PKG_SOURCES_DIR}/neighbor_kokkos.cpp
${KOKKOS_PKG_SOURCES_DIR}/neigh_list_kokkos.cpp
${KOKKOS_PKG_SOURCES_DIR}/neigh_bond_kokkos.cpp
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1624?email_source=notifications&email_token=AEFLJ7AUA6G6GXK4ID5H5B3QJGR3ZA5CNFSM4IJ2PJIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6QOFAQ#issuecomment-530637442>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEFLJ7F6KDVV2K423QAYXGTQJGR3ZANCNFSM4IJ2PJIA>
.
|
@stanmoore1 In some places the rigid code calls functions in math_extra that expects arrays of (implicit) size three. I am sure Kokkos provides a way to slice an array (subview or something). Two related questions:
|
Any function that is called in a If a Kokkos view is 2D LayoutRight, then you can get a 1D slice view using |
For |
Actually I'm not 100% sure if |
OK, before I can actually test any of that I stumbled upon another thing: Rigid uses a bunch of additional storage for center-of-mass positions, velocities and forces. It looks like there are no associated Kokkos containers or data masks for that yet, at least, I cannot see any masks for them in atom_masks.h nor any containers in atom_kokkos.h. What is the preferred way to add such things? These arrays only have to be the size of nbody which will probably be significantly smaller than nlocal. |
Just to be clear, are you working on |
fix rigid. |
I would add Kokkos dualviews inside fix rigid/kk and call sync/modify directly on them. No need to add them to atom_masks.h. In other words, any array that is declared in fix_rigid.h would have a corresponding Kokkos view in fix_rigid_kokkos.h. |
Ah, that is brilliant! So, just to make sure I fundamentally understand this; whenever you do a memoryKK->create_array or memoryKK->grow_array, Kokkos wraps that memory in a dualview so that after you have a handle to the arrays on both the host and the device? And then in device code you use d_view and in host code you use h_view, and you just have to make sure to sync it whenever required? Does Kokkos take care of memcpy'ing it to the device from host when you create an array? It seems to but I am not sure. Do you think it makes sense for me to make a pull request to push my changes to so you can review code as we go? That might put more strain on your time than me just bugging you here though. Overall I'm pleasantly surprised by how straightforward it seems to port to Kokkos. I will try to take notes that might be useful for me and/or others later. |
So I now have the fix create its own Kokkos counterparts to arrays in the
base fix rigid. However, when I do
memoryKK->create_kokkos(k_xcm, xcm, "rigid/kk:xcm")
the data in xcm is now all zeros, but the data in the host and device views
is still zeros. I assume that is because there has to be an explicit
synchronization. For data that has an atom mask the atomKK->sync and
atomKK->modified took care of that, but how does that work for my own
custom arrays?
…On Fri, Sep 13, 2019, 18:12 Stan Moore ***@***.***> wrote:
For example:
https://github.com/lammps/lammps/blob/master/src/KOKKOS/fix_minimize_kokkos.h#L47
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1624?email_source=notifications&email_token=AEFLJ7BUSPNOQF4QX5Y27X3QJQF5LA5CNFSM4IJ2PJIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6WKBSY#issuecomment-531407051>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEFLJ7GUCISLLVPYYEKLGWDQJQF5LANCNFSM4IJ2PJIA>
.
|
This is correct. Typically
Correct
It is a little complicated. If the host view is marked as modified, it will do the create/grow on the host, otherwise it will default to the device.
By default Kokkos will initialize a view to all zeros when it is created or the new part when it is resized.
You just call one of these: k_view.modify<DeviceType>();
k_view.sync<DeviceType>();
k_view.modify<LMPHostType>();
k_view.sync<LMPHostType>(); |
I suggest creating a work in progress PR and I can review as I have time. |
Am working on it in PR #1680. The syncing is still not entirely clear to me. Do these do this? If so, the function names make some sense to me. Otherwise they don't. :) |
Yes:
You never want to concurrently mark modified on both host and device. Also if you sync but nothing is modified it is just a no-op. |
So basically before any kernel where the data is used (Kokkos or legacy), first sync to the execution space (host or device). Then after the data is changed by the kernel, mark it as modified on the corresponding execution space. This will ensure you always have synced data. |
Sorry to keep bothering you @stanmoore1, The good news is that, when I manually fixed the body array using temporary arrays I do get the correct numbers in the thermo output for the first step, and the porting of the initial_integrate and final_integrate functions should be a lot easier than figuring all the memory stuff out. |
Ah yes, this is tricky. Normally I would just override the |
I think moving initialization to init() makes sense, both conceptually and in that it would solve this specific problem. However, I would not like to touch it at this point because I have not verified yet whether or not the other FixRigid variants depend on some of these flags being set in their own constructors, so for now I will just memcpy the host data to a temporary array and copy it back into the kokkos array. |
For now you could just temporarily wrap the pointers into a host Kokkos view then copy up to the device, for example see https://github.com/stanmoore1/lammps/blob/fft/src/KOKKOS/fft3d_kokkos.cpp#L91 |
In other words you can use something like HAT::t_int_1d h_body(body,atom->local);
k_body.h_view = h_body;
k_body.modify<LMPHostType>();
k_body.sync<DeviceType>(); |
Right. I suppose this works because the host view "takes ownership" of the original array and the view is copied by value. That looks cleaner than what it is now, I will copy it in later. |
This does not seem to work. Even after a call to modify() and sync, k_body.d_view.size() is reported to be 0, and a call to memoryKK->grow_kokkos() leads to the data being overwritten with zeros again. Turns out I need to do this:
Is this because my k_body has not been initialized at this point yet? As in, I cannot do memoryKK->create_kokkos(k_body, body,...) because that overwrites body but create_kokkos does seem to "couple" the d_view and h_view together, which I might have to do explicitly? |
So I semi-abandoned the porting of the functions and instead kept everything on the host but with KOKKOS arrays just to make sure the output is identical to the original code. That seems to be the case now for the rigid example, so I will now selectively port the functions using your comments on my PR. |
I updated #1680 to latest master. This is still on my to-do list. |
Summary
Porting fix rigid to KOKKOS
Detailed Description
In the past I've benefited significantly from using LAMMPS accelerated with KOKKOS. I am trying to run large scale simulations in GPUs with rigid bodies. Is porting fix rigid planned for the future?
The text was updated successfully, but these errors were encountered: