cuda.lua 2.69 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("cublas", "cudnn")
PanZezhongQY's avatar
PanZezhongQY committed
19
20
21
22
    add_cugencodes("native")

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

    set_languages("cxx17")
    add_files("../src/infiniop/devices/cuda/*.cu", "../src/infiniop/ops/*/cuda/*.cu")
target_end()
39
40
41

target("infinirt-cuda")
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
42
    add_deps("infini-utils")
43
    on_install(function (target) end)
44

45
    set_policy("build.cuda.devlink", true)
46
47
    set_toolchains("cuda")
    add_links("cudart")
48
49
50

    if is_plat("windows") then
        add_cuflags("-Xcompiler=/utf-8", "--expt-relaxed-constexpr", "--allow-unsupported-compiler")
51
        add_cxxflags("/FS")
52
53
54
55
56
57
58
59
60
    else
        add_cuflags("-Xcompiler=-fPIC")
        add_culdflags("-Xcompiler=-fPIC")
        add_cxflags("-fPIC")
    end

    set_languages("cxx17")
    add_files("../src/infinirt/cuda/*.cu")
target_end()
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

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")
    
target_end()