cpu_adagrad.py 1.39 KB
Newer Older
aiss's avatar
aiss committed
1
2
3
4
5
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team

aiss's avatar
aiss committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
from .builder import TorchCPUOpBuilder


class CPUAdagradBuilder(TorchCPUOpBuilder):
    BUILD_VAR = "DS_BUILD_CPU_ADAGRAD"
    NAME = "cpu_adagrad"

    def __init__(self):
        super().__init__(name=self.NAME)

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

    def sources(self):
aiss's avatar
aiss committed
21
22
23
        if self.build_for_cpu:
            return ['csrc/adagrad/cpu_adagrad.cpp']

aiss's avatar
aiss committed
24
25
        return ['csrc/adagrad/cpu_adagrad.cpp', 'csrc/common/custom_cuda_kernel.cu']

aiss's avatar
aiss committed
26
27
28
29
30
31
32
33
34
    def libraries_args(self):
        args = super().libraries_args()
        if self.build_for_cpu:
            return args

        if not self.is_rocm_pytorch():
            args += ['curand']
        return args

aiss's avatar
aiss committed
35
36
    def include_paths(self):
        import torch
aiss's avatar
aiss committed
37
38
39
        if self.build_for_cpu:
            CUDA_INCLUDE = []
        elif not self.is_rocm_pytorch():
aiss's avatar
aiss committed
40
41
42
            CUDA_INCLUDE = [os.path.join(torch.utils.cpp_extension.CUDA_HOME, "include")]
        else:
            CUDA_INCLUDE = [
aiss's avatar
aiss committed
43
44
45
                os.path.join(torch.utils.cpp_extension.ROCM_HOME, "include"),
                os.path.join(torch.utils.cpp_extension.ROCM_HOME, "include", "rocrand"),
                os.path.join(torch.utils.cpp_extension.ROCM_HOME, "include", "hiprand"),
aiss's avatar
aiss committed
46
47
            ]
        return ['csrc/includes'] + CUDA_INCLUDE