About eam/alloy and eam/fs potential .cpp file

Dear lammps developers:
I have recently been studying the source code you wrote about the EAM potential functions (pair_eam_alloy.cpp and pair_eam_fs.cpp), but I encountered an issue: the number of rhor parameters differs between the two potential functions—specifically, nr and ( nr x nelements) per element, respectively. However, neither of the .cpp files explicitly details the process of calculating the potential energy values. Could you explain how the distinction is implemented in the actual calculations?

Looking forward to your reply deeply.

You forgot to read pair_eam.cpp which provides the base class to the two other classes.

All classes perform the same calculation on the same data, only the potential files are different.
Thus pair_eam_fs.cpp and pair_eam_alloy.cpp override the function for reading and processing the potential data from the potential file(s) for later use but otherwise use the functionality from their base class.

Details about the file formats and how the EAM styles are related to each other are in the manual.

Sorry, I only know pair_style eam command — LAMMPS documentation manual. This website seems to only introduce the formula for potential functions. May I ask which manual you are referring to?

I refer to exactly that manual page.

Thank for your reply very much.
Now, I want to write the GPU acceleration Variants for my potential function, but there is a prompt during compilation: “undefined reference to `twobandl_gpu_clear()'”
May I ask how this should be resolved?

By implementing the missing function?
… or fixing the typo?

It is a separate potential function file, including cpp and h files, which have been successfully compiled and used.

I have no idea what you mean by this statement.
We cannot give meaningful advice without detailed and digestible information and yours is neither.

For the most part, if you want to implement some style that is similar to an existing one, then you just have to follow the existing source code. How well that works depends entirely on your personal programming skills and how well you are at reading and understanding C++ (and CUDA?) code.

Please note that LAMMPS supports two different ways to add support for GPU acceleration. The GPU package is one option, the KOKKOS package a second. For the latter, we have a recorded live stream explaining the Kokkos programming model and how the KOKKOS package in LAMMPS is implemented available at: https://www.youtube.com/@templelammps/streams

I’m sorry I didn’t express the information clearly.
pair_2bandl_gpu.cpp (8.9 KB)
pair_2bandl_gpu.h (1.5 KB)

The two files above are the ones I have currently written, which were written with reference to pair_ eam_gpu. cpp and pair_ eam_gpu. h. However, an error was prompted during compilation: “undefined reference to `twobandl_gpu_clear()'”.

In the recent period, I have studied the relevant content again. I seem to need to write the corresponding program in the lib/gpu folder to implement this function. But I found that there is a file (eam_cubin. h) inside that is not normal code. May I ask how this code is written and executed. Thank you for your patience.

It is not written but generated as part of the compilation. It contains the compiled CUDA kernel(s) a C-style string objects to they can be embedded into the executable and use for JIT compilation.

Here is the traditional make rule

$(OBJ_DIR)/%_cubin.h: lal_%.cu  $(ALL_H)
        $(CUDA) --fatbin -DNV_KERNEL -o $(OBJ_DIR)/$*.cubin $(OBJ_DIR)/lal_$*.cu
        $(BIN2C) -c -n $* $(OBJ_DIR)/$*.cubin > $@

and here the corresponding CMake code:

cuda_compile_fatbin(GPU_GEN_OBJS ${GPU_LIB_CU} OPTIONS ${CUDA_REQUEST_PIC}
          -DUNIX -O3 --use_fast_math -Wno-deprecated-gpu-targets -allow-unsupported-compiler -DNV_KERNEL -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING} -DLAMMPS_${LAMMPS_SIZES})

cuda_compile(GPU_OBJS ${GPU_LIB_CUDPP_CU} OPTIONS ${CUDA_REQUEST_PIC}
          -DUNIX -O3 --use_fast_math -Wno-deprecated-gpu-targets -allow-unsupported-compiler -DUCL_CUDADR ${GPU_CUDA_GENCODE} -D_${GPU_PREC_SETTING} -DLAMMPS_${LAMMPS_SIZES})

foreach(CU_OBJ ${GPU_GEN_OBJS})
    get_filename_component(CU_NAME ${CU_OBJ} NAME_WE)
    string(REGEX REPLACE "^.*_lal_" "" CU_NAME "${CU_NAME}")
    add_custom_command(OUTPUT ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h
      COMMAND ${BIN2C} -c -n ${CU_NAME} ${CU_OBJ} > ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h
      DEPENDS ${CU_OBJ}
      COMMENT "Generating ${CU_NAME}_cubin.h")
    list(APPEND GPU_LIB_SOURCES ${LAMMPS_LIB_BINARY_DIR}/gpu/${CU_NAME}_cubin.h)
  endforeach()
  set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${LAMMPS_LIB_BINARY_DIR}/gpu/*_cubin.h")

In that case, lal_eam.cpp, lal_eam.h, lal_eam_ext.cpp are they necessary to write it by myself and then put it in the lib/gpu folder, and then recompile it?

Dear akohlmey,
I have written a lal_2bandl.cpp program, but I am not sure if it is correct. I am not sure if the addition of fps (which includes max_fps_size, * fps_ptr, _fps. host. regin(), fps_tex, etc.) is correct, especially.
Do you know how to debug or test?

lal_2bandl.cpp (23.6 KB)
This is the .cpp file.