Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally set C++17 for latest pytorch versions #126

Closed
wants to merge 18 commits into from
Closed
56 changes: 42 additions & 14 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,33 @@ jobs:
matrix:
include:
# Oldest supported versions
# NOTE: renable CUDA 10.2 when it supported by NNPOps (https://github.com/conda-forge/nnpops-feedstock/pull/8)
- name: Linux (CUDA 11.0, Python 3.7, PyTorch 1.11)
os: ubuntu-22.04
cuda-version: "11.0.3"
gcc-version: "8.5.*"
nvcc-version: "11.0"
python-version: "3.7"
pytorch-version: "1.11.*"
envfile: build-ubuntu-22.04

# Latest supported versions
- name: Linux (CUDA 11.8, Python 3.10, PyTorch 2.0)
- name: Linux (CUDA 12.0, Python 3.11, PyTorch 2.1.2)
os: ubuntu-22.04
cuda-version: "11.8.0"
gcc-version: "10.3.*"
nvcc-version: "11.8"
python-version: "3.10"
pytorch-version: "2.0.*"

cuda-version: "12.0"
gcc-version: "12.3.*"
nvcc-version: ""
python-version: "3.11"
pytorch-version: "2.1.2"
envfile: build-cuda12

- name: MacOS (Python 3.9, PyTorch 1.9)
os: macos-11
cuda-version: ""
gcc-version: ""
nvcc-version: ""
python-version: "3.9"
pytorch-version: "1.9.*" # Some test fails with 1.10

envfile: build-macos-11

steps:
- name: "Check out"
Expand All @@ -59,7 +60,7 @@ jobs:
with:
cuda: ${{ matrix.cuda-version }}
linux-local-args: '["--toolkit", "--override"]'
if: startsWith(matrix.os, 'ubuntu')
if: startsWith(matrix.cuda-version, '11')

- name: "Install SDK on MacOS (if needed)"
run: source devtools/scripts/install_macos_sdk.sh
Expand All @@ -70,23 +71,50 @@ jobs:
with:
tokenPrefix: '@'
tokenSuffix: '@'
files: devtools/conda-envs/build-${{ matrix.os }}.yml
files: devtools/conda-envs/${{ matrix.envfile }}.yml
env:
CUDATOOLKIT_VERSION: ${{ matrix.cuda-version }}
GCC_VERSION: ${{ matrix.gcc-version }}
NVCC_VERSION: ${{ matrix.nvcc-version }}
PYTORCH_VERSION: ${{ matrix.pytorch-version }}

- uses: conda-incubator/setup-miniconda@v2
- name: Print env file
run: cat devtools/conda-envs/${{ matrix.envfile }}.yml

- name: Manage disk space
if: matrix.os == 'ubuntu'
run: |
sudo mkdir -p /opt/empty_dir || true
for d in \
/opt/ghc \
/opt/hostedtoolcache \
/usr/lib/jvm \
/usr/local/.ghcup \
/usr/local/lib/android \
/usr/local/share/powershell \
/usr/share/dotnet \
/usr/share/swift \
; do
sudo rsync --stats -a --delete /opt/empty_dir/ $d || true
done
sudo apt-get purge -y -f firefox \
google-chrome-stable \
microsoft-edge-stable
sudo apt-get autoremove -y >& /dev/null
sudo apt-get autoclean -y >& /dev/null
sudo docker image prune --all --force
df -h

- uses: conda-incubator/setup-miniconda@v3
name: "Install dependencies with Mamba"
with:
activate-environment: build
environment-file: devtools/conda-envs/build-${{ matrix.os }}.yml
environment-file: devtools/conda-envs/${{ matrix.envfile }}.yml
miniforge-variant: Mambaforge
python-version: ${{ matrix.python-version }}
env:
# Override the CUDA detection as the CI hosts don't have NVIDIA drivers
CONDA_OVERRIDE_CUDA: ${{ matrix.nvcc-version }}
CONDA_OVERRIDE_CUDA: ${{ matrix.cuda-version }}

- name: "List conda packages"
shell: bash -l {0}
Expand Down
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# OpenMM PyTorch Plugin
#----------------------------------------------------

CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
CMAKE_MINIMUM_REQUIRED(VERSION 3.7)

# We need to know where OpenMM is installed so we can access the headers and libraries.
SET(OPENMM_DIR "/usr/local/openmm" CACHE PATH "Where OpenMM is installed")
Expand All @@ -14,8 +14,15 @@ SET(PYTORCH_DIR "" CACHE PATH "Where the PyTorch C++ API is installed")
SET(CMAKE_PREFIX_PATH "${PYTORCH_DIR}")
FIND_PACKAGE(Torch REQUIRED)

# Specify the C++ version we are building for.
SET (CMAKE_CXX_STANDARD 14)
# Specify the C++ version we are building for. Latest pytorch versions require C++17
message(STATUS "Found Torch: ${Torch_VERSION}")
if(${Torch_VERSION} VERSION_GREATER_EQUAL "2.1.0")
set(CMAKE_CXX_STANDARD 17)
message(STATUS "Setting C++ standard to C++17")
else()
set(CMAKE_CXX_STANDARD 14)
message(STATUS "Setting C++ standard to C++14")
endif()

# Set flags for linking on mac
IF(APPLE)
Expand Down
27 changes: 27 additions & 0 deletions devtools/conda-envs/build-cuda12.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: build
channels:
- conda-forge
dependencies:
- cmake
- cuda-version @CUDATOOLKIT_VERSION@
- cuda-libraries-dev
- cuda-nvcc
- cuda-driver-dev
- cuda-nvtx-dev
- cuda-nvrtc-dev
- gxx @GCC_VERSION@
- make
- nnpops
- ocl-icd
- openmm >=7.7
- pip
- pocl
- pytest
- python
- pytorch-gpu @PYTORCH_VERSION@
- swig
- sysroot_linux-64 2.17
- torchani
# Required by python<3.8
# xref: https://github.com/conda-forge/linux-sysroot-feedstock/issues/52
- libxcrypt
3 changes: 3 additions & 0 deletions devtools/conda-envs/build-ubuntu-22.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ dependencies:
- swig
- sysroot_linux-64 2.17
- torchani
# Required by python<3.8
# xref: https://github.com/conda-forge/linux-sysroot-feedstock/issues/52
- libxcrypt
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_custom_command(
add_custom_target(PythonInstall DEPENDS "${WRAP_FILE}" "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
set(NN_PLUGIN_HEADER_DIR "${CMAKE_SOURCE_DIR}/openmmapi/include")
set(NN_PLUGIN_LIBRARY_DIR "${CMAKE_BINARY_DIR}")
set(EXTENSION_CXX_STANDARD "${CMAKE_CXX_STANDARD}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
add_custom_command(TARGET PythonInstall
COMMAND "${PYTHON_EXECUTABLE}" -m pip install .
Expand Down
3 changes: 2 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
torch_include_dirs = '@TORCH_INCLUDE_DIRS@'.split(';')
nn_plugin_header_dir = '@NN_PLUGIN_HEADER_DIR@'
nn_plugin_library_dir = '@NN_PLUGIN_LIBRARY_DIR@'
cpp_std = '@EXTENSION_CXX_STANDARD@'
torch_dir, _ = os.path.split('@TORCH_LIBRARY@')

# setup extra compile and link arguments on Mac
extra_compile_args = ['-std=c++14']
extra_compile_args = ['-std=c++' + cpp_std]
extra_link_args = []

if platform.system() == 'Darwin':
Expand Down
Loading