-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpresent.html
381 lines (265 loc) · 10.3 KB
/
present.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<html>
<head>
<title>Improvements in package precompilation</title>
<link rel="stylesheet" href="node_modules/reveal.js/dist/reveal.css">
<link rel="stylesheet" href="node_modules/reveal.js/dist/theme/white.css">
<link rel="stylesheet" href="mystyles.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h2>Improvements in package precompilation</h2>
<br>
<p style="text-align:center;font-size:40px;line-height:20px">Timothy E. Holy</p>
<p style="text-align:center;font-size:20px">Washington University in St. Louis</p>
<br>
<p style="text-align:center;font-size:40px;line-height:20px">Valentin Churavy</p>
<p style="text-align:center;font-size:20px">Massachusetts Institute of Technology</p>
</section>
<section data-markdown>
<script type="text/template">
### Julia runs fast

---
### You can write fast code quickly

- <!-- .element: class="fragment" data-fragment-index="1" --> Python `dask.array`: ~12,000 lines of code
- <!-- .element: class="fragment" data-fragment-index="2" --> Julia: 18 lines of code
---
### But Julia has a major usability problem: latency, aka Time To First eXecution (TTFX)
Julia:
```julia
using GLMakie
plot(rand(10))
```
Python: <!-- .element: class="fragment" data-fragment-index="1" -->
```python
import matplotlib.pyplot as plt
from numpy import random
plt.plot(random.rand(10))
plt.show()
```
<!-- .element: class="fragment" data-fragment-index="1" -->
---
### The two halves of TTFX
- package loading (a subject for a later day)
- code compilation (our current target)
---
### Strategies to reduce compilation time
- make the compiler faster
- compile as little as needed (LLVM compile-on-demand) <!-- .element: class="fragment" data-fragment-index="1" -->
- re-use the compiled code: better precompilation <!-- .element: class="fragment" data-fragment-index="2" -->
---
### Why precompilation is important

</script>
</section>
<section data-markdown
data-transition="slide-in fade-out">
<script>
### What gets saved from Julia's compilation pipeline?

</script>
</section>
<section data-markdown
data-transition="fade-in fade-out">
<script>
### What gets saved from Julia's compilation pipeline?

</script>
</section>
<section data-markdown
data-transition="fade-in fade-out">
<script>
### What gets saved from Julia's compilation pipeline?

</script>
</section>
<section data-markdown
data-transition="fade-in slide-out">
<script>
### What gets saved from Julia's compilation pipeline (Julia 1.0-1.7)?

</script>
</section>
<section data-markdown>
<script type="text/template">
### Challenges to more comprehensive precompilation: invalidation
Julia has to discard compiled code if it's no longer valid. How does this happen?
```julia
f(::Integer) = 1
g(x) = f(x)
g(1) # compiles g(::Int) and f(::Int)
```
But now define <!-- .element: class="fragment" data-fragment-index="1" -->
```julia
f(::Int) = 2
```
<!-- .element: class="fragment" data-fragment-index="1" -->
and the compiled code for <!-- .element: class="fragment" data-fragment-index="2" --> `g(::Int)` <!-- .element: class="fragment" data-fragment-index="2" --> has to be discarded (`f(::Int) from f(::Integer)` is no longer used).
---
### How common is invalidation?

<span style="font-weight:700;font-size:20px">
Fewer invalidations => more benefit from precompilation
</span>
---
### What gets saved from Julia's compilation pipeline (Julia 1.8)?

</script>
</section>
<section data-markdown
data-transition="slide-in fade-out">
<script>
### Some benchmarks

</script>
</section>
<section data-markdown
data-transition="fade-in fade-out">
<script>
### Some benchmarks

</script>
</section>
<section data-markdown
data-transition="fade-in slide-out">
<script>
### Some benchmarks

