setup.py 4.4 KB
Newer Older
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Copyright 2021 AlQuraishi Laboratory
# Copyright 2021 DeepMind Technologies Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
15
16
17
18
import os
from setuptools import setup, Extension, find_packages
import subprocess

zhuwenwen's avatar
zhuwenwen committed
19
import torch
zhuww's avatar
zhuww committed
20
from torch.utils.cpp_extension import BuildExtension, CUDAExtension, ROCM_HOME
21

zhuww's avatar
zhuww committed
22
23
24
from typing import Optional, Union
import subprocess
from pathlib import Path
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
25

26
27
28
29
30
31
32
33

version_dependent_macros = [
    '-DVERSION_GE_1_1',
    '-DVERSION_GE_1_3',
    '-DVERSION_GE_1_5',
]

extra_cuda_flags = [
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
34
    '-std=c++14',
zhuww's avatar
zhuww committed
35
    #'-maxrregcount=50',
zhuwenwen's avatar
zhuwenwen committed
36
37
    '-U__CUDA_NO_HALF_OPERATORS__',
    '-U__CUDA_NO_HALF_CONVERSIONS__'
38
39
]

zhuwenwen's avatar
zhuwenwen committed
40
cc_flag = ['-DAMDGPU_TARGETS', 'gfx900;gfx906;gfx926']
41
42
43

extra_cuda_flags += cc_flag

Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
44

zhuwenwen's avatar
zhuwenwen committed
45
def get_sha(root: Union[str, Path]) -> str:
zhuww's avatar
zhuww committed
46
    try:
zhuwenwen's avatar
zhuwenwen committed
47
        return subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=root).decode('ascii').strip()
zhuww's avatar
zhuww committed
48
49
50
51
    except Exception:
        return 'Unknown'


zhuwenwen's avatar
zhuwenwen committed
52
53
54
55
56
57
58
59
60
61
62
def get_abi():
    try:
        command = "echo '#include <string>' | gcc -x c++ -E -dM - | fgrep _GLIBCXX_USE_CXX11_ABI" 
        result = subprocess.run(command, shell=True, capture_output=True, text=True) 
        output = result.stdout.strip() 
        abi = "abi" + output.split(" ")[-1]
        return abi
    except Exception:
        return 'abiUnknown'
    
    
zhuww's avatar
zhuww committed
63
def get_version_add(sha: Optional[str] = None) -> str:
zhuwenwen's avatar
zhuwenwen committed
64
    openfold_root = os.path.dirname(os.path.abspath(__file__))
zhuwenwen's avatar
zhuwenwen committed
65
    add_version_path = os.path.join(os.path.join(openfold_root, "openfold"), "version.py")
zhuww's avatar
zhuww committed
66
67
    if sha != 'Unknown':
        if sha is None:
zhuwenwen's avatar
zhuwenwen committed
68
            sha = get_sha(openfold_root)
zhuww's avatar
zhuww committed
69
70
        version = 'git' + sha[:7]

zhuwenwen's avatar
zhuwenwen committed
71
72
73
    # abi version
    version += "." + get_abi()

zhuwenwen's avatar
zhuwenwen committed
74
    # dtk version
zhuwenwen's avatar
zhuwenwen committed
75
76
77
78
79
80
81
82
83
84
    if os.getenv("ROCM_PATH"):
        rocm_path = os.getenv('ROCM_PATH', "")
        rocm_version_path = os.path.join(rocm_path, '.info', "rocm_version")
        with open(rocm_version_path, 'r',encoding='utf-8') as file:
            lines = file.readlines()
        rocm_version=lines[0][:-2].replace(".", "")
        version += ".dtk" + rocm_version

    # torch version
    version += ".torch" + torch.__version__[:4]
zhuww's avatar
zhuww committed
85
86

    with open(add_version_path, encoding="utf-8", mode="w") as file:
zhuwenwen's avatar
zhuwenwen committed
87
88
        file.write("__version__='1.0.1'\n")
        file.write("__dcu_version__='1.0.1+{}'\n".format(version))
zhuww's avatar
zhuww committed
89
90
91
92
93
    file.close()


def get_version():
    get_version_add()
zhuwenwen's avatar
zhuwenwen committed
94
    version_file = 'openfold/version.py'
zhuww's avatar
zhuww committed
95
96
    with open(version_file, encoding='utf-8') as f:
        exec(compile(f.read(), version_file, 'exec'))
zhuwenwen's avatar
zhuwenwen committed
97
    return locals()['__dcu_version__']
zhuww's avatar
zhuww committed
98

Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
99
100
setup(
    name='openfold',
zhuww's avatar
zhuww committed
101
    #version='1.0.1',
zhuwenwen's avatar
zhuwenwen committed
102
    version=get_version(),
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
103
    description='A PyTorch reimplementation of DeepMind\'s AlphaFold 2',
104
    author='Gustaf Ahdritz & DeepMind',
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
105
106
107
    author_email='gahdritz@gmail.com',
    license='Apache License, Version 2.0',
    url='https://github.com/aqlaboratory/openfold',
108
    packages=find_packages(exclude=["tests", "scripts"]),
zhuww's avatar
zhuww committed
109
    include_package_data=False,
110
111
112
113
114
115
116
117
118
119
120
121
    package_data={
        "openfold": ['utils/kernel/csrc/*'],
        "": ["resources/stereo_chemical_props.txt"]
    },
    ext_modules=[CUDAExtension(
        name="attn_core_inplace_cuda",
        sources=[
            "openfold/utils/kernel/csrc/softmax_cuda.cpp",
            "openfold/utils/kernel/csrc/softmax_cuda_kernel.cu",
        ],
        include_dirs=[
            os.path.join(
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
122
                os.path.dirname(os.path.abspath(__file__)),
123
124
125
126
127
                'openfold/utils/kernel/csrc/'
            )
        ],
        extra_compile_args={
            'cxx': ['-O3'] + version_dependent_macros,
zhuww's avatar
zhuww committed
128
            'hipcc': (
zhuwenwen's avatar
zhuwenwen committed
129
                ['-O3'] + version_dependent_macros + extra_cuda_flags
130
131
132
133
            ),
        }
    )],
    cmdclass={'build_ext': BuildExtension},
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
134
135
136
    classifiers=[
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: POSIX :: Linux',
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
137
        'Programming Language :: Python :: 3.7,'
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
138
139
140
        'Topic :: Scientific/Engineering :: Artificial Intelligence',
    ],
)
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
141
142
143