Hi Toni,
below is the step-by-step instruction for adding new pair styles for the GPU package (when pair table/gpu does not apply). I encourage you try to implement the version buck/coul/long/cs/gpu based on what is done with born/coul/long/cs/gpu. I agree with Axel that the changes should be straightforward.
If you have any issues with the compilation or runtime errors, please post them here and I can take a look.
Cheers,
-Trung
There are two places you need to make addition to:the GPU library in lib/gpu (i.e. libgpu.a) and the /gpu styles in src/GPU. Let’s say you have already implemented a pair style class named PairFoo. Now you want to have a new class PairFooGPU for GPU acceleration.
- Addition to the GPU package, i.e. lib/gpu
You will need to add/implement four source files:
lal_foo.h: header to the class Foo
lal_foo.cpp: implementation of the class Foo
lal_foo.cu: the GPU kernel(s) for the force compute, where the computation mirrors what you have in PairFoo.
lal_foo_ext.cpp: contains an instance of the Foo class and the necessary functions to be added into the GPU library, libgpu.a. The functions are essentially invoked for initialize, compute and clean up the memory allocated for the Foo instance.
A good start to look at is the corresponding files for the Gauss class in lib/gpu. You will see how the per-type arrays are declared and allocated (lal_gauss.h and lal_gauss.cpp), how the kernels are implemented (lal_gauss.cu) and how the exported functions are defined (lal_gauss_ext.cpp).
Finally, you need to modify Nvidia.makefile you are using to build libgpu.a (assuming you are using the CUDA toolkit) to include the newly added files. Again, you can look for the lines in Nvidia.makefile that contain lal_gauss* to see how they got built. In case you wand to compile with OpenCL, Opencl.makefile is where to look and Makefile.linux_opencl is the relevant Makefile.
Now, you can rebuild the GPU package via: make -f Makefile.your_machine
- Addition to src/GPU
Once you are successful in building the GPU package with the new Foo class from the previous step (by checking that the lal_foo.o and lal_foo_ext.o are included in libgpu.a), it’s time to create an entry from src/GPU to call the external functions defined in lal_foo_ext.cpp. You will need to create the PairFooGPU class (pair_foo_gpu.h and pair_foo_gpu.cpp). Again, pair_gauss_gpu.h and pair_gauss_gpu.cpp are good examples to start with.
Finally, you need to modify Install.sh in src/GPU so that the newly added pair style got installed when users (you) run “make yes-gpu” or “make package-update” from src/. The lines to be added should look similar to what is done to pair_gauss_gpu.cpp and pair_gauss_gpu.h.
Once you are done implementing the PairFooGPU class, you can copy the source files into src/ and rebuild LAMMPS with the updated GPU package:
make yes-gpu
make your_machine
- Modification to src/GPU/Install.sh
You can make changes to the Install.sh script so that the newly added gpu pair style can be installed/updated/uninstalled via make package-update, or make no-gpu. Again, take a look at how this is done with the existing styles.