Skip to content

Commit 14e7ed4

Browse files
committed
refactoring web gpu puzzles evaluation code, change createTensor pointer inputs to const
1 parent 7f09c52 commit 14e7ed4

6 files changed

Lines changed: 979 additions & 188 deletions

File tree

experimental/fasthtml/gpu_puzzles/client.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ const PuzzleSpec = [
8585
},
8686
];
8787

88+
////////////////////////////////////////
89+
// Initialization
90+
////////////////////////////////////////
91+
8892
function initializeApp(initial_content) {
8993
initializeTerminal();
9094
initializeEditor(initial_content);
@@ -166,7 +170,7 @@ function setupEventListeners() {
166170
}
167171

168172
////////////////////////////////////////
169-
// Printing to terminal
173+
// Printing to output window
170174
////////////////////////////////////////
171175

172176
function customPrint(text) {
@@ -178,6 +182,10 @@ function customPrint(text) {
178182
}
179183
}
180184

185+
////////////////////////////////////////
186+
// Update
187+
////////////////////////////////////////
188+
181189
function updateDispatchParams() {
182190
wgSize = [
183191
document.getElementById("workgroup_x").value,
@@ -200,25 +208,22 @@ function updateDispatchParams() {
200208
console.log("New preamble:\n", AppState.preamble);
201209
}
202210

203-
////////////////////////////////////////
204-
// Code Editor
205-
////////////////////////////////////////
211+
async function updateEditor() {
206212

207-
function waitForDispatchReady() {
208-
return new Promise((resolve) => {
209-
function checkReady() {
210-
if (AppState.isDispatchReady) {
211-
resolve();
212-
} else {
213-
console.log("Waiting...");
214-
setTimeout(checkReady, 100); // Check every 100ms
213+
function waitForDispatchReady() {
214+
return new Promise((resolve) => {
215+
function checkReady() {
216+
if (AppState.isDispatchReady) {
217+
resolve();
218+
} else {
219+
console.log("Waiting...");
220+
setTimeout(checkReady, 100); // Check every 100ms
221+
}
215222
}
216-
}
217-
checkReady();
218-
});
219-
}
223+
checkReady();
224+
});
225+
}
220226

221-
async function updateEditor() {
222227
// Recover from errors TODO(avh): only do this if there's an error
223228
createModule().then((Module) => {
224229
console.log("updateEditor() - Module ready");
@@ -269,6 +274,10 @@ function update(event) {
269274
render();
270275
}
271276

277+
////////////////////////////////////////
278+
// Render
279+
////////////////////////////////////////
280+
272281
function render() {
273282
document.getElementById("preamble").innerHTML = AppState.preamble;
274283
// update DIV

0 commit comments

Comments
 (0)