Skip to content

Commit 51615eb

Browse files
authored
add CI (#25)
* add CI * point to pytorch install * fix vars * fix vars again * create symlink * sudo * add mesa * Retry * make sure we only use conda-forge * pin pytorch * try other env config for ubuntu * try other way for cuda * try cmake_args * patch envs with versions * export CUDA_PATH too? * add nvcc metapkg * restraint nvcc too * link to stubs * make CUDA required (temporarily) * debug libcuda.so * symlink libcuda stub * fix symlink * try luck with library paths * try cmake_prefix_path * fix python paths * try different env vars * try like this instead * use extra_compile_flags * summarize skipped tests too * Clean up a bit * update readme * try pocl for tests * debug opencl platforms * more debugging * pytorch >= 1.7 * fix typo * explicit pytorch gpu * rename jobs * workaround with custom flag * alternative attempt * do not use cmake_args * is it opencl's fault? * is it openmm? * openmm _on linux_ * remove nvidia's opencl * try pocl again * force pytorch gpu * build opencl again * fix pytorch req * plugin info * try ld_library_path * add python tests too * fix ld path * fix pytest call * export ld for python tests too
1 parent 3ef5aa2 commit 51615eb

File tree

7 files changed

+278
-1
lines changed

7 files changed

+278
-1
lines changed

.github/workflows/CI.yml

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "master"
10+
schedule:
11+
# Nightly tests run on master by default:
12+
# Scheduled workflows run on the latest commit on the default or base branch.
13+
# (from https://help.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule)
14+
- cron: "0 0 * * *"
15+
16+
17+
jobs:
18+
unix:
19+
runs-on: ${{ matrix.os }}
20+
name: ${{ matrix.name }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
include:
25+
- name: Linux CPU CUDA 10.0 Python 3.6
26+
python-version: "3.6"
27+
os: ubuntu-latest
28+
gcc-version: "9"
29+
cuda-version: "10.0"
30+
cdt-name: cos6 # cuda 11+ requires cos7
31+
CMAKE_FLAGS: |
32+
-DNN_BUILD_CUDA_LIB=ON \
33+
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
34+
-DEXTRA_COMPILE_FLAGS="-L/usr/local/cuda/lib64/stubs -Wl,-rpath,/usr/local/cuda/lib64/stubs -Wl,-rpath-link,/usr/local/cuda/lib64/stubs"
35+
36+
- name: MacOS Intel CPU Python 3.9
37+
python-version: "3.9"
38+
os: macos-latest
39+
cuda-version: ""
40+
CMAKE_FLAGS: ""
41+
42+
43+
steps:
44+
- uses: actions/checkout@v2
45+
46+
- name: "Patch conda env (if needed)"
47+
if: startsWith(matrix.os, 'ubuntu')
48+
run: |
49+
sed -i -e "s/@CDT_NAME@/${{ matrix.cdt-name }}/g" \
50+
-e "s/@GCC_VERSION@/${{ matrix.gcc-version }}.*/g" \
51+
-e "s/@CUDATOOLKIT_VERSION@/${{ matrix.cuda-version }}.*/g" \
52+
devtools/conda-envs/build-${{ matrix.os }}.yml
53+
54+
- uses: conda-incubator/setup-miniconda@v2
55+
name: "Prepare base dependencies"
56+
with:
57+
python-version: ${{ matrix.python-version }}
58+
activate-environment: build
59+
environment-file: devtools/conda-envs/build-${{ matrix.os }}.yml
60+
auto-activate-base: false
61+
channels: conda-forge
62+
63+
- name: "Install CUDA on Ubuntu (if needed)"
64+
if: matrix.cuda-version != ''
65+
env:
66+
CUDA_VERSION: ${{ matrix.cuda-version }}
67+
run: source devtools/scripts/install_cuda.sh
68+
69+
- name: "Set SDK on MacOS (if needed)"
70+
if: startsWith(matrix.os, 'macos')
71+
run: source devtools/scripts/install_macos_sdk.sh
72+
73+
- name: "Conda info"
74+
shell: bash -l {0}
75+
run: |
76+
conda info -a
77+
conda list
78+
79+
- name: "Configure build with CMake"
80+
shell: bash -l {0}
81+
run: |
82+
mkdir build
83+
cd build
84+
85+
SHLIB_EXT=".so"
86+
if [[ ${{ matrix.os }} == macos-* ]]; then
87+
SHLIB_EXT=".dylib"
88+
fi
89+
90+
cmake .. \
91+
-DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} \
92+
-DCMAKE_PREFIX_PATH=${CONDA_PREFIX} \
93+
-DCMAKE_BUILD_TYPE=Release \
94+
-DOPENMM_DIR=${CONDA_PREFIX} \
95+
-DPYTORCH_DIR=${CONDA_PREFIX}/lib/python${{ matrix.python-version }}/site-packages/torch \
96+
-DTorch_DIR=${CONDA_PREFIX}/lib/python${{ matrix.python-version }}/site-packages/torch/share/cmake/Torch \
97+
-DNN_BUILD_OPENCL_LIB=ON \
98+
-DOPENCL_INCLUDE_DIR=${CONDA_PREFIX}/include \
99+
-DOPENCL_LIBRARY=${CONDA_PREFIX}/lib/libOpenCL${SHLIB_EXT} \
100+
${{ matrix.CMAKE_FLAGS }}
101+
102+
- name: "Build"
103+
shell: bash -l {0}
104+
run: |
105+
cd build
106+
make -j2 install
107+
make -j2 PythonInstall
108+
109+
- name: "Plugin information"
110+
shell: bash -l {0}
111+
run: |
112+
export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib/python${{ matrix.python-version }}/site-packages/torch/lib:${LD_LIBRARY_PATH}"
113+
python -c "import simtk.openmm as mm; print('---Loaded---', *mm.pluginLoadedLibNames, '---Failed---', *mm.Platform.getPluginLoadFailures(), sep='\n')"
114+
115+
- name: "Test C++"
116+
shell: bash -l {0}
117+
run: |
118+
export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib/python${{ matrix.python-version }}/site-packages/torch/lib:${LD_LIBRARY_PATH}"
119+
cd build
120+
set +e
121+
summary=""
122+
exitcode=0
123+
for f in Test*; do
124+
echo "::group::$f"
125+
summary+="\n${f}: "
126+
if [[ $f == *Cuda* ]]; then
127+
echo "Skipping $f..."
128+
summary+="Skipped"
129+
echo "::endgroup::"
130+
continue
131+
fi
132+
echo "Running $f..."
133+
./${f}
134+
thisexitcode=$?
135+
if [[ $thisexitcode == 0 ]]; then summary+="OK"; else summary+="FAILED"; fi
136+
((exitcode+=$thisexitcode))
137+
echo "::endgroup::"
138+
done
139+
echo "-------"
140+
echo "Summary"
141+
echo "-------"
142+
echo -e "${summary}"
143+
exit $exitcode
144+
145+
- name: "Test Python"
146+
shell: bash -l {0}
147+
run: |
148+
export LD_LIBRARY_PATH="${CONDA_PREFIX}/lib/python${{ matrix.python-version }}/site-packages/torch/lib:${LD_LIBRARY_PATH}"
149+
cd python/tests
150+
python -m pytest -v Test*

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[![GH Actions Status](https://github.com/openmm/openmm-torch/workflows/CI/badge.svg)](https://github.com/openmm/openmm-torch/actions?query=branch%3Amaster+workflow%3ACI)
2+
[![Conda](https://img.shields.io/conda/v/conda-forge/openmm-torch.svg)](https://anaconda.org/conda-forge/openmm-torch)
3+
[![Anaconda Cloud Badge](https://anaconda.org/conda-forge/openmm-torch/badges/downloads.svg)](https://anaconda.org/conda-forge/openmm-torch)
4+
15
OpenMM PyTorch Plugin
26
=====================
37

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: build
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
# build
6+
- cmake
7+
- make
8+
- compilers
9+
# host
10+
- python
11+
- pip
12+
- swig
13+
- openmm
14+
- pytorch-cpu >=1.7
15+
- khronos-opencl-icd-loader
16+
- pocl
17+
# test
18+
- pytest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: build
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
# build
6+
- cmake
7+
- make
8+
- gcc_linux-64 @GCC_VERSION@
9+
- gxx_linux-64 @GCC_VERSION@
10+
- nvcc_linux-64 @CUDATOOLKIT_VERSION@
11+
- libx11-common-@CDT_NAME@-x86_64
12+
- libx11-@CDT_NAME@-x86_64
13+
- mesa-dri-drivers-@CDT_NAME@-x86_64
14+
- mesa-dri1-drivers-@CDT_NAME@-x86_64
15+
- mesa-libgl-@CDT_NAME@-x86_64
16+
- mesa-libgl-devel-@CDT_NAME@-x86_64
17+
# host
18+
- python
19+
- pip
20+
- swig
21+
- openmm
22+
- pytorch >=1.7 cuda*
23+
- ocl-icd
24+
- cudatoolkit @CUDATOOLKIT_VERSION@
25+
- pocl
26+
# test
27+
- pytest

devtools/scripts/install_cuda.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This script install CUDA on Ubuntu-based systemws
2+
# It uses the Nvidia repos for Ubuntu 18.04, which as of Dec 2020
3+
# includes packages for CUDA 10.0, 10.1, 10.2, 11.0, 11.1, 11.2
4+
# Future versions might require an updated repo (maybe Ubuntu 20)
5+
# It expects a $CUDA_VERSION environment variable set to major.minor (e.g. 10.0)
6+
7+
set -euxo pipefail
8+
9+
# Enable retrying
10+
echo 'APT::Acquire::Retries "5";' | sudo tee /etc/apt/apt.conf.d/80-retries
11+
12+
sudo wget --retry-connrefused --waitretry=1 --read-timeout=20 --timeout=15 --tries 5 \
13+
-O /etc/apt/preferences.d/cuda-repository-pin-600 \
14+
https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
15+
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
16+
sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
17+
sudo apt-get update -qq
18+
19+
CUDA_APT=${CUDA_VERSION/./-}
20+
## cufft changed package names in CUDA 11
21+
if [[ ${CUDA_VERSION} == 10.* ]]; then CUFFT="cuda-cufft"; else CUFFT="libcufft"; fi
22+
sudo apt-get install -y \
23+
libgl1-mesa-dev cuda-compiler-${CUDA_APT} \
24+
cuda-drivers cuda-driver-dev-${CUDA_APT} \
25+
cuda-cudart-${CUDA_APT} cuda-cudart-dev-${CUDA_APT} \
26+
${CUFFT}-${CUDA_APT} ${CUFFT}-dev-${CUDA_APT} \
27+
cuda-nvprof-${CUDA_APT} tree
28+
sudo apt-get clean
29+
30+
if [[ ! -d /usr/local/cuda ]]; then
31+
sudo ln -s /usr/local/cuda-${CUDA_VERSION} /usr/local/cuda
32+
fi
33+
34+
if [[ -f /usr/local/cuda-${CUDA_VERSION}/lib64/stubs/libcuda.so ]]; then
35+
sudo ln -s /usr/local/cuda-${CUDA_VERSION}/lib64/stubs/libcuda.so /usr/local/cuda-${CUDA_VERSION}/lib64/stubs/libcuda.so.1
36+
fi
37+
38+
# Remove Nvidia's OpenCL
39+
sudo rm -rf /usr/local/cuda-${CUDA_VERSION}/lib64/libOpenCL.* /usr/local/cuda-${CUDA_VERSION}/include/CL /etc/OpenCL/vendors/nvidia.icd
40+
41+
export CUDA_HOME="/usr/local/cuda"
42+
export CUDA_PATH="/usr/local/cuda"
43+
export PATH="${CUDA_HOME}/bin:${PATH}"
44+
45+
echo "CUDA_HOME=${CUDA_HOME}" >> ${GITHUB_ENV}
46+
echo "CUDA_PATH=${CUDA_PATH}" >> ${GITHUB_ENV}
47+
echo "PATH=${PATH}" >> ${GITHUB_ENV}

devtools/scripts/install_macos_sdk.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Install an older MacOS SDK
2+
# This should guarantee OpenMM builds with extended compatibility across MacOS versions
3+
# Adapted from conda-forge-ci-setup scripts:
4+
# * https://github.com/conda-forge/conda-forge-ci-setup-feedstock/blob/dde296e/recipe/run_conda_forge_build_setup_osx
5+
# * https://github.com/conda-forge/conda-forge-ci-setup-feedstock/blob/dde296e/recipe/download_osx_sdk.sh
6+
#
7+
# Some possible updates might involve upgrading the download link to future MacOS releases (10.15 to something else),
8+
# depending on the version provided by the CI
9+
10+
OSX_SDK_DIR="$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs"
11+
export MACOSX_DEPLOYMENT_TARGET=10.9
12+
export MACOSX_SDK_VERSION=10.9
13+
14+
export CMAKE_OSX_SYSROOT="${OSX_SDK_DIR}/MacOSX${MACOSX_SDK_VERSION}.sdk"
15+
16+
if [[ ! -d ${CMAKE_OSX_SYSROOT}} ]]; then
17+
echo "Downloading ${MACOSX_SDK_VERSION} sdk"
18+
curl -L -O --connect-timeout 5 --max-time 10 --retry 5 --retry-delay 0 --retry-max-time 40 --retry-connrefused --retry-all-errors \
19+
https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX${MACOSX_SDK_VERSION}.sdk.tar.xz
20+
tar -xf MacOSX${MACOSX_SDK_VERSION}.sdk.tar.xz -C "$(dirname ${CMAKE_OSX_SYSROOT})"
21+
fi
22+
23+
if [[ "$MACOSX_DEPLOYMENT_TARGET" == 10.* ]]; then
24+
# set minimum sdk version to our target
25+
plutil -replace MinimumSDKVersion -string ${MACOSX_SDK_VERSION} $(xcode-select -p)/Platforms/MacOSX.platform/Info.plist
26+
plutil -replace DTSDKName -string macosx${MACOSX_SDK_VERSION}internal $(xcode-select -p)/Platforms/MacOSX.platform/Info.plist
27+
fi
28+
29+
echo "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" >> ${GITHUB_ENV}
30+
echo "CMAKE_OSX_SYSROOT=${MACOSX_DEPLOYMENT_TARGET}" >> ${GITHUB_ENV}
31+
echo "CMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}" >> ${GITHUB_ENV}

platforms/cuda/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ TARGET_LINK_LIBRARIES(${SHARED_TARGET} OpenMMCUDA)
6464
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${NN_LIBRARY_NAME})
6565
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES
6666
COMPILE_FLAGS "-DOPENMM_BUILDING_SHARED_LIBRARY ${EXTRA_COMPILE_FLAGS}"
67-
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}")
67+
LINK_FLAGS "${EXTRA_COMPILE_FLAGS} ${EXTRA_LINK_FLAGS_CUDA}")
6868
IF (APPLE)
6969
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "-F/Library/Frameworks -framework CUDA ${EXTRA_COMPILE_FLAGS}")
7070
ENDIF (APPLE)

0 commit comments

Comments
 (0)