cuda.lua 2.98 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
5
6
7
8
9
10
11
12

local CUDA_ROOT = os.getenv("CUDA_ROOT") or os.getenv("CUDA_HOME") or os.getenv("CUDA_PATH")
local CUDNN_ROOT = os.getenv("CUDNN_ROOT") or os.getenv("CUDNN_HOME") or os.getenv("CUDNN_PATH")
if CUDA_ROOT ~= nil then
    add_includedirs(CUDA_ROOT .. "/include")
end
if CUDNN_ROOT ~= nil then
    add_includedirs(CUDNN_ROOT .. "/include")
end

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

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

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

43
44
    add_cuflags("-Xcompiler=-Wno-error=deprecated-declarations")

PanZezhongQY's avatar
PanZezhongQY committed
45
    set_languages("cxx17")
Jiacheng Huang's avatar
Jiacheng Huang committed
46
    add_files("../src/infiniop/devices/cuda/*.cu", "../src/infiniop/ops/*/cuda/*.cu", "../build/ninetoothed/*.c")
PanZezhongQY's avatar
PanZezhongQY committed
47
target_end()
48
49
50

target("infinirt-cuda")
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
51
    add_deps("infini-utils")
52
    on_install(function (target) end)
53

54
    set_policy("build.cuda.devlink", true)
55
56
    set_toolchains("cuda")
    add_links("cudart")
57
58
59

    if is_plat("windows") then
        add_cuflags("-Xcompiler=/utf-8", "--expt-relaxed-constexpr", "--allow-unsupported-compiler")
60
        add_cxxflags("/FS")
61
62
63
64
65
66
67
68
69
    else
        add_cuflags("-Xcompiler=-fPIC")
        add_culdflags("-Xcompiler=-fPIC")
        add_cxflags("-fPIC")
    end

    set_languages("cxx17")
    add_files("../src/infinirt/cuda/*.cu")
target_end()
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

target("infiniccl-cuda")
    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")
99

100
target_end()