nvidia.lua 3.18 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
23
    on_load(function (target)
        import("lib.detect.find_tool")
        local nvcc = find_tool("nvcc")
        if nvcc ~= nil then
            target:add("linkdirs", path.directory(path.directory(nvcc.program)) .. "/lib64/stubs")
24
            target:add("links", "cuda")
25
26
27
        end
    end)

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

47
48
    add_cuflags("-Xcompiler=-Wno-error=deprecated-declarations")

PanZezhongQY's avatar
PanZezhongQY committed
49
    set_languages("cxx17")
50
51
52
53
54
    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
55
target_end()
56

57
target("infinirt-nvidia")
58
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
59
    add_deps("infini-utils")
60
    on_install(function (target) end)
61

62
    set_policy("build.cuda.devlink", true)
63
64
    set_toolchains("cuda")
    add_links("cudart")
65
66
67

    if is_plat("windows") then
        add_cuflags("-Xcompiler=/utf-8", "--expt-relaxed-constexpr", "--allow-unsupported-compiler")
68
        add_cxxflags("/FS")
69
70
71
72
73
74
75
76
77
    else
        add_cuflags("-Xcompiler=-fPIC")
        add_culdflags("-Xcompiler=-fPIC")
        add_cxflags("-fPIC")
    end

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

79
target("infiniccl-nvidia")
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    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")
107

108
target_end()