Skip to content

Commit c87c1d4

Browse files
committed
Update with comments
1 parent 68c06c5 commit c87c1d4

File tree

81 files changed

+274
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+274
-336
lines changed

icing/CakeMLtoFloVerLemsScript.sml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(*
2-
Lemmas for connection to FloVer
2+
Lemmas for connection to FloVer,
3+
the translation function is defined in CakeMLtoFloVerScript.sml, and the main
4+
connection theorem in CakeMLtoFloVerProofsScript.sml
35
*)
46
(* HOL4 *)
57
open machine_ieeeTheory realTheory realLib RealArith;

icing/CakeMLtoFloVerProofsScript.sml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(*
2-
Central theorem about connection to FloVer
2+
Main connection theorem relating FloVer's roundoff error bound
3+
to CakeML floating-point kernel executions
34
*)
45
(* HOL4 *)
56
open machine_ieeeTheory realTheory realLib RealArith;

icing/CakeMLtoFloVerScript.sml

+1-188
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(*
2-
Definition of translation to FloVer
2+
Translation from CakeML floating-point kernels to FloVer input
33
*)
44
(* CakeML *)
55
open compilerTheory;
@@ -264,190 +264,3 @@ Definition getError_def:
264264
End
265265

266266
val _ = export_theory ();
267-
268-
(**
269-
Definition Eval_oracle_def:
270-
Eval_oracle env exp P oracle =
271-
∀ refs.
272-
∃ res.
273-
End
274-
275-
276-
Theorem evaluate_const:
277-
Eval env (App FpFromWord [Lit (Word64 w)]) ((=) (FP_WordTree (Fp_const w)))
278-
Proof
279-
fs[ml_translatorTheory.Eval_def, ml_progTheory.eval_rel_def]
280-
\\ EVAL_TAC \\ fs[]
281-
QED
282-
283-
Theorem evaluate_var:
284-
nsLookup env.v (Short x) = SOME fp ⇒
285-
Eval env (Var (Short x)) ((=) fp)
286-
Proof
287-
fs[ml_translatorTheory.Eval_def, ml_progTheory.eval_rel_def]
288-
\\ EVAL_TAC \\ fs[]
289-
QED
290-
291-
Theorem evaluate_bop:
292-
Eval env e1 ((=) (FP_WordTree fp1)) ∧
293-
Eval env e2 ((=) (FP_WordTree fp2)) ⇒
294-
Eval env (App (FP_bop bop) [e1;e2]) ((=) (FP_WordTree (Fp_bop bop fpT1 fpT2)))
295-
Proof
296-
rpt strip_tac
297-
\\ simp [ml_translatorTheory.Eval_def, ml_progTheory.eval_rel_def]
298-
\\ simp[terminationTheory.evaluate_def, astTheorsemanticPrimitivesTheoryy.getOpClass_def]
299-
\\ EVAL_TAC \\ fs[]
300-
301-
302-
303-
exception valError of string;
304-
305-
fun translate t =
306-
case free_vars t of
307-
v::vs => raise valError "No free vars allowed"
308-
| [] =>
309-
**)
310-
311-
(** UNUSED:
312-
313-
Definition isFloVerExps_def:
314-
isFloVerExps [Var x] = T ∧
315-
isFloVerExps [App op exps] =
316-
(isFloVerExps exps ∧
317-
(case op of
318-
| FP_bop _ => LENGTH exps = 2
319-
| FP_uop FP_Neg => LENGTH exps = 1
320-
| FP_top _ => LENGTH exps = 3
321-
| _ => F)) ∧
322-
isFloVerExps [e] = F ∧
323-
isFloVerExps (e1::es) = (isFloVerExps [e1] ∧ isFloVerExps es)
324-
Termination
325-
wf_rel_tac `measure exp6_size`
326-
End
327-
328-
Definition isFloVerCmd_def:
329-
isFloVerCmd (Let so e1 e2) =
330-
(case so of
331-
| SOME x => isFloVerExps [e1] ∧ isFloVerCmd e2
332-
| NONE => F) ∧
333-
isFloVerCmd (App op exps) = isFloVerExps [App op exps] ∧
334-
isFloVerCmd (Var x) = T ∧
335-
isFloVerCmd _ = F
336-
End
337-
338-
Definition stripAssert_def:
339-
stripAssert (Let NONE P body) =
340-
(case P of
341-
| App op [fN; P] =>
342-
if (op = Opapp ∧ fN = Var (Long "Runtime" (Short "assert")))
343-
then SOME (P, body)
344-
else NONE
345-
| _ => NONE) ∧
346-
stripAssert _ = NONE
347-
End
348-
349-
Definition prepareKernel_def:
350-
prepareKernel exps =
351-
case exps of
352-
| NONE => NONE
353-
| SOME exps =>
354-
if (LENGTH exps ≠ 1)
355-
then NONE
356-
else
357-
case exps of
358-
| [(n1, n2, e)] =>
359-
let
360-
fN = stripNoOpt e;
361-
(vars, body) = stripFuns fN in
362-
do
363-
(P, body) <- stripAssert body;
364-
(* FIXME: should not need to strip noopt annotations here *)
365-
return (n2::vars, P, stripNoOpt body);
366-
od
367-
| _ => NONE
368-
End
369-
370-
(**
371-
Function getInterval
372-
Argument:
373-
A single CakeML AST describing an interval constraint
374-
The argument must have the shape (lo ≤ x) ∧ (x ≤ hi)
375-
Returns:
376-
The CakeML variable constraint by the interval, the lower bound,
377-
the upper bound
378-
**)
379-
Definition getInterval_def:
380-
getInterval (Log lop e1 e2) =
381-
(if (lop <> And) then NONE
382-
else
383-
case e1 of
384-
| App (FP_cmp FP_LessEqual) [c1; var1] =>
385-
(case e2 of
386-
| App (FP_cmp FP_LessEqual) [var2; c2] =>
387-
if (var1 ≠ var2) then NONE
388-
else
389-
(case c1 of
390-
| App FpFromWord [Lit (Word64 w1)] =>
391-
(case c2 of
392-
| App FpFromWord [Lit (Word64 w2)] =>
393-
(case var1 of
394-
| Var (Short x) =>
395-
if (fp64_isFinite w1 ∧ fp64_isFinite w2)
396-
then SOME (x, (fp64_to_real w1, fp64_to_real w2))
397-
else NONE
398-
| _ => NONE)
399-
| _ => NONE)
400-
| _ => NONE)
401-
| _ => NONE)
402-
| _ => NONE) ∧
403-
getInterval _ = NONE
404-
End
405-
406-
(**
407-
Function toFloVerPre
408-
Arguments:
409-
CakeML AST of a precondition
410-
a 1-1 map from CakeML to FloVer variables
411-
The AST of the precondition must be encoded exactly that the top-most
412-
conjunct joins either a single constraint (lo ≤ x) ∧ (x ≤ hi), or
413-
that it joins a single constraint with the remainder of the precondition
414-
((lo ≤ x) ∧ (x ≤ hi)) ∧ precondition_remainder
415-
Returns:
416-
A FloVer encoding of the precondition as a function from numbers to
417-
reals, and a list of variables bound in the precondition
418-
The list is used to make sure that a variable can only be bound once
419-
by the precondition in CakeML
420-
**)
421-
Definition toFloVerPre_def:
422-
toFloVerPre [] ids = NONE ∧
423-
toFloVerPre [Log And e1 e2] ids =
424-
(* base case: (lo ≤ x ∧ x <= hi) *)
425-
(case getInterval (Log And e1 e2) of
426-
| SOME (x, lo, hi) =>
427-
(case lookupCMLVar (Short x) ids of
428-
| NONE => NONE
429-
| SOME (y, n) =>
430-
SOME ((λ (z:num). if z = n then (lo,hi) else (0:real, 0:real)), [n]))
431-
(* compound case: ((lo <= x ∧ x ≤ hi) ∧ remainder *)
432-
| NONE =>
433-
(* get an interval for the left-hand side of the conjunct *)
434-
case getInterval e1 of
435-
| NONE => NONE
436-
| SOME (x, lo, hi) =>
437-
(* get a FloVer variable for the CakeML var from the mapping *)
438-
case lookupCMLVar (Short x) ids of
439-
| NONE => NONE
440-
| SOME (y, n) =>
441-
(* recursive translation *)
442-
case toFloVerPre [e2] ids of
443-
| NONE => NONE
444-
| SOME (P, bVars) =>
445-
(* check whether the variable is already bound *)
446-
case FIND (λ m. n = m) bVars of
447-
| SOME _ => NONE (* cannot rebind variable *)
448-
| NONE =>
449-
SOME ((λ (z:num). if z = n then (lo,hi) else P z), n :: bVars)) ∧
450-
toFloVerPre _ _ = NONE
451-
End
452-
453-
**)

icing/README.md

+62-28
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,82 @@
1-
Icing: CAV'19...
1+
Main implementation directory for PrincessCake(ML): Verified Compilation and
2+
Optimization of Floating-Point Programs
3+
===========================================================================
4+
5+
The development is known to compile with HOL4 commit:
6+
52ffdc8f01c5cf044427bf6f3a12e8300e91765a
7+
8+
Running the files in this directory requires a working version of
9+
[FloVer](https://gitlab.mpi-sws.org/AVA/FloVer).
10+
You need to download FloVer, compile its HOL4 development and store its
11+
directory as a shell variable:
12+
13+
```
14+
git clone https://gitlab.mpi-sws.org/AVA/FloVer FloVer
15+
export FLOVERDIR=<current directory>/FloVer/
16+
cd FloVer/hol4/ && $HOLDIR/bin/Holmake
17+
```
18+
19+
Afterwards the content in the directory can be build with `Holmake`.
20+
21+
Files contained in this directory:
222

323
[CakeMLtoFloVerLemsScript.sml](CakeMLtoFloVerLemsScript.sml):
4-
Lemmas for connection to FloVer
24+
Lemmas for connection to FloVer,
25+
the translation function is defined in CakeMLtoFloVerScript.sml, and the main
26+
connection theorem in CakeMLtoFloVerProofsScript.sml
527

628
[CakeMLtoFloVerProofsScript.sml](CakeMLtoFloVerProofsScript.sml):
7-
Central theorem about connection to FloVer
29+
Main connection theorem relating FloVer's roundoff error bound
30+
to CakeML floating-point kernel executions
831

932
[CakeMLtoFloVerScript.sml](CakeMLtoFloVerScript.sml):
10-
Definition of translation to FloVer
33+
Translation from CakeML floating-point kernels to FloVer input
1134

1235
[cfSupportScript.sml](cfSupportScript.sml):
13-
Support lemmas for CF reasoning
36+
Support lemmas for CF proofs in the end-to-end correctness theorems
1437

1538
[examples](examples):
16-
Case studies for the Marzipan optimizer
39+
FPBench benchmarks used in the evaluation of PrincessCake.
1740

1841
[floatToRealProofsScript.sml](floatToRealProofsScript.sml):
19-
Proofs about translation from float computations to real number computations
42+
Proofs about translation from floating-point computations to real-number
43+
computations. Needed to prove simulations in the end-to-end correctness
44+
theorems.
2045

2146
[floatToRealScript.sml](floatToRealScript.sml):
22-
Define a translation from float computations to real number computations
47+
Translation from CakeML floating-point computations to
48+
CakeML real-number computations.
2349

2450
[icingTacticsLib.sml](icingTacticsLib.sml):
25-
Tactic library specific to Icing
51+
Tactic library for PrincessCake development
2652

2753
[icing_optimisationProofsScript.sml](icing_optimisationProofsScript.sml):
28-
Correctness proofs for Icing optimisations supported by CakeML
29-
Each optimisation is defined in icing_optimisationsScript.
54+
Correctness proofs for peephole optimisations supported by PrincessCake
55+
Each optimisation is defined in icing_optimisationsScript.sml.
3056
This file proves the low-level correctness theorems for a single
31-
application of the optimisation, as well as that optimisations
32-
are real-valued identities.
57+
application of the optimisation.
58+
Real-valued identity proofs are in icing_realIdProofsScript.sml.
3359
The overall correctness proof for a particular run of the optimiser
3460
from source_to_sourceScript is build using the automation in
3561
icing_optimisationsLib and the general theorems from
3662
source_to_sourceProofsScript.
3763

3864
[icing_optimisationsLib.sml](icing_optimisationsLib.sml):
39-
Library defining function mk_opt_correct_thms that builds an optimiser
40-
correctness theorem for a list of rewriteFPexp_correct theorems
65+
Library defining HOL4 automation that builds an optimiser
66+
correctness theorem for an optimisation plan.
4167

4268
[icing_optimisationsScript.sml](icing_optimisationsScript.sml):
43-
Icing optimisations supported by CakeML
44-
This file defines all the optimisations that can be used by the Icing
45-
optimizer, defined in source_to_sourceScript.
46-
Correctness proofs for each optimisation are in the file
69+
Peephole optimisations used by PrincessCake
70+
This file defines all the optimisations that are can be used by the
71+
PrincessCake optimiser, defined in source_to_sourceScript.sml .
72+
The local correctness proofs for each optimisation are in the file
4773
icing_optimisationProofsScript.
4874

4975
[icing_realIdProofsScript.sml](icing_realIdProofsScript.sml):
5076
Real-number identity proofs for Icing optimisations supported by CakeML
5177
Each optimisation is defined in icing_optimisationsScript.
52-
This file proves the low-level correctness theorems for a single
53-
application of the optimisation, as well as that optimisations
54-
are real-valued identities.
55-
The overall correctness proof for a particular run of the optimiser
78+
This file proves that optimisations are real-valued identities.
79+
The overall real-number simluation proof for a particular run of the optimiser
5680
from source_to_sourceScript is build using the automation in
5781
icing_optimisationsLib and the general theorems from
5882
source_to_sourceProofsScript.
@@ -66,20 +90,30 @@ Implementation of the source to source floating-point rewriter
6690
This file defines the basic rewriter, used by the optimisation pass later.
6791
Correctness proofs are in icing_rewriterProofsScript.
6892

93+
[optPlannerProofsScript.sml](optPlannerProofsScript.sml):
94+
Correctness proof for optimization planner
95+
6996
[optPlannerScript.sml](optPlannerScript.sml):
70-
Unverified optimisation planners
97+
Unverified optimisation planner.
98+
Definitions in this file correspond to the function ‘planOpts’
99+
from Section 5 of the PrincessCake paper.
71100

72101
[pureExpsScript.sml](pureExpsScript.sml):
73102
predicate to check whether an expression is pure, i.e. does not use memory
74103
or the FFI
75104

76105
[source_to_sourceProofsScript.sml](source_to_sourceProofsScript.sml):
77-
Correctness proofs for floating-point optimizations
106+
Overall correctness proofs for optimisation functions
107+
defined in source_to_sourceScript.sml.
108+
To prove a particular run correct, they are combined
109+
using the automation in icing_optimisationsLib.sml with
110+
the local correctness theorems from icing_optimisationProofsScript.sml.
78111

79112
[source_to_sourceScript.sml](source_to_sourceScript.sml):
80-
Source to source optimiser, applying Icing optimizations
81-
This file defines the high-level Icing optimisers.
82-
Their general correctness theorems are proven in source_to_sourceProofsScript.
113+
This file defines the PrincessCake optimiser as a source to source pass.
114+
Function ‵stos_pass_with_plans‵ corresponds to ‵applyOpts‵
115+
from the paper.
116+
General correctness theorems are proven in source_to_sourceProofsScript.
83117
The optimiser definitions rely on the low-level functions from
84118
icing_rewriterScript implementing pattern matching and pattern instantiation.
85119

icing/cfSupportScript.sml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(**
2-
Support lemmas for CF reasoning
2+
Support lemmas for CF proofs in the end-to-end correctness theorems
33
**)
44
open basis_ffiTheory cfHeapsBaseTheory basis;
55
open cfTacticsLib ml_translatorLib;

icing/examples/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
Case studies for the Marzipan optimizer
1+
FPBench benchmarks used in the evaluation of PrincessCake.
2+
3+
WARNING: Running all of these at once takes a significant amount of time
4+
as an instance of FloVer will be spawned for all the 44 benchmarks that
5+
contain no `sqrt` operation.
26

37
[RungeKuttaProgCompScript.sml](RungeKuttaProgCompScript.sml):
48
Auto-generated by Daisy (https://gitlab.mpi-sws.org/AVA/daisy

icing/examples/RungeKuttaProgCompScript.sml

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Definition theAST_def:
161161
End
162162

163163
Definition theErrBound_def:
164-
theErrBound = inv (2 pow (10))
164+
theErrBound = inv (2 pow (5))
165165
End
166166

167167
val x = define_benchmark theAST_def theAST_pre_def false;

icing/examples/bspline3ProgCompScript.sml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Definition theAST_def:
3838
End
3939

4040
Definition theErrBound_def:
41-
theErrBound = inv (2 pow (10))
41+
theErrBound = inv (2 pow (5))
4242
End
4343

4444
val x = define_benchmark theAST_def theAST_pre_def true;

0 commit comments

Comments
 (0)