kunlun.lua 2.44 KB
Newer Older
1
2
add_defines("ENABLE_KUNLUN_API")
local KUNLUN_HOME = os.getenv("KUNLUN_HOME")
3
local XTDK_DIR = path.join(KUNLUN_HOME, "XTDK")
4
5
6
7
8
9
10

-- Add include dirs
add_includedirs(path.join(KUNLUN_HOME, "include"), {public=true})
add_linkdirs(path.join(KUNLUN_HOME, "lib64"))
add_links("xpurt")
add_links("xpuapi")

11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)
        local basename = objectfile:gsub("%.o$", "")
        os.mkdir(path.directory(objectfile))
        local cc = path.join(XTDK_DIR, "bin/clang++")
        local includedirs = table.concat(target:get("includedirs"), " ")
25
26
27
28
29
        local arch_map = {
            ["x86_64"] = "x86_64-linux-gnu",
            ["arm64"] = "aarch64-linux-gnu"
        }

30
31
32

        local args = {
            "--sysroot=/",
33
            "--target=" .. arch_map[os.arch()],
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
            "-fPIC",
            "-pie",
            "--xpu-arch=xpu2",
            "--basename", basename,
            "-std=c++11",
            "-O2",
            "-fno-builtin",
            "-g",
            "-c", sourcefile,
            "-v"
        }
        
        for _, includedir in ipairs(target:get("includedirs")) do
            table.insert(args, "-I" .. includedir)
        end

        -- print(args)
        os.execv(cc, args)
        table.insert(target:objectfiles(), objectfile)
        table.insert(target:objectfiles(), basename .. ".device.bin.o")
        print(target:objectfiles())
    end)
rule_end()

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

60
61
target("infiniop-kunlun")
    set_kind("static")
PanZezhong's avatar
PanZezhong committed
62
    add_deps("infini-utils")
63
64
    on_install(function (target) end)

65
66
67
68
69
    add_cxflags("-lstdc++ -fPIC")
    set_warnings("all", "error")

    set_languages("cxx17")
    add_files("$(projectdir)/src/infiniop/devices/kunlun/*.cc", "$(projectdir)/src/infiniop/ops/*/kunlun/*.cc")
70
71
72
73
74
    -- 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
75
target_end()
zhangyue's avatar
zhangyue committed
76
77
78
79
80
81
82
83
84
85
86

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