nvidia.lua 3.93 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
5
local CUDNN_ROOT = os.getenv("CUDNN_ROOT") or os.getenv("CUDNN_HOME") or os.getenv("CUDNN_PATH")
if CUDNN_ROOT ~= nil then
    add_includedirs(CUDNN_ROOT .. "/include")
end

6
7
8
9
10
11
local CUTLASS_ROOT = os.getenv("CUTLASS_ROOT") or os.getenv("CUTLASS_HOME") or os.getenv("CUTLASS_PATH")

if CUTLASS_ROOT ~= nil then
    add_includedirs(CUTLASS_ROOT)
end

12
target("infiniop-nvidia")
PanZezhongQY's avatar
PanZezhongQY committed
13
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
14
    add_deps("infini-utils")
PanZezhongQY's avatar
PanZezhongQY committed
15
16
    on_install(function (target) end)

17
    set_policy("build.cuda.devlink", true)
PanZezhongQY's avatar
PanZezhongQY committed
18
    set_toolchains("cuda")
19
    add_links("cudart", "cublas")
20
21
22
    if has_config("cudnn") then
        add_links("cudnn")
    end
PanZezhongQY's avatar
PanZezhongQY committed
23

24
25
26
27
    on_load(function (target)
        import("lib.detect.find_tool")
        local nvcc = find_tool("nvcc")
        if nvcc ~= nil then
pengcheng888's avatar
pengcheng888 committed
28
29
30
31
32
33
34
            if is_plat("windows") then
                nvcc_path = os.iorun("where nvcc"):match("(.-)\r?\n")
            else
                nvcc_path = nvcc.program
            end

            target:add("linkdirs", path.directory(path.directory(nvcc_path)) .. "/lib64/stubs")
35
            target:add("links", "cuda")
36
37
38
        end
    end)

PanZezhongQY's avatar
PanZezhongQY committed
39
40
    if is_plat("windows") then
        add_cuflags("-Xcompiler=/utf-8", "--expt-relaxed-constexpr", "--allow-unsupported-compiler")
41
        add_cuflags("-Xcompiler=/W3", "-Xcompiler=/WX")
42
        add_cxxflags("/FS")
PanZezhongQY's avatar
PanZezhongQY committed
43
44
45
46
        if CUDNN_ROOT ~= nil then
            add_linkdirs(CUDNN_ROOT .. "\\lib\\x64")
        end
    else
47
        add_cuflags("-Xcompiler=-Wall", "-Xcompiler=-Werror")
PanZezhongQY's avatar
PanZezhongQY committed
48
        add_cuflags("-Xcompiler=-fPIC")
49
        add_cuflags("--extended-lambda")
PanZezhongQY's avatar
PanZezhongQY committed
50
51
        add_culdflags("-Xcompiler=-fPIC")
        add_cxxflags("-fPIC")
52
        add_cflags("-fPIC")
PanZezhong's avatar
PanZezhong committed
53
54
55
56
        add_cuflags("--expt-relaxed-constexpr")
        if CUDNN_ROOT ~= nil then
            add_linkdirs(CUDNN_ROOT .. "/lib")
        end
PanZezhongQY's avatar
PanZezhongQY committed
57
58
    end

59
    add_cuflags("-Xcompiler=-Wno-error=deprecated-declarations", "-Xcompiler=-Wno-error=unused-function")
60

61
62
63
64
65
66
67
68
69
70
71
    local arch_opt = get_config("cuda_arch")
    if arch_opt and type(arch_opt) == "string" then
        for _, arch in ipairs(arch_opt:split(",")) do
            arch = arch:trim()
            local compute = arch:gsub("sm_", "compute_")
            add_cuflags("-gencode=arch=" .. compute .. ",code=" .. arch)
        end
    else
        add_cugencodes("native")
    end

PanZezhongQY's avatar
PanZezhongQY committed
72
    set_languages("cxx17")
73
74
75
76
77
    add_files("../src/infiniop/devices/nvidia/*.cu", "../src/infiniop/ops/*/nvidia/*.cu")

    if has_config("ninetoothed") then
        add_files("../build/ninetoothed/*.c")
    end
PanZezhongQY's avatar
PanZezhongQY committed
78
target_end()
79

80
target("infinirt-nvidia")
81
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
82
    add_deps("infini-utils")
83
    on_install(function (target) end)
84

85
    set_policy("build.cuda.devlink", true)
86
87
    set_toolchains("cuda")
    add_links("cudart")
88
89
90

    if is_plat("windows") then
        add_cuflags("-Xcompiler=/utf-8", "--expt-relaxed-constexpr", "--allow-unsupported-compiler")
91
        add_cxxflags("/FS")
92
93
94
95
96
97
98
99
100
    else
        add_cuflags("-Xcompiler=-fPIC")
        add_culdflags("-Xcompiler=-fPIC")
        add_cxflags("-fPIC")
    end

    set_languages("cxx17")
    add_files("../src/infinirt/cuda/*.cu")
target_end()
101

102
target("infiniccl-nvidia")
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
    set_kind("static")
    add_deps("infinirt")
    on_install(function (target) end)
    if has_config("ccl") then
        set_policy("build.cuda.devlink", true)
        set_toolchains("cuda")
        add_links("cudart")

        if not is_plat("windows") then
            add_cuflags("-Xcompiler=-fPIC")
            add_culdflags("-Xcompiler=-fPIC")
            add_cxflags("-fPIC")

            local nccl_root = os.getenv("NCCL_ROOT")
            if nccl_root then
                add_includedirs(nccl_root .. "/include")
                add_links(nccl_root .. "/lib/libnccl.so")
            else
                add_links("nccl") -- Fall back to default nccl linking
            end

            add_files("../src/infiniccl/cuda/*.cu")
        else
            print("[Warning] NCCL is not supported on Windows")
        end
    end
    set_languages("cxx17")
130

131
target_end()