File size: 2,195 Bytes
9c6594c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team

import os
from .async_io import AsyncIOBuilder


class GDSBuilder(AsyncIOBuilder):
    BUILD_VAR = "DS_BUILD_GDS"
    NAME = "gds"

    def __init__(self):
        super().__init__()

    def absolute_name(self):
        return f'deepspeed.ops.gds.{self.NAME}_op'

    def lib_sources(self):
        src_list = ['csrc/gds/py_lib/deepspeed_py_gds_handle.cpp', 'csrc/gds/py_lib/deepspeed_gds_op.cpp']
        return super().lib_sources() + src_list

    def sources(self):
        return self.lib_sources() + ['csrc/gds/py_lib/py_ds_gds.cpp']

    def cxx_args(self):
        return super().cxx_args() + ['-lcufile']

    def include_paths(self):
        import torch
        CUDA_INCLUDE = [os.path.join(torch.utils.cpp_extension.CUDA_HOME, "include")]
        return ['csrc/aio/py_lib', 'csrc/aio/common'] + CUDA_INCLUDE

    def extra_ldflags(self):
        return super().extra_ldflags() + ['-lcufile']

    def is_compatible(self, verbose=False):
        if self.is_rocm_pytorch():
            if verbose:
                self.warning(f'{self.NAME} is not compatible with ROCM')
            return False

        try:
            import torch.utils.cpp_extension
        except ImportError:
            if verbose:
                self.warning("Please install torch if trying to pre-compile GDS")
            return False

        CUDA_HOME = torch.utils.cpp_extension.CUDA_HOME
        if CUDA_HOME is None:
            if verbose:
                self.warning("Please install torch CUDA if trying to pre-compile GDS with CUDA")
            return False

        CUDA_LIB64 = os.path.join(CUDA_HOME, "lib64")
        gds_compatible = self.has_function(funcname="cuFileDriverOpen",
                                           libraries=("cufile", ),
                                           library_dirs=(
                                               CUDA_HOME,
                                               CUDA_LIB64,
                                           ),
                                           verbose=verbose)

        return gds_compatible and super().is_compatible(verbose)