|
7 | 7 | TARGET = os.getenv("TARGET", "debug") |
8 | 8 |
|
9 | 9 | ace_editor = Script(src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js") |
10 | | -gpucpp_runtime = Script(src="/build/run.js") |
11 | | -gpucpp_wasm = Script(src="/build/run.wasm") |
| 10 | +gpucpp_runtime = Script(src="/build/run.js") |
| 11 | +gpucpp_wasm = Script(src="/build/run.wasm") |
12 | 12 | tippy_css = Link(rel="stylesheet", href="https://unpkg.com/tippy.js@6/dist/tippy.css") |
13 | 13 | tippy_js = Script(src="https://unpkg.com/@popperjs/core@2") |
14 | 14 | tippy_js2 = Script(src="https://unpkg.com/tippy.js@6") |
15 | | -xterm_css = Link(rel="stylesheet", href="https://cdn.jsdelivr.net/npm/xterm/css/xterm.css") |
| 15 | +xterm_css = Link( |
| 16 | + rel="stylesheet", href="https://cdn.jsdelivr.net/npm/xterm/css/xterm.css" |
| 17 | +) |
16 | 18 | xterm_js = Script(src="https://cdn.jsdelivr.net/npm/xterm/lib/xterm.js") |
17 | | -xterm_fit_js = Script(src="https://cdn.jsdelivr.net/npm/xterm-addon-fit/lib/xterm-addon-fit.js") |
| 19 | +xterm_fit_js = Script( |
| 20 | + src="https://cdn.jsdelivr.net/npm/xterm-addon-fit/lib/xterm-addon-fit.js" |
| 21 | +) |
18 | 22 |
|
19 | | -global_style = Style(""" |
| 23 | +global_style = Style( |
| 24 | + """ |
20 | 25 | #editor { |
21 | 26 | height: 50vh; |
22 | 27 | width: 50vw; |
23 | 28 | } |
24 | | -""") |
| 29 | +""" |
| 30 | +) |
25 | 31 |
|
26 | | -terminal_init = Script(""" |
27 | | - console.log("Terminal initialized"); |
| 32 | +terminal_init = \ |
| 33 | + """ |
28 | 34 | const terminal = new Terminal(); |
29 | 35 | const fitAddon = new FitAddon.FitAddon(); |
30 | 36 | terminal.loadAddon(fitAddon); |
31 | 37 | // terminal.open(document.getElementById('output')); |
32 | 38 | window.terminal = terminal; |
33 | | - fitAddon.fit(); |
| 39 | + // fitAddon.fit(); |
34 | 40 | console.log("Terminal initialized"); |
35 | | -"""); |
| 41 | +""" |
36 | 42 |
|
37 | | -print_script = Script(""" |
| 43 | +print_script = ( |
| 44 | + Script( |
| 45 | + """ |
38 | 46 | window.customPrint = function(text) { |
39 | 47 | console.log(text); |
40 | 48 | if (window.terminal) { |
|
48 | 56 | Module.printErr = window.customPrint; |
49 | 57 | window.Module = Module; |
50 | 58 | console.log("Module ready"); |
| 59 | + // window.Module.executeKernel(editor.getValue()); |
51 | 60 | }); |
52 | | -"""), |
53 | | - |
54 | | -bind_terminal = Script("window.terminal.open(document.getElementById('output'));") |
| 61 | +""" |
| 62 | + ), |
| 63 | +) |
55 | 64 |
|
56 | | -# TODO(avh): Global state handling of terminal binding, module creation, etc. |
| 65 | +bind_terminal = """ |
| 66 | + window.terminal.open(document.getElementById('output')); |
| 67 | + fitAddon.fit(); |
| 68 | +""" |
| 69 | + |
| 70 | +gelu_kernel = """// Start editing here to see the results. |
| 71 | +// Warning: You are in vim mode. |
| 72 | +@group(0) @binding(0) var<storage, read_write> input : array<f32>; |
| 73 | +@group(0) @binding(1) var<storage, read_write> output : array<f32>; |
| 74 | +@compute @workgroup_size(256) |
| 75 | +fn main( |
| 76 | + @builtin(global_invocation_id) GlobalInvocationID: vec3<u32>) { |
| 77 | + let i: u32 = GlobalInvocationID.x; |
| 78 | + if (i < arrayLength(&input)) { |
| 79 | + output[i] = input[i] + 1; |
| 80 | + } |
| 81 | + } |
| 82 | + """ |
| 83 | + |
| 84 | +# TODO(avh) : Global state handling of terminal binding, module creation, etc. |
57 | 85 | # could be improved |
58 | 86 |
|
59 | 87 | HDRS = ( |
60 | | - picolink, |
| 88 | + picolink, |
61 | 89 | ace_editor, |
62 | 90 | xterm_css, |
63 | 91 | xterm_js, |
64 | 92 | xterm_fit_js, |
65 | | - terminal_init, |
| 93 | + Script(terminal_init), |
66 | 94 | gpucpp_runtime, |
67 | 95 | print_script, |
68 | | - bind_terminal, |
69 | 96 | global_style, |
70 | 97 | tippy_css, |
71 | 98 | tippy_js, |
|
78 | 105 | image="", |
79 | 106 | url="https://gpucpp.answer.ai", |
80 | 107 | ), |
81 | | - ) |
| 108 | +) |
82 | 109 |
|
83 | 110 | if TARGET == "release": |
84 | 111 | app = FastHTML(hdrs=HDRS) |
|
87 | 114 |
|
88 | 115 | rt = app.route |
89 | 116 |
|
| 117 | + |
90 | 118 | @app.get("/build/run.js") |
91 | 119 | async def serve_wasm(fname: str, ext: str): |
92 | 120 | return FileResponse(f"build/run.js") |
93 | 121 |
|
| 122 | + |
94 | 123 | @app.get("/build/run.wasm") |
95 | 124 | async def serve_wasm(fname: str, ext: str): |
96 | 125 | return FileResponse(f"build/run.wasm") |
97 | 126 |
|
| 127 | + |
98 | 128 | def page(): |
99 | | - return Title("GPU Puzzles"), Body( |
100 | | - Div( |
| 129 | + return ( |
| 130 | + Title("GPU Puzzles"), |
| 131 | + Body( |
101 | 132 | Div( |
102 | | - CodeEditor(), |
103 | | - style="width: 66vw; height:100vh; background-color: #333; float: left;", |
104 | | - ), |
105 | | - Div( |
106 | | - "Output", |
107 | | - id="output", |
108 | | - style="width: 34vw; height:100vh; background-color: #444; float: right;", |
| 133 | + Div( |
| 134 | + CodeEditor(initial_content=gelu_kernel), |
| 135 | + style="width: 66vw; height:100vh; background-color: #333; float: left;", |
| 136 | + ), |
| 137 | + Div( |
| 138 | + "Output", |
| 139 | + id="output", |
| 140 | + style="width: 34vw; height:100vh; background-color: #444; float: right;", |
| 141 | + ), |
109 | 142 | ), |
| 143 | + Script(bind_terminal), |
| 144 | + style="height: 100vh; overflow: hidden;", |
110 | 145 | ), |
111 | | - bind_terminal, |
112 | | - style="height: 100vh; overflow: hidden;"), |
| 146 | + ) |
113 | 147 |
|
114 | 148 |
|
115 | 149 | @rt("/") |
|
0 commit comments