utils.py 3.07 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
17
    )
    parser.add_argument(
Gustaf Ahdritz's avatar
Fixes  
Gustaf Ahdritz committed
18
        '--uniclust30_database_path', type=str, default=None,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    )
    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'
    )
    parser.add_argument(
        '--kalign_binary_path', type=str, default='/usr/bin/kalign'
    )
    parser.add_argument(
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
36
        '--max_template_date', type=str,
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
37
38
39
40
41
        default=date.today().strftime("%Y-%m-%d"),
    )
    parser.add_argument(
        '--obsolete_pdbs_path', type=str, default=None
    )
42
43
44
    parser.add_argument(
        '--release_dates_path', type=str, default=None
    )
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
45
46
47
48
49
50
51
52


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
53
    Adapted from script by Jan Schlüte t
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
54
55
56
57
    https://gist.github.com/f0k/63a664160d016a491b2cbea15913d549
    """
    CUDA_SUCCESS = 0

58
59
60
61
    libnames = [
        'libcuda.so', 
        'libcuda.dylib', 
        'cuda.dll',
62
        '/usr/local/cuda/compat/libcuda.so', # For Docker
63
    ]
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
64
65
66
67
68
69
70
71
    for libname in libnames:
        try:
            cuda = ctypes.CDLL(libname)
        except OSError:
            continue
        else:
            break
    else:
72
        return None, "Could not load any of: " + ' '.join(libnames)
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
73
74
75
76
77
78
79
80
81
82
83
84

    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:
        err = cuda.cuGetErrorString(result, ctypes.byref(error_str))
85
        print(err.value.decode())
Gustaf Ahdritz's avatar
Gustaf Ahdritz committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
        return None, err.value.decode()
    result = cuda.cuDeviceGetCount(ctypes.byref(nGpus))
    if result != CUDA_SUCCESS:
        err = cuda.cuGetErrorString(result, ctypes.byref(error_str))
        return None, err.value.decode()

    if(nGpus.value < 1):
        return None, err.value.decode()

    result = cuda.cuDeviceGet(ctypes.byref(device), 0)
    if result != CUDA_SUCCESS:
        err = cuda.cuGetErrorString(result, ctypes.byref(error_str))
        return None, err.value.decode()

    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