</script>
</section>
<section data-markdown>
<script type="text/template">
### Custom precompilation: `Startup.jl`
`~/.julia/config/startup.jl`:
```julia
using Startup
```
`~/.julia/dev/Startup/src/Startup.jl`: <!-- .element: class="fragment" data-fragment-index="1" -->
```julia
module Startup
import Pkg1, Pkg2, Pkg3
# force precompilation of `somefunction` and its dependents
Pkg1.somefunction(rand(10))
⋮
end
```
<!-- .element: class="fragment" data-fragment-index="1" -->
New package: <!-- .element: class="fragment" data-fragment-index="2" --> `SnoopPrecompile.jl` <!-- .element: class="fragment" data-fragment-index="2" -->
---
### Comparing Startup.jl vs PackageCompiler
| | Startup.jl | PackageCompiler |
|:---------:|:------------:|:-----------------:|
| Load time | **Poor** | **Good** |
| Inferred code saved | Yes | Yes |
| Native code saved | **No** | **Yes** |
| Works with Pkg updates | **Yes** | **No** |
<!-- .element.table: style="font-size:100%;" -->
---
### Looking ahead: saving native code in package precompilation
Julia has two independent systems for storing code in files:
| | `dump.c` | `staticdata.c` |
|:----- |:--------:|:--------------:|
| Lowered code | Yes | Yes |
| Type-inferred code | Yes | Yes |
| Native code | **No** | **Yes** |
| Usable for packages | **Yes** | **No** |
<!-- .element.table: style="font-size:100%;" -->
</script>
</section>
<section data-markdown
data-transition="slide-in fade-out">
<script>
### What's needed to support packages in `staticdata.c`?
Work has started: see PR#44527

</script>
</section>
<section data-markdown
data-transition="fade-in fade-out">
<script>
### What's needed to support packages in `staticdata.c`?
Work has started: see PR#44527

</script>
</section>
<section data-markdown
data-transition="fade-in fade-out">
<script>
### What's needed to support packages in `staticdata.c`?
Work has started: see PR#44527

</script>
</section>
<section data-markdown
data-transition="fade-in slide-out">
<script>
### What's needed to support packages in `staticdata.c`?
Work has started: see PR#44527

</script>
</section>
<section data-markdown>
<script type="text/template">
### Challenges
- De-duplication: `PkgA.f(::Integer)` gets specialized as `f(::Int)` in *both* `PkgB` and `PkgC`, these two (identical) specializations must be merged.
- Invalidation: must check validity of compiled code upon loading <!-- .element: class="fragment" data-fragment-index="1" -->
All this exists in <!-- .element: class="fragment" data-fragment-index="2" --> `dump.c`. <!-- .element: class="fragment" data-fragment-index="2" -->
---
### A common challenge
Compiling Julia to native code is "easy", as long as you...
- **Don't** use the Julia runtime (GC, exceptions, multi-threading, IO, ...)
- **Don't** use global data
- **Don't** have dynamic dispatch
---
### GPUCompiler.jl
GPUCompiler.jl provides infrastructure to exfiltrate "near static" code.
- CUDA.jl/AMDGPU.jl/... very limited runtime on device
- Enzyme.jl: Compiling code within the same instance of Julia through a parallel JIT
- StaticCompiler.jl: Originally limited runtime environment, now linking against libjulia.
---
### From `sysimage` to `pkgimage`
Each `.ji` becomes a `.so`:
1. Contains the metadata information for inserting methods into the method-table
2. Precompiled code cache
3. *New:* Object code cache
Object code cache must be *relocatable*.
---
### Relocating code
1. Global data is owned/rooted by the module in which it was declared
2. Will be serialized into the corresponding `pkgimage`.
3. Dependent compilation replaces references to these objects with relocation entries
4. Relocation will be performed by the `pkgimage` loader in Julia.
Implemented in PR#44527, **but** functions are unecessarily duplicated.
---
### Relocation is implementing save & load for the arrows

---
### Next steps
1. During codegen detect that call target has already been compiled, and replace with relocation/trampoline.
2. Automate the process and integrate into precompilation
3. Enable package loading to `pkgimage`s
4. (Speculative) Can we support `@ccallable`?
---
### A hopeful future
Julia 1.8: less invalidation, more comprehensive precompilation than any prior Julia version
On the horizon: comprehensive precompilation of native code <!-- .element: class="fragment" data-fragment-index="1" -->
Not yet started: <!-- .element: class="fragment" data-fragment-index="2" -->
- improvements in load times <!-- .element: class="fragment" data-fragment-index="2" -->
- tools for streamlining the ecosystem (e.g., de-duplication across packages) <!-- .element: class="fragment" data-fragment-index="3" -->
</script>
</section>
</div>
</div>
<script src="node_modules/reveal.js/dist/reveal.js"></script>
<script src="node_modules/reveal.js/plugin/markdown/markdown.js"></script>
<script>
Reveal.initialize({
plugins: [ RevealMarkdown ],
center: false,
});
</script>
</body>
</html>