nvidia.lua 3.36 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
target("infiniop-nvidia")
PanZezhongQY's avatar
PanZezhongQY committed
7
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
8
    add_deps("infini-utils")
PanZezhongQY's avatar
PanZezhongQY committed
9
10
    on_install(function (target) end)

11
    set_policy("build.cuda.devlink", true)
PanZezhongQY's avatar
PanZezhongQY committed
12
    set_toolchains("cuda")
13
    add_links("cudart", "cublas")
14
15
16
    if has_config("cudnn") then
        add_links("cudnn")
    end
PanZezhongQY's avatar
PanZezhongQY committed
17
18
    add_cugencodes("native")

19
20
21
22
    on_load(function (target)
        import("lib.detect.find_tool")
        local nvcc = find_tool("nvcc")
        if nvcc ~= nil then
pengcheng888's avatar
pengcheng888 committed
23
24
25
26
27
28
29
            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")
30
            target:add("links", "cuda")
31
32
33
        end
    end)

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

53
54
    add_cuflags("-Xcompiler=-Wno-error=deprecated-declarations")

PanZezhongQY's avatar
PanZezhongQY committed
55
    set_languages("cxx17")
56
57
58
59
60
    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
61
target_end()
62

63
target("infinirt-nvidia")
64
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
65
    add_deps("infini-utils")
66
    on_install(function (target) end)
67

68
    set_policy("build.cuda.devlink", true)
69
70
    set_toolchains("cuda")
    add_links("cudart")
71
72
73

    if is_plat("windows") then
        add_cuflags("-Xcompiler=/utf-8", "--expt-relaxed-constexpr", "--allow-unsupported-compiler")
74
        add_cxxflags("/FS")
75
76
77
78
79
80
81
82
83
    else
        add_cuflags("-Xcompiler=-fPIC")
        add_culdflags("-Xcompiler=-fPIC")
        add_cxflags("-fPIC")
    end

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

85
target("infiniccl-nvidia")
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
    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")
113

114
target_end()