From 17b58083364397a056b285b57a11debfcaa18b89 Mon Sep 17 00:00:00 2001 From: Charlles Abreu Date: Mon, 11 Dec 2023 13:09:31 -0500 Subject: [PATCH] Changes in CMake configuration (#14) --- CMakeLists.txt | 22 ++++--- devtools/conda-recipes/anaconda/build.sh | 45 +++++++++++++++ devtools/conda-recipes/anaconda/meta.yaml | 70 +++++++++++++++++++++++ python/setup.py | 2 +- 4 files changed, 129 insertions(+), 10 deletions(-) create mode 100644 devtools/conda-recipes/anaconda/build.sh create mode 100644 devtools/conda-recipes/anaconda/meta.yaml diff --git a/CMakeLists.txt b/CMakeLists.txt index eac79fc..83c1b32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,20 +4,24 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.17) -PROJECT(OpenMMNonbondedSlicing VERSION 0.1) +PROJECT(OpenMMNonbondedSlicing VERSION 0.2.0) IF(DEFINED ENV{CONDA_PREFIX}) SET(OPENMM_DIR $ENV{CONDA_PREFIX} CACHE PATH "Where OpenMM is installed") - EXECUTE_PROCESS( - COMMAND conda list ^openmm\\b - OUTPUT_VARIABLE OPENMM_VERSION - ) - STRING(REGEX REPLACE ".* ([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" OPENMM_VERSION_MAJOR "${OPENMM_VERSION}") - STRING(REGEX REPLACE ".* [0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" OPENMM_VERSION_MINOR "${OPENMM_VERSION}") - ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MAJOR=${OPENMM_VERSION_MAJOR}) - ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MINOR=${OPENMM_VERSION_MINOR}) ENDIF(DEFINED ENV{CONDA_PREFIX}) +EXECUTE_PROCESS( + COMMAND conda list ^openmm\\b + OUTPUT_VARIABLE OPENMM_VERSION +) +IF (NOT OPENMM_VERSION) + MESSAGE(FATAL_ERROR "OpenMM conda package not found. Please install OpenMM with conda.") +ENDIF(NOT OPENMM_VERSION) +STRING(REGEX REPLACE ".* ([0-9]+)\\.[0-9]+\\.[0-9]+.*" "\\1" OPENMM_VERSION_MAJOR "${OPENMM_VERSION}") +STRING(REGEX REPLACE ".* [0-9]+\\.([0-9]+)\\.[0-9]+.*" "\\1" OPENMM_VERSION_MINOR "${OPENMM_VERSION}") +ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MAJOR=${OPENMM_VERSION_MAJOR}) +ADD_COMPILE_DEFINITIONS(OPENMM_VERSION_MINOR=${OPENMM_VERSION_MINOR}) + INCLUDE_DIRECTORIES("${OPENMM_DIR}/include") LINK_DIRECTORIES("${OPENMM_DIR}/lib" "${OPENMM_DIR}/lib/plugins") diff --git a/devtools/conda-recipes/anaconda/build.sh b/devtools/conda-recipes/anaconda/build.sh new file mode 100644 index 0000000..151fdbe --- /dev/null +++ b/devtools/conda-recipes/anaconda/build.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -euxo pipefail + +rm -rf build || true + +CMAKE_FLAGS=" -DCMAKE_INSTALL_PREFIX=${PREFIX}" +CMAKE_FLAGS+=" -DCMAKE_BUILD_TYPE=Release" + +CMAKE_FLAGS+=" -DOPENMM_DIR=${PREFIX}" +CMAKE_FLAGS+=" -DPLUGIN_LIBRARY_DIR=${PREFIX}/lib" + +# OpenCL +CMAKE_FLAGS+=" -DPLUGIN_BUILD_OPENCL_LIB=ON" +CMAKE_FLAGS+=" -DOPENCL_INCLUDE_DIR=${PREFIX}/include" +CMAKE_FLAGS+=" -DOPENCL_LIBRARY=${PREFIX}/lib/libOpenCL${SHLIB_EXT}" + +# if CUDA_HOME is defined and not empty, we enable CUDA +if [[ -n ${CUDA_HOME-} ]]; then + CMAKE_FLAGS+=" -DCUDA_TOOLKIT_ROOT_DIR=${CUDA_HOME}" + CMAKE_FLAGS+=" -DCMAKE_LIBRARY_PATH=${CUDA_HOME}/lib64/stubs" + CMAKE_FLAGS+=" -DPLUGIN_BUILD_CUDA_LIB=ON" +fi + +if [[ "$target_platform" == osx* ]]; then + CMAKE_FLAGS+=" -DCMAKE_OSX_SYSROOT=${CONDA_BUILD_SYSROOT}" + CMAKE_FLAGS+=" -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" +fi + +# Build in subdirectory and install. +mkdir -p build +cd build +cmake ${CMAKE_FLAGS} ${SRC_DIR} +make -j$CPU_COUNT install +make -j$CPU_COUNT PythonInstall + +# Include test executables too +mkdir -p ${PREFIX}/share/openmm-nonbonded-slicing/tests +if [[ "$target_platform" == osx* ]]; then + find . -name "Test*" -perm +0111 -type f \ + -exec python $RECIPE_DIR/patch_osx_tests.py "{}" \; \ + -exec cp "{}" $PREFIX/share/openmm-nonbonded-slicing/tests/ \; +else + find . -name "Test*" -executable -type f -exec cp "{}" $PREFIX/share/openmm-nonbonded-slicing/tests/ \; +fi \ No newline at end of file diff --git a/devtools/conda-recipes/anaconda/meta.yaml b/devtools/conda-recipes/anaconda/meta.yaml new file mode 100644 index 0000000..d767d70 --- /dev/null +++ b/devtools/conda-recipes/anaconda/meta.yaml @@ -0,0 +1,70 @@ +{% set version = environ['PLUGIN_VERSION'][1:] %} + +package: + name: openmm-nonbonded-slicing + version: {{ version }} + +source: + git_url: ../../../ + +build: + number: 0 + script: build.sh + +requirements: + build: + - {{ compiler('cxx') }} + - {{ compiler('cuda') }} # [linux and cuda_compiler_version != 'None'] + - {{ cdt('mesa-libgl-devel') }} # [linux] + - cmake + - make + - conda-build + + host: + - python + - pip + - openmm + - swig <4.1 + - ocl-icd # [linux] + - khronos-opencl-icd-loader # [osx] + run: + - python + - {{ pin_compatible('openmm', lower_bound='7.7') }} + - ocl-icd # [linux] + - ocl-icd-system # [linux] + - khronos-opencl-icd-loader # [osx] + - ocl_icd_wrapper_apple # [osx] + +test: + imports: + - nonbondedslicing + commands: | + cd ${PREFIX}/share/openmm-nonbonded-slicing/tests + set +e + for f in Test*; do + if [[ $f == *Cuda* || $f == *OpenCL* ]]; then + continue + fi + ./${f} + ((exitcode+=$?)) + done + exit $exitcode + +about: + home: https://github.com/craabreu/openmm-nonbonded-slicing + summary: 'An OpenMM plugin for slicing nonbonded interactions' + description: | + This plugin contains the SlicedNonbondedForce class, a variant of + OpenMM's NonbondedForce. By partitioning all particles among disjoint + subsets, the total potential energy becomes a linear combination of + contributions from pairs of subsets. + license: MIT + license_family: MIT + license_file: LICENSE.md + doc_url: https://craabreu.github.io/openmm-nonbonded-slicing + dev_url: https://github.com/craabreu/openmm-nonbonded-slicing + +extra: + recipe-maintainers: + - craabreu + - jananzhu \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index f6c395b..593ece4 100644 --- a/python/setup.py +++ b/python/setup.py @@ -31,7 +31,7 @@ setup( name='nonbondedslicing', - version='1.0', + version='@CMAKE_PROJECT_VERSION@', py_modules=['nonbondedslicing'], ext_modules=[extension], )