diff --git a/.github/workflows/ci-cuda12.yml b/.github/workflows/ci-cuda12.yml new file mode 100644 index 0000000..4ba3777 --- /dev/null +++ b/.github/workflows/ci-cuda12.yml @@ -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 + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 760f69b..8986d65 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 89f3491..c0346d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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) @@ -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()