"examples/llm/vscode:/vscode.git/clone" did not exist on "5d89a0c858b65599922a89967d415ff9010a76f4"
utils.py 3.53 KB
Newer Older
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
1
import argparse
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
2
import ctypes
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
3
from datetime import date
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
4
import sys
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
5
6
7
8


def add_data_args(parser: argparse.ArgumentParser):
    parser.add_argument(
Gustaf Ahdritz's avatar
Fixes  
Gustaf Ahdritz committed
9
        '--uniref90_database_path', type=str, default=None,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
10
11
    )
    parser.add_argument(
Gustaf Ahdritz's avatar
Fixes  
Gustaf Ahdritz committed
12
        '--mgnify_database_path', type=str, default=None,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
13
14
    )
    parser.add_argument(
Gustaf Ahdritz's avatar
Fixes  
Gustaf Ahdritz committed
15
        '--pdb70_database_path', type=str, default=None,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
16
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
17
18
19
    parser.add_argument(
        '--pdb_seqres_database_path', type=str, default=None,
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
20
    parser.add_argument(
Gustaf Ahdritz's avatar
Fixes  
Gustaf Ahdritz committed
21
        '--uniclust30_database_path', type=str, default=None,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
22
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
23
24
25
    parser.add_argument(
        '--uniprot_database_path', type=str, default=None,
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
26
27
28
29
30
31
32
33
34
35
36
37
    parser.add_argument(
        '--bfd_database_path', type=str, default=None,
    )
    parser.add_argument(
        '--jackhmmer_binary_path', type=str, default='/usr/bin/jackhmmer'
    )
    parser.add_argument(
        '--hhblits_binary_path', type=str, default='/usr/bin/hhblits'
    )
    parser.add_argument(
        '--hhsearch_binary_path', type=str, default='/usr/bin/hhsearch'
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
38
39
40
41
42
43
    parser.add_argument(
        '--hmmsearch_binary_path', type=str, default='/usr/bin/hmmsearch'
    )
    parser.add_argument(
        '--hmmbuild_binary_path', type=str, default='/usr/bin/hmmbuild'
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
44
45
46
47
    parser.add_argument(
        '--kalign_binary_path', type=str, default='/usr/bin/kalign'
    )
    parser.add_argument(
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
48
        '--max_template_date', type=str,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
49
50
51
52
53
        default=date.today().strftime("%Y-%m-%d"),
    )
    parser.add_argument(
        '--obsolete_pdbs_path', type=str, default=None
    )
54
55
56
    parser.add_argument(
        '--release_dates_path', type=str, default=None
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
57
58
59
60
61
62
63
64


def get_nvidia_cc():
    """
    Returns a tuple containing the Compute Capability of the first GPU
    installed in the system (formatted as a tuple of strings) and an error
    message. When the former is provided, the latter is None, and vice versa.

Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
65
    Adapted from script by Jan Schlüte t
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
66
67
68
69
    https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549
    """
    CUDA_SUCCESS = 0

70
71
72
73
    libnames = [
        'libcuda.so', 
        'libcuda.dylib', 
        'cuda.dll',
74
        '/usr/local/cuda/compat/libcuda.so', # For Docker
75
    ]
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
76
77
78
79
80
81
82
83
    for libname in libnames:
        try:
            cuda = ctypes.CDLL(libname)
        except OSError:
            continue
        else:
            break
    else:
84
        return None, "Could not load any of: " + ' '.join(libnames)
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
85
86
87
88
89
90
91
92
93
94
95

    nGpus = ctypes.c_int()
    cc_major = ctypes.c_int()
    cc_minor = ctypes.c_int()

    result = ctypes.c_int()
    device = ctypes.c_int()
    error_str = ctypes.c_char_p()

    result = cuda.cuInit(0)
    if result != CUDA_SUCCESS:
96
        cuda.cuGetErrorString(result, ctypes.byref(error_str))
97
98
99
100
        if error_str.value:
            return None, error_str.value.decode()
        else:
            return None, "Unknown error: cuInit returned %d" % result
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
101
102
    result = cuda.cuDeviceGetCount(ctypes.byref(nGpus))
    if result != CUDA_SUCCESS:
103
104
        cuda.cuGetErrorString(result, ctypes.byref(error_str))
        return None, error_str.value.decode()
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
105

106
    if nGpus.value < 1:
107
        return None, "No GPUs detected"
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
108
109
110

    result = cuda.cuDeviceGet(ctypes.byref(device), 0)
    if result != CUDA_SUCCESS:
111
112
        cuda.cuGetErrorString(result, ctypes.byref(error_str))
        return None, error_str.value.decode()
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
113
114
115
116
117
118
119
120

    if cuda.cuDeviceComputeCapability(ctypes.byref(cc_major), ctypes.byref(cc_minor), device) != CUDA_SUCCESS:
        return None, "Compute Capability not found"

    major = cc_major.value
    minor = cc_minor.value

    return (major, minor), None