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

Set c++17 standard in CMake for recent torch/cuda versions #109

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 84 additions & 0 deletions .github/workflows/ci-cuda12.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI-CUDA12

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
# Run every Sunday at midnight
- cron: '0 0 * * 0'

defaults:
run:
shell: bash -l {0}

jobs:
build:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
# Latest supported versions (with CUDA)
- name: Linux (CUDA 12, Python 3.11, PyTorch 2.1)
cuda: "12"
gcc: "11.*"
python: "3.11.*"
torchani: "2.2.*"
pytorch: "2.1.*"

steps:
- name: Check out
uses: actions/checkout@v2

- name: Install Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ""
auto-activate-base: true
miniforge-variant: Mambaforge

- name: Prepare dependencies (with CUDA)
run: |
sed -i -e "/cudatoolkit/c\ - cuda ${{ matrix.cuda }}" \
-e "/gxx_linux-64/c\ - gxx ${{ matrix.gcc }}" \
-e "/torchani/c\ - torchani ${{ matrix.torchani }}" \
-e "/nvcc_linux-64/d" \
-e "/python/c\ - python ${{ matrix.python }}" \
-e "/pytorch-gpu/c\ - pytorch-gpu ${{ matrix.pytorch }}" \
environment.yml
echo " - cuda-nvtx-dev" >> environment.yml
- name: Show dependency file
run: cat environment.yml

- name: Install dependencies
run: mamba env create -n nnpops -f environment.yml
env:
# Needed to install pytorch-gpu on a machine without a GPU
CONDA_OVERRIDE_CUDA: ${{ matrix.cuda }}
- name: List conda environment
run: |
conda activate nnpops
conda list

- name: Configure, compile, and install
# CUDA_INC_PATH is required because conda-forge installs CUDA headers to a non standard place
# TORCH_CUDA_ARCH_LIST is set to avoid torch setting an invalid one automatically
run: |
conda activate nnpops
mkdir build && cd build
CUDA_INC_PATH=$CONDA_PREFIX/$targetsDir/include cmake .. \
-DENABLE_CUDA=${{ matrix.enable_cuda }} \
-DTorch_DIR=$(python -c 'import torch.utils; print(torch.utils.cmake_prefix_path)')/Torch \
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
-DTORCH_CUDA_ARCH_LIST=8.9
make install

- name: Test
run: |
conda activate nnpops
cd build
ctest --verbose --exclude-regex TestCuda

24 changes: 7 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,23 @@ jobs:
torchani: "2.2.*"
pytorch: "1.12.*"

# Latest supported versions (with CUDA)
- name: Linux (CUDA 11.8, Python 3.10, PyTorch 2.0)
enable_cuda: true
cuda: "11.8.0"
gcc: "10.3.*"
nvcc: "11.8"
python: "3.10.*"
torchani: "2.2.*"
pytorch: "2.0.*"

# Latest supported versions (without CUDA)
- name: Linux (no CUDA, Python 3.10, PyTorch 2.0)
- name: Linux (no CUDA, Python 3.11, PyTorch 2.1)
enable_cuda: false
gcc: "10.3.*"
python: "3.10.*"
pytorch: "2.0.*"
gcc: "11.*"
python: "3.11.*"
pytorch: "2.1.*"
torchani: "2.2.*"

steps:
- name: Check out
uses: actions/checkout@v2

- name: Install CUDA Toolkit
uses: Jimver/cuda-toolkit@v0.2.10
- name: Install CUDA Toolkit
uses: Jimver/cuda-toolkit@v0.2.11
with:
cuda: ${{ matrix.cuda }}
linux-local-args: '["--toolkit", "--override"]'
linux-local-args: '["--toolkit", "--override"]'
if: ${{ matrix.enable_cuda }}

- name: Install Miniconda
Expand Down
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ endif(ENABLE_CUDA)
# Find dependencies
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
find_package(Torch REQUIRED)
# 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)
if(ENABLE_CUDA)
set(CMAKE_CUDA_STANDARD 17)
endif(ENABLE_CUDA)
message(STATUS "Setting C++ standard to C++17")
else()
set(CMAKE_CXX_STANDARD 14)
if(ENABLE_CUDA)
set(CMAKE_CUDA_STANDARD 14)
endif(ENABLE_CUDA)
message(STATUS "Setting C++ standard to C++14")
endif()

enable_testing()

# Source files of the library
Expand All @@ -32,12 +48,11 @@ set(SRC_FILES src/ani/CpuANISymmetryFunctions.cpp
# Build the library
set(LIBRARY ${NAME}PyTorch)
add_library(${LIBRARY} SHARED ${SRC_FILES})
set_property(TARGET ${LIBRARY} PROPERTY CXX_STANDARD 14)

target_include_directories(${LIBRARY} PRIVATE ${Python3_INCLUDE_DIRS}
src/ani src/pytorch src/schnet)
target_link_libraries(${LIBRARY} ${TORCH_LIBRARIES} ${Python3_LIBRARIES})
if(ENABLE_CUDA)
set_property(TARGET ${LIBRARY} PROPERTY CUDA_STANDARD 14)
target_compile_definitions(${LIBRARY} PRIVATE ENABLE_CUDA)
endif(ENABLE_CUDA)

Expand All @@ -51,10 +66,6 @@ endif(ENABLE_CUDA)
foreach(TEST_PATH ${TEST_PATHS})
cmake_path(GET TEST_PATH STEM TEST_NAME)
add_executable(${TEST_NAME} ${TEST_PATH})
set_property(TARGET ${TEST_NAME} PROPERTY CXX_STANDARD 14)
if(ENABLE_CUDA)
set_property(TARGET ${TEST_NAME} PROPERTY CUDA_STANDARD 14)
endif(ENABLE_CUDA)
target_link_libraries(${TEST_NAME} ${LIBRARY})
add_test(${TEST_NAME} ${TEST_NAME})
endforeach()
Expand Down
Loading