13
13
}
14
14
"""
15
15
16
- terminal_init = """
17
- const terminal = new Terminal();
18
- const fitAddon = new FitAddon.FitAddon();
19
- terminal.loadAddon(fitAddon);
20
- window.terminal = terminal;
21
- console.log("Terminal initialized");
22
- """
23
-
24
- print_script = """
25
- window.customPrint = function(text) {
26
- console.log(text);
27
- if (window.terminal) {
28
- window.terminal.writeln(text);
29
- } else {
30
- console.warn("Terminal not initialized");
31
- }
32
- };
33
- createModule().then((Module) => {
34
- Module.print = window.customPrint;
35
- Module.printErr = window.customPrint;
36
- window.Module = Module;
37
- console.log("Initial module created");
38
- });
39
- """
40
-
41
16
bind_terminal = """
42
17
window.terminal.open(document.getElementById('output'));
43
18
fitAddon.fit();
60
35
}
61
36
""" .strip ()
62
37
63
- cpp_code = """
64
- static constexpr size_t N = 4;
65
- Tensor a = createTensor(ctx, {N}, kf32, makeData<N>().data());
66
- Tensor output = createTensor(ctx, {N}, kf32);
67
- Kernel op = createKernel(ctx, {kPuzzle1, N}, Bindings{a, output},
68
- /*nWorkgroups */ {1, 1, 1});
69
-
70
- std::promise<void> promise;
71
- std::future<void> future = promise.get_future();
72
- dispatchKernel(ctx, op, promise);
73
- std::array<float, R * C> outputArr;
74
- wait(ctx, future);
75
- toCPU(ctx, output, outputArr.data(), sizeof(outputArr));
76
- printf("%s", show<float, R, C>(outputArr, "output").c_str());
77
- """ .strip ()
78
-
79
-
80
38
def controls ():
81
39
# left and right buttons
82
40
return Div (
@@ -202,13 +160,21 @@ def CodeEditor(initial_content: str):
202
160
# cls="flex flex-col h-screen w-full", style="height: 100vh; overflow: hidden;"
203
161
style = "height: 33vh; overflow: hidden;" ,
204
162
),
205
- # Script(editor_script(initial_content)),
163
+ Script (editor_script (initial_content )),
206
164
)
207
165
208
166
209
167
# TODO(avh) : Global state handling of terminal binding, module creation, etc.
210
168
# could be improved
211
169
170
+ init_app = """
171
+ document.addEventListener('DOMContentLoaded', () => {
172
+ window.AppState = Object.create(State);
173
+ const AppState = window.AppState;
174
+ initializeApp();
175
+ });
176
+ """ .strip ()
177
+
212
178
HDRS = (
213
179
picolink ,
214
180
# ace code editor
@@ -217,15 +183,13 @@ def CodeEditor(initial_content: str):
217
183
Link (rel = "stylesheet" , href = "https://cdn.jsdelivr.net/npm/xterm/css/xterm.css" ),
218
184
Script (src = "https://cdn.jsdelivr.net/npm/xterm/lib/xterm.js" ),
219
185
Script (src = "https://cdn.jsdelivr.net/npm/xterm-addon-fit/lib/xterm-addon-fit.js" ),
220
- # Script(terminal_init),
221
186
Script (src = "/build/run.js" ), # gpu.cpp runtime
222
- # Script(print_script),
223
187
Style (global_style ),
224
188
Link (rel = "stylesheet" , href = "https://unpkg.com/tippy.js@6/dist/tippy.css" ),
225
189
Script (src = "https://unpkg.com/@popperjs/core@2" ),
226
190
Script (src = "https://unpkg.com/tippy.js@6" ),
227
191
Script (src = "/client.js" ),
228
- Script ("document.addEventListener('DOMContentLoaded', () => { initializeApp(); });" ),
192
+ Script (init_app ),
229
193
* Socials (
230
194
title = "gpu.cpp gpu puzzles" ,
231
195
description = "" ,
0 commit comments