cpu_adam_x86.py 1.59 KB
Newer Older
1
import platform
2

3
4
from ..cuda_extension import _CudaExtension
from ..utils import append_nvcc_threads
5
6


7
class CpuAdamX86Extension(_CudaExtension):
8
    def __init__(self):
9
10
        super().__init__(name="cpu_adam_x86")

11
12
    def is_available(self) -> bool:
        return platform.machine() == "x86_64" and super().is_available()
13

14
    def assert_compatible(self) -> None:
15
16
17
18
        arch = platform.machine()
        assert (
            arch == "x86_64"
        ), f"[extension] The {self.name} kernel requires the CPU architecture to be x86_64 but got {arch}"
19
        super().assert_compatible()
20
21
22
23

    # necessary 4 functions
    def sources_files(self):
        ret = [
24
            self.csrc_abs_path("cuda/cpu_adam.cpp"),
25
        ]
26
        return ret
27
28

    def include_dirs(self):
29
        return [self.csrc_abs_path("includes"), self.get_cuda_home_include()]
30
31

    def cxx_flags(self):
32
33
34
35
36
37
38
39
40
41
        extra_cxx_flags = [
            "-std=c++14",
            "-std=c++17",
            "-lcudart",
            "-lcublas",
            "-g",
            "-Wno-reorder",
            "-fopenmp",
            "-march=native",
        ]
42
        return ["-O3"] + self.version_dependent_macros + extra_cxx_flags
43
44
45

    def nvcc_flags(self):
        extra_cuda_flags = [
46
            "-std=c++14",
47
            "-std=c++17",
48
49
50
51
            "-U__CUDA_NO_HALF_OPERATORS__",
            "-U__CUDA_NO_HALF_CONVERSIONS__",
            "-U__CUDA_NO_HALF2_OPERATORS__",
            "-DTHRUST_IGNORE_CUB_VERSION_CHECK",
52
        ]
53
        ret = ["-O3", "--use_fast_math"] + self.version_dependent_macros + extra_cuda_flags
54
        return append_nvcc_threads(ret)