Skip to content

Commit

Permalink
Use CustomCPPForceImpl to simplify code (#70)
Browse files Browse the repository at this point in the history
* Use CustomCPPForceImpl to simplify code

* Assorted cleanup

* Bug fix

* Remove obsolete references to CUDA and OpenCL in CI scripts

* Updated python versions for CI
  • Loading branch information
peastman authored Nov 29, 2023
1 parent 66873f7 commit cc79ab7
Show file tree
Hide file tree
Showing 41 changed files with 160 additions and 14,985 deletions.
34 changes: 6 additions & 28 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,15 @@ jobs:
fail-fast: false
matrix:
include:
- name: Linux CPU CUDA 11.0 Python 3.6
python-version: "3.6"
- name: Linux CPU Python 3.12
python-version: "3.12"
os: ubuntu-latest
gcc-version: "9"
cuda-version: "11.0"
cdt-name: cos7 # CentOS sysroot: cuda 10.x needs cos6, 11+ needs cos7
CMAKE_FLAGS: |
-DPLUMED_BUILD_CUDA_LIB=ON \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-DEXTRA_COMPILE_FLAGS="-L/usr/local/cuda/lib64/stubs -Wl,-rpath,/usr/local/cuda/lib64/stubs -Wl,-rpath-link,/usr/local/cuda/lib64/stubs"
- name: MacOS Intel CPU OpenCL Python 3.9
python-version: "3.9"
cdt-name: cos7

- name: MacOS Intel CPU OpenCL Python 3.10
python-version: "3.10"
os: macos-latest
cuda-version: ""
CMAKE_FLAGS: ""

steps:
Expand All @@ -47,7 +41,6 @@ jobs:
run: |
sed -i -e "s/@CDT_NAME@/${{ matrix.cdt-name }}/g" \
-e "s/@GCC_VERSION@/${{ matrix.gcc-version }}.*/g" \
-e "s/@CUDATOOLKIT_VERSION@/${{ matrix.cuda-version }}.*/g" \
devtools/conda-envs/build-${{ matrix.os }}.yml
- uses: conda-incubator/setup-miniconda@v2
Expand All @@ -59,12 +52,6 @@ jobs:
auto-activate-base: false
channels: conda-forge

- name: "Install CUDA on Ubuntu (if needed)"
if: matrix.cuda-version != ''
env:
CUDA_VERSION: ${{ matrix.cuda-version }}
run: source devtools/scripts/install_cuda.sh

- name: "Set SDK on MacOS (if needed)"
if: startsWith(matrix.os, 'macos')
run: source devtools/scripts/install_macos_sdk.sh
Expand Down Expand Up @@ -98,9 +85,6 @@ jobs:
-DOPENMM_DIR=${CONDA_PREFIX} \
-DPLUMED_INCLUDE_DIR=${CONDA_PREFIX}/include/plumed \
-DPLUMED_LIBRARY_DIR=${CONDA_PREFIX}/lib \
-DPLUMED_BUILD_OPENCL_LIB=ON \
-DOPENCL_INCLUDE_DIR=${CONDA_PREFIX}/include \
-DOPENCL_LIBRARY=${CONDA_PREFIX}/lib/libOpenCL${SHLIB_EXT} \
${{ matrix.CMAKE_FLAGS }}
- name: "Build"
Expand Down Expand Up @@ -131,12 +115,6 @@ jobs:
fn=$(basename $f)
echo "::group::$fn"
summary+="\n${fn}: "
if [[ $fn == *Cuda* ]]; then
echo "Skipping $fn..."
summary+="Skipped"
echo "::endgroup::"
continue
fi
echo "Running $fn..."
./${f}
thisexitcode=$?
Expand Down
26 changes: 1 addition & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,9 @@ INSTALL (FILES ${API_ONLY_INCLUDE_FILES_INTERNAL} DESTINATION include/internal)
# Enable testing

ENABLE_TESTING()
ADD_SUBDIRECTORY(tests)
ADD_SUBDIRECTORY(serialization/tests)

# Build the implementations for different platforms

ADD_SUBDIRECTORY(platforms/reference)

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
FIND_PACKAGE(OpenCL QUIET)
IF(OPENCL_FOUND)
SET(PLUMED_BUILD_OPENCL_LIB ON CACHE BOOL "Build implementation for OpenCL")
ELSE(OPENCL_FOUND)
SET(PLUMED_BUILD_OPENCL_LIB OFF CACHE BOOL "Build implementation for OpenCL")
ENDIF(OPENCL_FOUND)
IF(PLUMED_BUILD_OPENCL_LIB)
ADD_SUBDIRECTORY(platforms/opencl)
ENDIF(PLUMED_BUILD_OPENCL_LIB)

FIND_PACKAGE(CUDA QUIET)
IF(CUDA_FOUND)
SET(PLUMED_BUILD_CUDA_LIB ON CACHE BOOL "Build implementation for CUDA")
ELSE(CUDA_FOUND)
SET(PLUMED_BUILD_CUDA_LIB OFF CACHE BOOL "Build implementation for CUDA")
ENDIF(CUDA_FOUND)
IF(PLUMED_BUILD_CUDA_LIB)
ADD_SUBDIRECTORY(platforms/cuda)
ENDIF(PLUMED_BUILD_CUDA_LIB)

# Build the Python API

FIND_PROGRAM(PYTHON_EXECUTABLE python)
Expand Down
95 changes: 0 additions & 95 deletions FindOpenCL.cmake

This file was deleted.

12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,9 @@ files and libraries are installed.
6. Set CMAKE_INSTALL_PREFIX to the directory where the plugin should be installed. Usually,
this will be the same as OPENMM_DIR, so the plugin will be added to your OpenMM installation.

7. If you plan to build the OpenCL platform, make sure that OPENCL_INCLUDE_DIR and
OPENCL_LIBRARY are set correctly, and that PLUMED_BUILD_OPENCL_LIB is selected.
7. Press "Configure" again if necessary, then press "Generate".

8. If you plan to build the CUDA platform, make sure that CUDA_TOOLKIT_ROOT_DIR is set correctly
and that PLUMED_BUILD_CUDA_LIB is selected.

9. Press "Configure" again if necessary, then press "Generate".

10. Use the build system you selected to build and install the plugin. For example, if you
8. Use the build system you selected to build and install the plugin. For example, if you
selected Unix Makefiles, type `make install` to install the plugin, and `make PythonInstall` to
install the Python wrapper.

Expand Down Expand Up @@ -81,7 +75,7 @@ Simbios, the NIH National Center for Physics-Based Simulation of
Biological Structures at Stanford, funded under the NIH Roadmap for
Medical Research, grant U54 GM072970. See https://simtk.org.

Portions copyright (c) 2016 Stanford University and the Authors.
Portions copyright (c) 2016-2023 Stanford University and the Authors.

Authors: Peter Eastman

Expand Down
1 change: 0 additions & 1 deletion devtools/conda-envs/build-ubuntu-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies:
- openmm
- plumed >=2.7
- ocl-icd
- cudatoolkit @CUDATOOLKIT_VERSION@
- pocl
# test
- pytest
45 changes: 0 additions & 45 deletions devtools/scripts/install_cuda.sh

This file was deleted.

22 changes: 9 additions & 13 deletions openmmapi/include/internal/PlumedForceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
* -------------------------------------------------------------------------- */

#include "PlumedForce.h"
#include "openmm/internal/ForceImpl.h"
#include "openmm/Kernel.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/CustomCPPForceImpl.h"
#include "wrapper/Plumed.h"
#include <utility>
#include <set>
#include <string>
Expand All @@ -47,26 +48,21 @@ class System;
* This is the internal implementation of PlumedForce.
*/

class OPENMM_EXPORT_PLUMED PlumedForceImpl : public OpenMM::ForceImpl {
class OPENMM_EXPORT_PLUMED PlumedForceImpl : public OpenMM::CustomCPPForceImpl {
public:
PlumedForceImpl(const PlumedForce& owner);
~PlumedForceImpl();
void initialize(OpenMM::ContextImpl& context);
const PlumedForce& getOwner() const {
return owner;
}
void updateContextState(OpenMM::ContextImpl& context, bool& forcesInvalid) {
// This force field doesn't update the state directly.
}
double calcForcesAndEnergy(OpenMM::ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
void updateParametersInContext(OpenMM::ContextImpl& context);
double computeForce(OpenMM::ContextImpl& context, const std::vector<OpenMM::Vec3>& positions, std::vector<OpenMM::Vec3>& forces);
private:
const PlumedForce& owner;
OpenMM::Kernel kernel;
plumed plumedmain;
bool hasInitialized, usesPeriodic;
int lastStepIndex;
std::vector<double> masses, charges;
};

} // namespace PlumedPlugin
Expand Down
Loading

0 comments on commit cc79ab7

Please sign in to comment.