-
Notifications
You must be signed in to change notification settings - Fork 1
/
optimization.html
114 lines (106 loc) · 4.85 KB
/
optimization.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://github.com/stan-dev/stanc3/releases/download/nightly/stanc.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="prism/prism.css">
<link rel="stylesheet" href="https://prismjs.com/plugins/line-numbers/prism-line-numbers.css">
<link rel="stylesheet" href="prism/prism-live.css">
<link rel="stylesheet" href="style.css?v=2">
<script src="demo.js"></script>
<title>Stan-to-C++ optimizations</title>
</head>
<body>
<main>
<div class="page-links"><a href="index.html">Print C++</a></div>
<div class="page-links"><a href="pedantic.html">Pedantic check</a></div>
<div class="page-links"><a href="signatures.html">Supported signatures</a></div>
<div class="page-links selected-link"><a class="selected" href="optimization.html">Optimization
diff</a></div>
<div class="page-links"><a href="autoformat.html">Auto format</a></div>
<div class="page-links"><a href="canonicalizer.html">Canonicalizer</a></div>
<div style="clear:both;"></div>
<textarea id="model" class="prism-live line-numbers language-stan" spellcheck="false"></textarea>
<div class="buttons">
<div class="action_btn">
<button id="compile" class="action_btn submit" style="width:
180px">Compile w optimizations</button>
<button id="url" class="action_btn cancel">Generate URL</button>
<p id="saved"></p>
</div>
</div>
Choose optimization level:
<input type="radio" name="opt" id="O0" value="O0" /> O0
<input type="radio" name="opt" checked=checked id="O1" value="O1" /> 01
<input type="radio" name="opt" value="0experimental" id="0experimental" /> 0experimental
<div id="url-box" class="error-box"></div>
<div id="error" class="error-box"></div>
<section class="container short">
<div class="one short">Unoptimized code</div>
<div class="two short">Optimized code</div>
</section>
<section class="container">
<div class="one">
<pre><code id = "result2" class="language-cpp1"></code></pre>
</div>
<div class="two">
<pre><code id = "result1" class="language-cpp2"></code></pre>
</div>
</section>
</main>
</body>
<script>
function optimization() {
var opt = "O1"
if ($("#O0").prop("checked")) {
opt = "O0"
}
if ($("#0experimental").prop("checked")) {
opt = "0experimental"
}
var model_opt = stanc("test_model", $("#model").val(), [opt, "debug-optimized-mir-pretty"]);
if (model_opt.errors) {
$("#error").html(model_opt.errors[1].replace(/\n/g, "<br/>").replace(/\s/g, ' '));
$("#result1").html("");
} else {
$("#result1").html(Prism.highlight(model_opt.result, Prism.languages.stan, 'cpp'));
$("#error").html("");
}
var model_no_opt = stanc("test_model", $("#model").val(), ["debug-optimized-mir-pretty"]);
if (model_no_opt.errors) {
$("#error").html(model_no_opt.errors[1].replace(/\n/g, "<br/>").replace(/\s/g, ' '));
$("#result2").html("");
} else {
$("#result2").html(Prism.highlight(model_no_opt.result, Prism.languages.stan, 'cpp'));
$("#error").html("");
}
}
$(document).ready(function () {
let model_url = GetURLParameter("model")
let model = "ZnVuY3Rpb25zIHsKICByZWFsIGZvbyhkYXRhIGFycmF5WyxdIHJlYWwgeCwgYXJyYXlbXSBpbnQgeSwgdmVjdG9yIGJldGEsIGludCBOLCBpbnQgSykgewogICAgbWF0cml4W04sIEtdIG14ID0gdG9fbWF0cml4KHgpOwogICAgcmV0dXJuIGJlcm5vdWxsaV9sb2dpdF9scG1mKHkgfCBteCAqIGJldGEpOwogIH0KfQpwYXJhbWV0ZXJzIHsKICByZWFsIHk7Cn0KbW9kZWwgewogIHkgfiBzdGRfbm9ybWFsKCk7Cn0%3D"
if (model_url) {
model = model_url
}
decoded_model = atob(decodeURIComponent(model))
$("#model").val(decoded_model)
$("code", $("#model").prev()).html(decoded_model)
Prism.highlightAll()
$("#model").focus(function () {
$("#url-box").html("");
})
$("#compile").click(function () {
optimization();
});
optimization();
$("#url").click(function () {
let url = window.location.href.split('?')[0] + "?model=" + encodeURIComponent(btoa($("#model").val()))
$("#url-box").html(url);
});
});
</script>
<script src="https://blissfuljs.com/bliss.shy.min.js"></script>
<script src="prism/prism.js"></script>
<script src="https://prismjs.com/plugins/line-numbers/prism-line-numbers.js"></script>
<script src="prism/prism-live.js"></script>
</html>