Skip to content

Commit 536ea44

Browse files
Patch and relocate pointers (#58)
* Patch and relocate points * comment out erroneous `@show` * doc update and `filename` support in `compile` * Update src/StaticCompiler.jl Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * Update README.md Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * Update src/StaticCompiler.jl Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * Update src/StaticCompiler.jl Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * Update src/StaticCompiler.jl Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * Update src/StaticCompiler.jl Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * Update src/pointer_patching.jl Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * Apply suggestions from code review Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me> * reenable blas test * go back to serialization stdlib * note on gvs * try using JITTargetMachine for the dynamic linker * try running CI on windows * do some code reorganization * refine warning * allow windows failures * add options to strip the llvm / asm code * remove `@showln` * add `pointer_patching_diff` function to quickly see the effect of `relocation_table!` * improve pointer relocation * consolidate logic and reduce segfaults during compilation * remove unnecessary stuff * don't duplicate global values, switch from Dict to IdDict for reloc * avoid re-creation of global variables * more tests * add dummy test for error handing * test with ErrorTypes.jl * bump version Co-authored-by: Julian Samaroo <jpsamaroo@jpsamaroo.me>
1 parent 567168a commit 536ea44

10 files changed

Lines changed: 523 additions & 104 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
test:
77
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
88
runs-on: ${{ matrix.os }}
9+
continue-on-error: ${{ matrix.os == 'windows-latest' }}
910
strategy:
1011
fail-fast: false
1112
matrix:
@@ -15,6 +16,7 @@ jobs:
1516
os:
1617
- ubuntu-latest
1718
- macOS-latest
19+
- windows-latest
1820
arch:
1921
- x64
2022
steps:

Manifest.toml

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.7.1"
3+
julia_version = "1.7.2"
44
manifest_format = "2.0"
55

66
[[deps.ArgTools]]
@@ -23,10 +23,34 @@ git-tree-sha1 = "8cf7e67e264dedc5d321ec87e78525e958aea057"
2323
uuid = "0ee61d77-7f21-5576-8119-9fcc46b10100"
2424
version = "12.0.1+3"
2525

26+
[[deps.Compat]]
27+
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
28+
git-tree-sha1 = "44c37b4636bc54afac5c574d2d02b625349d6582"
29+
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
30+
version = "3.41.0"
31+
32+
[[deps.CompilerSupportLibraries_jll]]
33+
deps = ["Artifacts", "Libdl"]
34+
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
35+
36+
[[deps.DataStructures]]
37+
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
38+
git-tree-sha1 = "3daef5523dd2e769dad2365274f760ff5f282c7d"
39+
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
40+
version = "0.18.11"
41+
2642
[[deps.Dates]]
2743
deps = ["Printf"]
2844
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
2945

46+
[[deps.DelimitedFiles]]
47+
deps = ["Mmap"]
48+
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
49+
50+
[[deps.Distributed]]
51+
deps = ["Random", "Serialization", "Sockets"]
52+
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
53+
3054
[[deps.Downloads]]
3155
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
3256
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
@@ -36,6 +60,12 @@ git-tree-sha1 = "56559bbef6ca5ea0c0818fa5c90320398a6fbf8d"
3660
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
3761
version = "0.1.8"
3862

63+
[[deps.FileIO]]
64+
deps = ["Pkg", "Requires", "UUIDs"]
65+
git-tree-sha1 = "80ced645013a5dbdc52cf70329399c35ce007fae"
66+
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
67+
version = "1.13.0"
68+
3969
[[deps.GPUCompiler]]
4070
deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "TimerOutputs", "UUIDs"]
4171
git-tree-sha1 = "abd824e1f2ecd18d33811629c781441e94a24e81"
@@ -46,6 +76,12 @@ version = "0.13.11"
4676
deps = ["Markdown"]
4777
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
4878

79+
[[deps.JLD2]]
80+
deps = ["DataStructures", "FileIO", "MacroTools", "Mmap", "Pkg", "Printf", "Reexport", "TranscodingStreams", "UUIDs"]
81+
git-tree-sha1 = "b528d68220e2aba1d2d0c0461b6f7eda8c5c1e33"
82+
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
83+
version = "0.4.20"
84+
4985
[[deps.JLLWrappers]]
5086
deps = ["Preferences"]
5187
git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1"
@@ -83,9 +119,19 @@ uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
83119
[[deps.Libdl]]
84120
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
85121

122+
[[deps.LinearAlgebra]]
123+
deps = ["Libdl", "libblastrampoline_jll"]
124+
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
125+
86126
[[deps.Logging]]
87127
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
88128

