Skip to content

Commit 061752c

Browse files
authored
Merge pull request #2 from jpsamaroo/jps/gpucompiler
Use GPUCompiler
2 parents e194063 + d67e4b9 commit 061752c

File tree

14 files changed

+897
-346
lines changed

14 files changed

+897
-346
lines changed

Manifest.toml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
[[Base64]]
4+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
5+
6+
[[CEnum]]
7+
git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9"
8+
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
9+
version = "0.4.1"
10+
11+
[[Compat]]
12+
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
13+
git-tree-sha1 = "215f1c81cfd1c5416cd78740bff8ef59b24cd7c0"
14+
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
15+
version = "3.15.0"
16+
17+
[[DataStructures]]
18+
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
19+
git-tree-sha1 = "88a93640bb3345436284ff089b383c34427f4117"
20+
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
21+
version = "0.18.2"
22+
23+
[[Dates]]
24+
deps = ["Printf"]
25+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
26+
27+
[[DelimitedFiles]]
28+
deps = ["Mmap"]
29+
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
30+
31+
[[Distributed]]
32+
deps = ["Random", "Serialization", "Sockets"]
33+
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
34+
35+
[[GPUCompiler]]
36+
deps = ["DataStructures", "InteractiveUtils", "LLVM", "Libdl", "TimerOutputs", "UUIDs"]
37+
path = "/home/jpsamaroo/.julia/dev/GPUCompiler-bpf/"
38+
uuid = "61eb1bfa-7361-4325-ad38-22787b887f55"
39+
version = "0.7.1"
40+
41+
[[InteractiveUtils]]
42+
deps = ["Markdown"]
43+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
44+
45+
[[LLVM]]
46+
deps = ["CEnum", "Libdl", "Printf", "Unicode"]
47+
git-tree-sha1 = "70070a0131f17fcffc5fc004f5f73f037bd217c5"
48+
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
49+
version = "3.2.0"
50+
51+
[[LibGit2]]
52+
deps = ["Printf"]
53+
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
54+
55+
[[Libdl]]
56+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
57+
58+
[[LinearAlgebra]]
59+
deps = ["Libdl"]
60+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
61+
62+
[[Logging]]
63+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
64+
65+
[[Markdown]]
66+
deps = ["Base64"]
67+
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
68+
69+
[[Mmap]]
70+
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
71+
72+
[[OrderedCollections]]
73+
git-tree-sha1 = "293b70ac1780f9584c89268a6e2a560d938a7065"
74+
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
75+
version = "1.3.0"
76+
77+
[[Pkg]]
78+
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
79+
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
80+
81+
[[Printf]]
82+
deps = ["Unicode"]
83+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
84+
85+
[[REPL]]
86+
deps = ["InteractiveUtils", "Markdown", "Sockets"]
87+
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
88+
89+
[[Random]]
90+
deps = ["Serialization"]
91+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
92+
93+
[[SHA]]
94+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
95+
96+
[[Serialization]]
97+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
98+
99+
[[SharedArrays]]
100+
deps = ["Distributed", "Mmap", "Random", "Serialization"]
101+
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
102+
103+
[[Sockets]]
104+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
105+
106+
[[SparseArrays]]
107+
deps = ["LinearAlgebra", "Random"]
108+
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
109+
110+
[[Statistics]]
111+
deps = ["LinearAlgebra", "SparseArrays"]
112+
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
113+
114+
[[Test]]
115+
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
116+
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
117+
118+
[[TimerOutputs]]
119+
deps = ["Printf"]
120+
git-tree-sha1 = "f458ca23ff80e46a630922c555d838303e4b9603"
121+
uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
122+
version = "0.5.6"
123+
124+
[[UUIDs]]
125+
deps = ["Random", "SHA"]
126+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
127+
128+
[[Unicode]]
129+
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

Project.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ authors = ["Julian P Samaroo <[email protected]>"]
44
version = "0.1.0"
55

66
[deps]
7-
CUDAapi = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3"
7+
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
88
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
99
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
10+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
11+
12+
[compat]
13+
GPUCompiler = "0.7"
14+
LLVM = "3"
15+
julia = "1.3"
16+
17+
[extras]
18+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
19+
20+
[targets]
21+
test = ["Test"]

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# BPFnative.jl
22

