kunlun.lua 2.9 KB
Newer Older
1
2
add_defines("ENABLE_KUNLUN_API")
local KUNLUN_HOME = os.getenv("KUNLUN_HOME")
zhangyue's avatar
zhangyue committed
3
4
5
local XRE_DIR = path.join(KUNLUN_HOME, "xre")
local XTDK_DIR = path.join(KUNLUN_HOME, "xtdk")
local XDNN_DIR = path.join(KUNLUN_HOME, "xhpc", "xdnn")
6
7

-- Add include dirs
zhangyue's avatar
zhangyue committed
8
9
10
11
12
13
add_includedirs(path.join(XRE_DIR, "include"), {public=true})
add_includedirs(path.join(XTDK_DIR, "include"), {public=true})
add_includedirs(path.join(XDNN_DIR, "include"), {public=true})

add_linkdirs(path.join(XRE_DIR, "so"))
add_linkdirs(path.join(XDNN_DIR, "so"))
14
15
16
add_links("xpurt")
add_links("xpuapi")

17
18
19
20
21
22
23
24
25
26
rule("xpu")
    set_extensions(".xpu")
    
    on_load(function (target)
        target:add("includedirs", path.join(os.projectdir(), "include"))
    end)

    on_build_file(function (target, sourcefile)

        local objectfile = target:objectfile(sourcefile)
zhangyue's avatar
zhangyue committed
27
28
        print("Compiling:", sourcefile, "->", objectfile)
        -- local basename = objectfile:gsub("%.o$", "")
29
30
31
        os.mkdir(path.directory(objectfile))
        local cc = path.join(XTDK_DIR, "bin/clang++")
        local includedirs = table.concat(target:get("includedirs"), " ")
32
33
34
35
36
        local arch_map = {
            ["x86_64"] = "x86_64-linux-gnu",
            ["arm64"] = "aarch64-linux-gnu"
        }

37
        local args = {
zhangyue's avatar
zhangyue committed
38
            -- "--sysroot=/",
39
            "--target=" .. arch_map[os.arch()],
40
            "-fPIC",
zhangyue's avatar
zhangyue committed
41
42
43
44
            -- "-pie",
            "--xpu-arch=xpu3",
            -- "--basename", basename,
            "-std=c++17",
45
46
            "-O2",
            "-fno-builtin",
zhangyue's avatar
zhangyue committed
47
            -- "-g",
48
            "-c", sourcefile,
zhangyue's avatar
zhangyue committed
49
50
            "-o", objectfile
            -- "-v"
51
52
53
54
55
56
57
        }
        
        for _, includedir in ipairs(target:get("includedirs")) do
            table.insert(args, "-I" .. includedir)
        end

        -- print(args)
zhangyue's avatar
zhangyue committed
58
59
60
        local ok, code = os.execv(cc, args)
        assert(ok == 0, "Compile failed: " .. sourcefile)

61
        table.insert(target:objectfiles(), objectfile)
zhangyue's avatar
zhangyue committed
62
63
        -- table.insert(target:objectfiles(), basename .. ".device.bin.o")
        -- print(target:objectfiles())
64
65
66
67
68
    end)
rule_end()

local src_dir = path.join(os.projectdir(), "src", "infiniop")

69
70
target("infiniop-kunlun")
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
71
    add_deps("infini-utils")
72
73
    on_install(function (target) end)

zhangyue's avatar
zhangyue committed
74
    add_cxflags("-lstdc++ -fPIC -Wno-error=unused-function")
75
76
77
78
    set_warnings("all", "error")

    set_languages("cxx17")
    add_files("$(projectdir)/src/infiniop/devices/kunlun/*.cc", "$(projectdir)/src/infiniop/ops/*/kunlun/*.cc")
79
80
81
82
83
    -- compile handwriting kernel
    local xpu_files = os.files(src_dir .. "/ops/*/kunlun/*.xpu")
    if #xpu_files > 0 then
        add_files(xpu_files, {rule = "xpu"})
    end
84
target_end()
zhangyue's avatar
zhangyue committed
85
86
87
88
89
90
91
92
93
94
95

target("infinirt-kunlun")
    set_kind("static")
    add_deps("infini-utils")
    set_languages("cxx17")
    on_install(function (target) end)
    -- Add include dirs
    add_files("../src/infinirt/kunlun/*.cc")
    add_cxflags("-lstdc++ -Wall -Werror -fPIC")

target_end()