warp-drive-express
v1.0.0
Published
A simple yet powerful Node.js and Express.js middleware to offload CPU-intensive tasks to the GPU, boosting performance for parallel computations. Ideal for machine learning, data analysis, and scientific computing applications.
Maintainers
Readme
warp-drive-express
A simple yet powerful Node.js and Express.js middleware to offload CPU-intensive tasks to the GPU, boosting performance for parallel computations. Ideal for machine learning, data analysis, and scientific computing applications.
This middleware acts as a drop-in solution that prefers the GPU over the CPU for heavy computations, with a graceful fallback to the CPU when a GPU context is not available. It uses the powerful gpu.js library to perform GPGPU (General-Purpose computing on Graphics Processing Units).
Why use warp-drive-express?
- Performance Boost: Drastically speed up parallelizable tasks by leveraging the massive parallel processing power of modern GPUs.
- Easy Integration: A simple-to-use Express.js middleware that can be added to any existing application.
- Graceful Fallback: Automatically falls back to CPU execution if a GPU is not available, ensuring your application runs anywhere.
- Extensible: Register your own custom GPU and CPU kernels to tailor the middleware to your specific needs.
Quickstart Usage
Install the package:
npm install warp-drive-expressAdd the middleware to your Express.js application:
const express = require('express'); const { createWarpDriveExpress } = require('warp-drive-express'); const app = express(); // Add the middleware app.use(createWarpDriveExpress()); // Your routes can now access the GPU kernels via req.warpDrive app.get('/my-computation', (req, res) => { const { matmul } = req.warpDrive.kernels; const result = matmul([1, 2], [3, 4]); // This will run on the GPU if available res.json(result); }); app.listen(3000, () => { console.log('Server running on port 3000'); });
Quick Example Usage
Here's an example of a route that calculates the Mandelbrot set, a computationally intensive task, using the warp-drive-express middleware.
app.get('/mandelbrot', (req, res) => {
const { mandelbrot } = req.warpDrive.kernels;
const { w = 200, h = 200, iter = 100 } = req.query;
// The 'auto' mode will try to use the GPU first, and fallback to CPU
const result = mandelbrot(parseInt(w), parseInt(h), parseInt(iter), 'auto');
res.send(result); // The result will be an image buffer
});Demo Server
For a more comprehensive set of examples and benchmarks, please see the demo server available on our GitHub repository. The demo server includes examples for:
- Mandelbrot set generation
- Matrix multiplication
- An A/B test to compare CPU vs. GPU performance
SEO Keywords
Node.js GPU acceleration, Express.js GPU middleware, gpu.js express example, force GPU usage in Node.js, offload CPU to GPU Node.js, parallel computing Node.js, high performance computing Node.js, speed up Node.js server with GPU.