33
## Instructions for use
4-
* Get a `] dev`'d copy of LLVM.jl, and modify the appropriate line in
5-
deps/build.jl as such: `config[:libllvm_targets] = [:NVPTX, :AMDGPU, :BPF]`
64
* Recompile Julia's LLVM with the appropriate line in deps/llvm.mk as such:
75
`LLVM_TARGETS := host;NVPTX;AMDGPU;BPF`
86
* `] build LLVM` to rebuild LLVM
@@ -12,8 +10,8 @@
1210
* If your kernel is an XDP filter, load it on the appropriate interface with:
1311
`ip link set dev myiface xdp obj mybpfkernel.o verbose`. `iproute2` will
1412
output some information on your kernel, which is useful for debugging when
15-
the kernel refuses to load your kernel (this is common). When you're done
16-
with that kernel, unload it with `ip link set dev myiface xdp off`.
13+
the Linux kernel refuses to load your kernel (this is common). When you're
14+
done with that kernel, unload it with `ip link set dev myiface xdp off`.
1715

1816
## Acknowledgments
1917
Thanks to @vchuravy for MCAnalyzer.jl, and @maleadt for CUDAnative.jl, both of

src/BPFnative.jl

Lines changed: 11 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,18 @@
11
module BPFnative
22

3-
using LLVM
4-
using LLVM.Interop
5-
using LLVM.API
6-
import CUDAapi: @debug, @trace
3+
using LLVM, LLVM.Interop
74
using InteractiveUtils
8-
9-
export bpfgen
10-
11-
const optlevel = Ref{Int}()
12-
13-
function __init__()
14-
# TODO: Do I need this?
15-
@assert LLVM.InitializeNativeTarget() == false
16-
InitializeBPFAsmPrinter()
17-
# TODO: Can we just do -Os due to eBPF limitations?
18-
optlevel[] = Base.JLOptions().opt_level
19-
end
20-
21-
include("irgen.jl")
22-
include("helpers.jl")
23-
24-
nameof(f::Core.Function) = String(typeof(f).name.mt.name)
25-
26-
function target_machine(lambda, mod::LLVM.Module)
27-
InitializeBPFTarget()
28-
InitializeBPFTargetInfo()
29-
triple = LLVM.triple(mod)
30-
target = LLVM.Target(triple)
31-
InitializeBPFTargetMC()
32-
# BPF doesn't have a cpu or features, right?
33-
LLVM.TargetMachine(lambda, target, triple, "", "")
34-
end
35-
36-
"""
37-
jloptimize!(tm, mod)
38-
39-
Runs the Julia optimizer pipeline.
40-
"""
41-
function jloptimize!(tm::LLVM.TargetMachine, mod::LLVM.Module)
42-
ModulePassManager() do pm
43-
add_library_info!(pm, triple(mod))
44-
add_transform_info!(pm, tm)
45-
ccall(:jl_add_optimization_passes, Nothing,
46-
(LLVM.API.LLVMPassManagerRef, Cint),
47-
LLVM.ref(pm), optlevel[])
48-
run!(pm, mod)
49-
end
50-
end
51-
5+
using Libdl
6+
using GPUCompiler
7+
8+
include("c_helpers.jl")
9+
include("libbpf.jl")
10+
include("maps.jl")
11+
include("compiler.jl")
12+
include("execution.jl")
5213
include("reflection.jl")
5314

54-
"""
55-
bpfgen(io, license::String, f, types; optimize! = jloptimize!)
56-
57-
Generates a BPF kernel with the specified license and writes it to `io`.
58-
"""
59-
function bpfgen(io::IO, license::String,
60-
@nospecialize(func::Core.Function), @nospecialize(types=Tuple);
61-
optimize!::Core.Function = jloptimize!)
62-
tt = Base.to_tuple_type(types)
63-
mod, llvmf = irgen(func, tt)
64-
obj = target_machine(mod) do tm
65-
optimize!(tm, mod)
66-
# FIXME: Add license section to mod
67-
LLVM.emit(tm, mod, LLVM.API.LLVMObjectFile)
68-
end
69-
write(io, obj)
70-
end
15+
# Some useful utilities
16+
include("xdp.jl")
7117

7218
end # module

0 commit comments

Comments
 (0)