Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e3eef8c
Example use of NAMD CudaGlobalMaster interface
HanatoK Mar 20, 2025
08c5b6e
refactor: use CUDA to transpose the positions
HanatoK Mar 21, 2025
8bf3c67
fix: correct the atom id setup and update the masses and charges
HanatoK Mar 21, 2025
0fa8cdb
chore: cleanups
HanatoK Mar 21, 2025
f243f13
chore: remove the debugging log
HanatoK Mar 21, 2025
1c7734d
fix: use the correct path for Colvars source code
HanatoK Mar 23, 2025
e813945
prof: use nvtx to profile Colvars
HanatoK Mar 24, 2025
b856893
refactor: using custom allocator for CUDA
HanatoK Mar 24, 2025
09ec341
opt: remove the unnecessary stream synchronization
HanatoK Mar 24, 2025
dc136be
opt: transpose to the device arrays at first and then copy to pinned
HanatoK Mar 25, 2025
73a98ef
Fix the deallocate of CudaHostAllocator
HanatoK Mar 25, 2025
1c57351
Fix the compilation with C++11
HanatoK Mar 25, 2025
f13c761
opt: use the onBuffersUpdated interface to separate the data moving from
HanatoK Mar 25, 2025
66a41d0
feature: support NAMD_TCL
HanatoK Mar 26, 2025
a0fea64
Squashed commit of the following:
HanatoK Mar 27, 2025
62b92b7
fix: fix the support of cv reset
HanatoK Mar 27, 2025
ecd5acd
fix: fix the setup and initialization
HanatoK Mar 28, 2025
0a3624b
feat: add TCL and LEPTON to the CMakeLists.txt file
HanatoK Mar 28, 2025
2a6fe6c
fix: implement TCL callback functions
HanatoK Mar 28, 2025
bc0cb54
workaround: use an independent TCL interpreter for Colvars
HanatoK Mar 28, 2025
ce7ed9b
fix: setup the constants that are missing
HanatoK Mar 31, 2025
c0dad04
fix: move the setup of initial step out of setup()
HanatoK Mar 31, 2025
bce33de
fix: check the last CUDA error after launching the kernels
HanatoK Apr 1, 2025
da3ecdf
fix: fix the total force calculation
HanatoK Apr 1, 2025
7ce04b4
Mark this plugin to be incompatible with the Colvars bundled with NAMD
HanatoK Apr 1, 2025
bc6c646
doc: add README.md for the plugin
HanatoK Apr 1, 2025
48372f9
opt: make sure the DtoH memcpy overlaps with the NB kernel
HanatoK Apr 3, 2025
8e11bab
Track Charm++ include directory
giacomofiorin Apr 10, 2025
a91a6ac
Add missing test input file
giacomofiorin Apr 11, 2025
df662ac
refactor: rename the vector types with host-pinned memory allocator
HanatoK Apr 14, 2025
a7a6753
Add missing instruction in README
jhenin May 11, 2025
67b82f4
Move the CudaGlobalMaster plugin to namd/
HanatoK May 12, 2025
7658b78
doc: correct the path in README.md of CudaGlobalMaster
HanatoK May 12, 2025
a238095
doc: CudaGlobalMaster is currently not compatible with minimization
HanatoK May 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions namd/cudaglobalmaster/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/*
/example/output/*
.clangd
100 changes: 100 additions & 0 deletions namd/cudaglobalmaster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
include(CheckIncludeFile)
project(cudaglobalmastercolvars LANGUAGES CXX)

option(NAMD_TCL "If your NAMD is built with TCL, use ON" ON)
option(NAMD_NVTX_ENABLED "If your NAMD is built with -DNAMD_NVTX_ENABLED, use ON" OFF)
set(NAMD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." CACHE STRING "NAMD source code directory")
set(NAMD_HEADER_DIR "${NAMD_DIR}/src" CACHE STRING "NAMD header directory")
set(CHARM_HEADER_DIR "${NAMD_DIR}/charm/include" CACHE STRING "Charm++ header directory")
set(MOLFILE_PLUGIN_HEADER_DIR "${NAMD_DIR}/plugins/include" CACHE STRING "Molfile plugin header directory")
set(COLVARS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../src" CACHE STRING "Colvars source code directory")
set(NAMD_TCL_INCLUDE_DIR "${NAMD_DIR}/tcl8.6.13-linux-x86_64-threaded/include" CACHE STRING "TCL header directory")
set(NAMD_LEPTON_DIR "${NAMD_DIR}/lepton" CACHE STRING "Lepton library directory")
set(NAMD_LEPTON_INCLUDE_DIR "${NAMD_LEPTON_DIR}/include" CACHE STRING "Lepton header directory")
set(NAMD_LEPTON_SOURCE_DIR "${NAMD_LEPTON_DIR}/src" CACHE STRING "Lepton source directory")

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES native)
endif()

message(STATUS "NAMD_HEADER_DIR is ${NAMD_HEADER_DIR}")
message(STATUS "CHARM_HEADER_DIR is ${CHARM_HEADER_DIR}")
message(STATUS "MOLFILE_PLUGIN_HEADER_DIR is ${MOLFILE_PLUGIN_HEADER_DIR}")
message(STATUS "COLVARS_SOURCE_DIR is ${COLVARS_SOURCE_DIR}")
message(STATUS "NAMD_TCL_INCLUDE_DIR is ${NAMD_TCL_INCLUDE_DIR}")
message(STATUS "NAMD_LEPTON_INCLUDE_DIR is ${NAMD_LEPTON_INCLUDE_DIR}")
message(STATUS "NAMD_LEPTON_SOURCE_DIR is ${NAMD_LEPTON_SOURCE_DIR}")

if(NOT EXISTS ${NAMD_HEADER_DIR})
message(FATAL_ERROR "The NAMD header directory ${NAMD_HEADER_DIR} does not exist!")
endif()

if(NOT EXISTS ${MOLFILE_PLUGIN_HEADER_DIR})
message(FATAL_ERROR "The molfile plugin header directory ${MOLFILE_PLUGIN_HEADER_DIR} does not exist!")
endif()

if(NOT EXISTS ${COLVARS_SOURCE_DIR})
message(FATAL_ERROR "The Colvars source directory ${COLVARS_SOURCE_DIR} does not exist!")
endif()

if(NOT EXISTS ${NAMD_LEPTON_INCLUDE_DIR})
message(FATAL_ERROR "The Lepton include directory ${NAMD_LEPTON_INCLUDE_DIR} does not exist!")
endif()

if(NOT EXISTS ${NAMD_LEPTON_SOURCE_DIR})
message(FATAL_ERROR "The Lepton source directory ${NAMD_LEPTON_SOURCE_DIR} does not exist!")
endif()

file(GLOB COLVARS_SOURCES ${COLVARS_SOURCE_DIR}/[^.]*.cpp)
file(GLOB LEPTON_SOURCES ${NAMD_LEPTON_SOURCE_DIR}/[^.]*.cpp)

find_package(CUDAToolkit)
include(CheckLanguage)
check_language(CUDA)
enable_language(CUDA)

if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()

if(NAMD_TCL)
message(STATUS "add -DNAMD_TCL to compiler flags")
add_definitions(-DCOLVARS_TCL)
if(NOT EXISTS ${NAMD_TCL_INCLUDE_DIR})
message(WARNING "-DNAMD_TCL is enabled but TCL headers are not found in ${NAMD_TCL_INCLUDE_DIR}")
message(WARNING "Trying to find TCL from the system")
find_package(TCL)
if(${TCL_FOUND})
set(NAMD_TCL_INCLUDE_DIR CACHE STRING "${TCL_INCLUDE_PATH}")
endif()
endif()
message(STATUS "TCL headers are found in ${NAMD_TCL_INCLUDE_DIR}")
endif()

if(NAMD_NVTX_ENABLED)
message(STATUS "add -DNAMD_NVTX_ENABLED and -DCUDAGLOBALMASTERCOLVARS_CUDA_PROFILING to compiler flags")
add_definitions(-DNAMD_NVTX_ENABLED -DCUDAGLOBALMASTERCOLVARS_CUDA_PROFILING)
endif()

add_definitions(-DNAMD_CUDA -DNODEGROUP_FORCE_REGISTER -DCOLVARS_CUDA -DLEPTON)
add_library(
cudaglobalmastercolvars SHARED
colvarproxy_cudaglobalmaster.h
colvarproxy_cudaglobalmaster.C
colvarproxy_cudaglobalmaster_kernel.h
colvarproxy_cudaglobalmaster_kernel.cu
${LEPTON_SOURCES}
${COLVARS_SOURCES})
target_include_directories(cudaglobalmastercolvars
PUBLIC "${COLVARS_SOURCE_DIR}"
PUBLIC "${NAMD_HEADER_DIR}"
PUBLIC "${CHARM_HEADER_DIR}"
PUBLIC "${MOLFILE_PLUGIN_HEADER_DIR}"
PUBLIC "${NAMD_TCL_INCLUDE_DIR}"
PUBLIC "${NAMD_LEPTON_INCLUDE_DIR}")
target_link_libraries(cudaglobalmastercolvars CUDA::cudart CUDA::nvToolsExt)
target_compile_options(cudaglobalmastercolvars PRIVATE -Wno-register)
set_property(TARGET cudaglobalmastercolvars PROPERTY LANGUAGE CUDA)
# set_property(TARGET cudaglobalmastercolvars PROPERTY CUDA_ARCHITECTURES OFF)
39 changes: 39 additions & 0 deletions namd/cudaglobalmaster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# NAMD CudaGlobalMaster Interface with Colvars

This is an experimental Colvars plugin that can be loaded using the NAMD's new CudaGlobalMaster interface. In the GPU-resident mode, although this plugin requires to copy the data from GPU to CPU due to Colvars' CPU-only code, it still runs Colvars significantly faster than the NAMD's bundled Colvars using the traditional GlobalMaster interface, mainly because it avoids the multiple memory copies in the traditional GlobalMaster code path and only copies the atoms that requested by Colvars.

## Compilation

This plugin depends on the source code of [NAMD](https://gitlab.com/tcbgUIUC/namd) (the [`opt_cudagm` branch](https://gitlab.com/tcbgUIUC/namd/-/tree/opt_cudagm?ref_type=heads)), [the CUDA compiler](https://developer.nvidia.com/cuda-downloads) and libraries and optionally the [TCL library](https://www.tcl-lang.org) (if your NAMD is built with TCL support). To compile this plugin you also need [cmake version 3.23 or above](https://cmake.org/download/).

Commands to compile the plugin under this directory:
```sh
mkdir build
cd build
cmake -DNAMD_DIR=<your_namd_git_directory>/ -DCMAKE_BUILD_TYPE=Release ../
make -j4
```
After the compilation, you will get a shared library named `libcudaglobalmastercolvars.so`.

### Notes for developers

If you built your NAMD with `-DNAMD_NVTX_ENABLED`, then you also need to switch that on in the CMake command by `-DNAMD_NVTX_ENABLED=on`. If you want to build the plugin on one computer but later want to run NAMD with it on another system, it is better to add `-DCMAKE_CUDA_ARCHITECTURES=all-major` to the CMake command.

## Example usage

This plugin is incompatible with the traditional way of using Colvars in NAMD, so you cannot use `colvars on` in your NAMD configuration and `numSteps` with it. Instead, please use the following TCL command in your NAMD configuration file before `run`:
```tcl
gpuGlobal on
gpuGlobalCreateClient <the_absolute_path_to_this_dir>/build/libcudaglobalmastercolvars.so COLVARS <colvars_config_file>
```

The example NAMD input file can be found in `<the_absolute_path_to_this_dir>/example/alad.namd`, which dynamically loads the shared library built above and runs an OPES simulation along the two dihedral angles of the alanine dipeptide.

## Limitations

This plugin is still in its early stage, and has the following limitations:
- Limited scripting support. You can call Colvars between `run`s by `gpuGlobalUpdateClient COLVARS cv <command>`. For example, you can reset Colvars by `gpuGlobalUpdateClient COLVARS cv reset`, and then load another configuration file by `gpuGlobalUpdateClient COLVARS cv configfile <new_config_file>`. However, you cannot use scripted Colvars force, and since this plugin uses an independent interpreter for the Colvars instance, so you cannot call NAMD's TCL procedures in the calculation of scripted CVs;
- `volmap` is not available;
- GaMD energy histograming/reweighting is not available (GaMD is not currently available in GPU-resident NAMD);
- Minimization is not supported since `minimize` in the NAMD GPU-resident mode actually calls the GPU-offload code path;
- SMP is not available.
Loading