conda-forge / torchani-feedstock

A conda-smithy repository for torchani.
BSD 3-Clause "New" or "Revised" License
1 stars 9 forks source link

Build torchani with a cuda extension #1

Closed hadim closed 2 years ago

hadim commented 3 years ago

Checklist

DO NOT MERGE:

conda-forge-linter commented 3 years ago

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

hadim commented 3 years ago

@scopatz @jakirkham do you mind having a quick look whenever you have time? (this is not urgent at all)

I am trying to build this package against cuda and pytorch.

Here is the setup.py file used:

import importlib
from setuptools import setup, find_packages

ext_modules = []
cmdclass = {}

# Check whether torch is available
if importlib.util.find_spec("torch") is not None:
    import torch

    # Check whether Cuda is available
    if torch.cuda.is_available():

        from torch.utils.cpp_extension import BuildExtension, CUDAExtension

        cuda_version = float(torch.version.cuda)

        print(f"Building with CUDA support for CUDA: {cuda_version}")

        nvcc_args = [
            "-gencode=arch=compute_50,code=sm_50",
            "-gencode=arch=compute_60,code=sm_60",
            "-gencode=arch=compute_61,code=sm_61",
            "-gencode=arch=compute_70,code=sm_70",
            "-Xptxas=-v",
            "--expt-extended-lambda",
            "-use_fast_math",
        ]

        if cuda_version >= 10:
            nvcc_args.append("-gencode=arch=compute_75,code=sm_75")
        if cuda_version >= 11:
            nvcc_args.append("-gencode=arch=compute_80,code=sm_80")
        if cuda_version >= 11.1:
            nvcc_args.append("-gencode=arch=compute_86,code=sm_86")

        ext_modules = [
            CUDAExtension(
                name="cuaev",
                sources=["torchani/extension/aev.cu"],
                extra_compile_args={"cxx": ["-std=c++14"], "nvcc": nvcc_args},
            )
        ]

        cmdclass = {"build_ext": BuildExtension}

with open("README.md", "r") as fh:
    long_description = fh.read()

setup(
    name="torchani",
    description="PyTorch implementation of ANI",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/aiqm/torchani",
    author="Xiang Gao",
    author_email="qasdfgtyuiop@gmail.com",
    license="MIT",
    packages=find_packages(),
    include_package_data=True,
    use_scm_version=True,
    setup_requires=["setuptools_scm"],
    install_requires=["torch", "lark-parser", "requests"],
    ext_modules=ext_modules,
    cmdclass=cmdclass,
)

The idea is to build the package both without cuda (no extension are built) and also with cuda. The cuda kernel also needs to be built against pytorch.

The build seems to work locally but it looks like the pytorch version selected during the build phase is only the cpu version instead of the cuda version when cuda_compiler_version != "None". In consequence pip install does not trigger any cuda build (see setup.py for the logic).

Could you check the cuda logic in the recipe is correct?

Also, my understanding is that once the build is working, then conda will automatically select the correct torchani version according to whether the conda env has cuda installed or not and fallback to the cuda=None version if no cudatoolkit detected (or cpuonly is installed?). Can you confirm my understanding is correct here?

hadim commented 3 years ago

@conda-forge-admin please rerender

conda-forge-linter commented 3 years ago

Hi! This is the friendly automated conda-forge-linting service.

I wanted to let you know that I linted all conda-recipes in your PR (recipe) and found some lint.

Here's what I've got...

For recipe:

conda-forge-linter commented 3 years ago

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

hadim commented 3 years ago

@conda-forge-admin please rerender

github-actions[bot] commented 3 years ago

Hi! This is the friendly automated conda-forge-webservice. I tried to rerender for you, but it looks like there was nothing to do.

hadim commented 3 years ago

@conda-forge-admin please rerender

github-actions[bot] commented 3 years ago

Hi! This is the friendly automated conda-forge-webservice. I tried to rerender for you, but it looks like there was nothing to do.

hadim commented 3 years ago

I feel like it's not possible to build using torch/extension.h since the "correct" pytorch packages are neither on conda-forge and default channels.

hadim commented 3 years ago

@conda-forge-admin please rerender

github-actions[bot] commented 3 years ago

Hi! This is the friendly automated conda-forge-webservice. I tried to rerender for you, but it looks like there was nothing to do.

hadim commented 3 years ago

Ok even adding the pytorch channel doesn't work. I am clueless at this point :-D

hadim commented 3 years ago

xref with https://github.com/conda-forge/pytorch-cpu-feedstock/pull/20 and https://github.com/conda-forge/pytorch-cpu-feedstock/issues/7

hadim commented 3 years ago

Try to follow what is being done for this recipe https://github.com/conda-forge/staged-recipes/pull/13659/files?

conda-forge-linter commented 3 years ago

Hi! This is the friendly automated conda-forge-linting service.

I wanted to let you know that I linted all conda-recipes in your PR (recipe) and found some lint.

Here's what I've got...

For recipe:

conda-forge-linter commented 3 years ago

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

hadim commented 2 years ago

Closing in favour of #2.