-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
158 lines (151 loc) · 4.68 KB
/
index.html
File metadata and controls
158 lines (151 loc) · 4.68 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Canvas Cache Visualizer</title>
<link rel="stylesheet" type="text/css" media="screen" href="canvas.css" />
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load("jquery", 1);</script>
<script type="text/javascript" src="store.js"></script>
<script type="text/javascript" src="cache.js"></script>
<script type="text/javascript" src="main.js"></script>
</head>
<body onload="main();">
<a id="gitsrc" style="float: right;" href="http://github.com/brk/canvas-cacheviz">source repository</a>
<span class="step-num">1: </span>
<span class="step-desc">Choose From Available Snippets:</span>
<h3>(click to load snippet)</h3>
<ul id="snippet-list">
<li><input type="button" class="title" value="// Sequential access by rows"></input>
<pre>
function (a, w, h) {
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
a.touch(i,j);
}
}
}
</pre></li>
<!-- ====================================================== -->
<li><input type="button" class="title" value="// Sequential access by columns"></input>
<pre>
function (a, w, h) {
for (j = 0; j < w; j++) {
for (i = 0; i < h; i++) {
a.touch(i,j);
}
}
}
</pre>
</pre></li>
<!-- ====================================================== -->
<li><input type="button" class="title" value="// Simple Matrix Transposition"></input>
<pre>
function (a, w, h) {
for (i = 0; i < h; i++) {
for (j = i+1; j < w; j++) {
a.touch(i,j);
a.touch(j,i);
}
}
}
</pre>
</pre></li>
<!-- ====================================================== -->
<li><input type="button" class="title" value="// Cache-Oblivious Matrix Transposition"></input>
<pre>
function (a, w, h) {
var transpose_base = function(a, x, y, w, h) {
for (i = x; i < x+w; i++) {
for (j = y; j < y+h; j++) {
if (j >= i) continue;
/* when iterating over a block that straddles
the diagonal, only swap the upper triangle */
a.touch(i,j);
a.touch(j,i);
}
}
};
var transpose_block = function(a, x, y, w, h) {
/* avoid blocks entirely below diagonal */
if ( (x+w) <= y ) return;
if (w <= 8 && h <= 8) {
transpose_base(a, x, y, w, h); return;
}
if (w >= h) {
var mid = Math.floor(w/2);
transpose_block(a, x , y, mid, h);
transpose_block(a, x+mid, y, w-mid, h);
} else {
var mid = Math.floor(h/2);
transpose_block(a, x, y, w, mid);
transpose_block(a, x, y+mid, w, h-mid);
}
};
transpose_block(a, 0, 0, w, h);
}
</pre></li>
</ul>
<p>In the code below, <kbd>a.touch(i,j)</kbd> indicates array access
<kbd>a[i][j]</kbd>.</p>
<textarea rows="14" cols="60" id="code-textarea" class="console">
// Sequential access by rows
function (a, w, h) {
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
a.touch(i,j);
}
}
}
</textarea>
<br>
<div id="control-buttons">
<span class="step-num">2: </span>
<span class="step-desc">Start Visualizing!</span>
<br>
<button id="run-button" onclick="window.animate = false; run();">Run</button>
<button id="animate-button" onclick="window.animate = true; run();">Animate</button>
<button id="draw-cache-button" onclick="window.animate = false; draw_cache_lines();">Draw Cache</button>
</div>
<br>
<span class="step-num">3: </span>
<span class="step-desc">See Results!</span>
<table>
<tr>
<th>Memory Touches</th>
<th>Cache Hits (green) / Misses (red)</th>
<th>TODO</th>
</tr>
<tr>
<td>
<canvas id="store-canvas"
width="256"
height="256"
></canvas>
</td>
<td>
<canvas id="cache-canvas"
width="256"
height="256"
></canvas>
</td>
<td>
<ul>
<li>jquery slider to control variable animation speeds</li>
<li>jQuery slider to scale views -- e.g. use 2 or 4 pixels instead of 1</li>
<li>On Chrome, at least, repeated runs can lead to de-synced animation... odd, but
mostly harmless</li>
</ul>
</td>
</tr>
<tr>
<td>Memory touches are colored by time:<br> black at the start, white at the end</td>
<td>Each "pixel" is a four-byte element.</td>
<td></td>
</tr>
</table>
<hr>
<div id="error" style="margin-bottom:20px;">
</div>
</body>
</html>