129+
[[deps.MacroTools]]
130+
deps = ["Markdown", "Random"]
131+
git-tree-sha1 = "3d3e902b31198a27340d0bf00d6ac452866021cf"
132+
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
133+
version = "0.5.9"
134+
89135
[[deps.Markdown]]
90136
deps = ["Base64"]
91137
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
@@ -94,12 +140,24 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
94140
deps = ["Artifacts", "Libdl"]
95141
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
96142

143+
[[deps.Mmap]]
144+
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
145+
97146
[[deps.MozillaCACerts_jll]]
98147
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
99148

100149
[[deps.NetworkOptions]]
101150
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
102151

152+
[[deps.OpenBLAS_jll]]
153+
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
154+
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
155+
156+
[[deps.OrderedCollections]]
157+
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
158+
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
159+
version = "1.4.1"
160+
103161
[[deps.Pkg]]
104162
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
105163
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
@@ -122,15 +180,38 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
122180
deps = ["SHA", "Serialization"]
123181
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
124182

183+
[[deps.Reexport]]
184+
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
185+
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
186+
version = "1.2.2"
187+
188+
[[deps.Requires]]
189+
deps = ["UUIDs"]
190+
git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7"
191+
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
192+
version = "1.3.0"
193+
125194
[[deps.SHA]]
126195
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
127196

128197
[[deps.Serialization]]
129198
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
130199

200+
[[deps.SharedArrays]]
201+
deps = ["Distributed", "Mmap", "Random", "Serialization"]
202+
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
203+
131204
[[deps.Sockets]]
132205
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
133206

207+
[[deps.SparseArrays]]
208+
deps = ["LinearAlgebra", "Random"]
209+
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
210+
211+
[[deps.Statistics]]
212+
deps = ["LinearAlgebra", "SparseArrays"]
213+
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
214+
134215
[[deps.TOML]]
135216
deps = ["Dates"]
136217
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
@@ -139,12 +220,22 @@ uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
139220
deps = ["ArgTools", "SHA"]
140221
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
141222

223+
[[deps.Test]]
224+
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
225+
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
226+
142227
[[deps.TimerOutputs]]
143228
deps = ["ExprTools", "Printf"]
144229
git-tree-sha1 = "97e999be94a7147d0609d0b9fc9feca4bf24d76b"
145230
uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
146231
version = "0.5.15"
147232

233+
[[deps.TranscodingStreams]]
234+
deps = ["Random", "Test"]
235+
git-tree-sha1 = "216b95ea110b5972db65aa90f88d8d89dcb8851c"
236+
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
237+
version = "0.9.6"
238+
148239
[[deps.UUIDs]]
149240
deps = ["Random", "SHA"]
150241
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
@@ -160,6 +251,10 @@ uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
160251
deps = ["Artifacts", "Libdl"]
161252
uuid = "8f36deef-c2a5-5394-99ed-8e07531fb29a"
162253

254+
[[deps.libblastrampoline_jll]]
255+
deps = ["Artifacts", "Libdl", "OpenBLAS_jll"]
256+
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
257+
163258
[[deps.nghttp2_jll]]
164259
deps = ["Artifacts", "Libdl"]
165260
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name = "StaticCompiler"
22
uuid = "81625895-6c0f-48fc-b932-11a18313743c"
33
authors = ["Tom Short"]
4-
version = "0.3.0"
4+
version = "0.4.0"
55

66
[deps]
77
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"
88
GPUCompiler = "61eb1bfa-7361-4325-ad38-22787b887f55"
9+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
910
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
1011
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
1112
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ This package uses the [GPUCompiler package](https://github.com/JuliaGPU/GPUCompi
4747

4848
## Limitations
4949

50-
* No heap allocations (e.g. creating an array or a string) are allowed inside a statically compiled function body. If you try to run such a function, you will get a segfault.
51-
** It's sometimes possible you won't get a segfault if you define and run the function in the same session, but trying to call the compiled function in a new julia session will definitely segfault if you allocate memory.
52-
* Doesn't currently work on Windows
53-
* If you find any other limitations, let us know. There's probably lots.
50+
* GC-tracked allocations and global variables do work with `compile`, but the way they are implemented is brittle and can be dangerous. Allocate with care.
51+
* GC-tracked allocations and global varaibles do *not* work with `compile_executable` (yet).
52+
* Type unstable code is not yet supported.
53+
* Throwing errors is not currently supported. In the meantime, consider wrapping possible errors with [ErrorTypes.jl](https://github.com/jakobnissen/ErrorTypes.jl)
54+
* Doesn't currently work on Windows.
55+
* If you find any other limitations, let us know. There's probably lots.

0 commit comments

Comments
 (0)