moore.lua 3.17 KB
Newer Older
zhushuang's avatar
zhushuang committed
1
2
3
local MUSA_ROOT = os.getenv("MUSA_ROOT") or os.getenv("MUSA_HOME") or os.getenv("MUSA_PATH")
add_includedirs(MUSA_ROOT .. "/include")
add_linkdirs(MUSA_ROOT .. "/lib")
4
add_links("musa", "musart", "mudnn", "mublas")
5
6
7
8
9
10
11
12
13
14
15

rule("mu")
    set_extensions(".mu")
    on_load(function (target)
        target:add("includedirs", "include")
    end)

    on_build_file(function (target, sourcefile)
        local objectfile = target:objectfile(sourcefile)
        os.mkdir(path.directory(objectfile))

zhushuang's avatar
zhushuang committed
16
        local mcc = MUSA_ROOT .. "/bin/mcc"
17
        local includedirs = table.concat(target:get("includedirs"), " ")
zhushuang's avatar
zhushuang committed
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
        local args = {
            "-c", sourcefile,
            "-o", objectfile,
            "-I" .. MUSA_ROOT .. "/include",
            "-O3",
            "-fPIC",
            "-Wall",
            "-std=c++17",
            "-pthread"
        }
        local moore_gpu_arch = get_config("moore-gpu-arch")

        if moore_gpu_arch == "mp_31" then
            table.insert(args, 1, "--cuda-gpu-arch=mp_31")
        end

35
36
37
38
        for _, includedir in ipairs(target:get("includedirs")) do
            table.insert(args, "-I" .. includedir)
        end

zhushuang's avatar
zhushuang committed
39
40
41
42
43
44
45
46
47
48
        -- ============================
        -- Retrieve all preprocessor defines added to the current target
        local defines = target:get("defines")
        if defines then
            for _, define in ipairs(defines) do
                table.insert(args, "-D" .. define)
            end
        end
        -- ===================================

49
50
51
52
53
        os.execv(mcc, args)
        table.insert(target:objectfiles(), objectfile)
    end)
rule_end()

54
target("infiniop-moore")
55
    set_kind("static")
56
    on_install(function (target) end)
57
    set_languages("cxx17")
58
59
    set_warnings("all", "error")
    add_cxflags("-lstdc++", "-fPIC", "-Wno-comment")
60
    add_cxxflags("-lstdc++", "-fPIC", "-Wno-comment")
61
62
    add_files("../src/infiniop/devices/moore/*.cc")
    add_files("../src/infiniop/ops/*/moore/*.mu", {rule = "mu"})
63
64
65

    -- Add source files for Moore muBLAS/muDNN GEMM backends.
    add_files("../src/infiniop/ops/gemm/moore/*/*.mu", {rule = "mu"})
66
67
68

    -- Add source files for Moore per_channel_quant_int8 backends.
    add_files("../src/infiniop/ops/quant/per_channel_quant_int8/moore/*.mu", {rule = "mu"})
69
target_end()
qinyiqun's avatar
qinyiqun committed
70
71
72
73
74
75

target("infinirt-moore")
    set_kind("static")
    set_languages("cxx17")
    on_install(function (target) end)
    add_deps("infini-utils")
76
77
    set_warnings("all", "error")
    add_cxflags("-lstdc++", "-fPIC")
78
    add_cxxflags("-lstdc++", "-fPIC")
79
    add_files("../src/infinirt/moore/*.cc")
qinyiqun's avatar
qinyiqun committed
80
target_end()
spike-zhu's avatar
spike-zhu committed
81
82
83
84
85
86
87
88

target("infiniccl-moore")
    set_kind("static")
    add_deps("infinirt")
    on_install(function (target) end)
    set_warnings("all", "error")
    if not is_plat("windows") then
        add_cxflags("-fPIC")
89
        add_cxxflags("-fPIC")
spike-zhu's avatar
spike-zhu committed
90
91
92
93
    end
    if has_config("ccl") then
        add_links("libmccl.so")
        add_files("../src/infiniccl/moore/*.cc")
94
95
96
97
98
99
        
        -- Moore GPU arch with mp_31 support mcclBfloat16 in MCCL
        if get_config("moore-gpu-arch") == "mp_31" then
            add_defines("MARCH_TYPE=310")
            add_cxxflags("-Wno-unused-function")
        end
spike-zhu's avatar
spike-zhu committed
100
101
102
103
    end
    set_languages("cxx17")

target_end()