__init__.py 1.34 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
import importlib
import os.path as osp
rusty1s's avatar
rusty1s committed
3

rusty1s's avatar
rusty1s committed
4
import torch
rusty1s's avatar
rusty1s committed
5

rusty1s's avatar
rusty1s committed
6
__version__ = '1.2.1'
rusty1s's avatar
rusty1s committed
7

rusty1s's avatar
rusty1s committed
8
9
suffix = 'cuda' if torch.cuda.is_available() else 'cpu'

rusty1s's avatar
rusty1s committed
10
11
for library in ['_version', '_basis', '_weighting']:
    torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
rusty1s's avatar
rusty1s committed
12
        f'{library}_{suffix}', [osp.dirname(__file__)]).origin)
rusty1s's avatar
rusty1s committed
13

rusty1s's avatar
rusty1s committed
14
if torch.cuda.is_available():  # pragma: no cover
rusty1s's avatar
rusty1s committed
15
    cuda_version = torch.ops.torch_spline_conv.cuda_version()
rusty1s's avatar
rusty1s committed
16
17
18
19
20
21
22
23
24

    if cuda_version == -1:
        major = minor = 0
    elif cuda_version < 10000:
        major, minor = int(str(cuda_version)[0]), int(str(cuda_version)[2])
    else:
        major, minor = int(str(cuda_version)[0:2]), int(str(cuda_version)[3])
    t_major, t_minor = [int(x) for x in torch.version.cuda.split('.')]

rusty1s's avatar
rusty1s committed
25
    if t_major != major:
rusty1s's avatar
rusty1s committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        raise RuntimeError(
            f'Detected that PyTorch and torch_spline_conv were compiled with '
            f'different CUDA versions. PyTorch has CUDA version '
            f'{t_major}.{t_minor} and torch_spline_conv has CUDA version '
            f'{major}.{minor}. Please reinstall the torch_spline_conv that '
            f'matches your PyTorch install.')

from .basis import spline_basis  # noqa
from .weighting import spline_weighting  # noqa
from .conv import spline_conv  # noqa

__all__ = [
    'spline_basis',
    'spline_weighting',
    'spline_conv',
    '__version__',
]