Add WebGPU compute shader support for GPU-accelerated matrix operations#84
Merged
InauguralPhysicist merged 2 commits intomainfrom Dec 7, 2025
Conversation
Implements a WebGPU/WGSL backend for EigenScript enabling GPU acceleration in the browser: Language changes: - Add 'gpu:' block syntax to lexer (GPU token) - Add GPUBlock AST node to parser for grouping GPU operations WGSL Backend (wgsl_backend.py): - GPU-lite EigenValue struct (value + gradient only, 8 bytes) - Tiled matrix multiplication kernel with shared memory - Parallel reduction kernels for dot product and norm - Element-wise operation kernels (add, sub, mul, div, scale) - JavaScript/WebGPU runtime for browser integration GPU-lite EigenValue model: - Unobserved GPU computation stays lean (f32 value + gradient) - Observation triggers device→host sync + full geometric promotion - Fits EigenScript's observer-effect semantics Includes GPU playground demo and 18 passing tests.
Comment on lines
+9
to
+15
| from eigenscript.compiler.codegen.wgsl_backend import ( | ||
| WGSLCodeGenerator, | ||
| WGSLKernel, | ||
| WGSLBuffer, | ||
| WGSLType, | ||
| generate_webgpu_runtime, | ||
| ) |
| WGSLType, | ||
| generate_webgpu_runtime, | ||
| ) | ||
| from eigenscript.parser.ast_builder import GPUBlock, Assignment, Identifier, Relation |
| """ | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Dict, List, Optional, Set, Tuple |
Comment on lines
+22
to
+38
| from eigenscript.parser.ast_builder import ( | ||
| ASTNode, | ||
| Literal, | ||
| Identifier, | ||
| BinaryOp, | ||
| UnaryOp, | ||
| Assignment, | ||
| FunctionDef, | ||
| Return, | ||
| Conditional, | ||
| Loop, | ||
| Relation, | ||
| Interrogative, | ||
| ListLiteral, | ||
| Index, | ||
| GPUBlock, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a WebGPU/WGSL backend for EigenScript enabling GPU acceleration
in the browser:
Language changes:
WGSL Backend (wgsl_backend.py):
GPU-lite EigenValue model:
Includes GPU playground demo and 18 passing tests.