A hardware accelerated linear algebra library for JavaScript.
Warning
Claw.js is currently in very early development. It's not going to solve any of your problems yet, but I'm working on it regularly.
Note This README is dedicated to the core C library (libclaw). See the claw-js npm package to learn about the JavaScript interface.
There are many libraries for Python for numerical computation, especially for linear algebra e.g. Numpy, PyTorch. Not many options are available for Node.js and to be fair, JavaScript is not the most suitable programming language for the job. But like many people from the JS community, I told myself, why not?
Claw.js uses OpenCL. I know that it's not the latest and greatest API for GPUs. The reason I wanted to first develop with that is portability. I don't want Claw.js to be dependent on a specific hardware vendor, you should be able to use it with any GPU you have!
However, support for CUDA will come in the near future.
Note Items with higher importance are usually appears higher in the list, so it's essentially a priority queue.
- First implementations of core library (datatypes, interfaces).
- Implement primitive matrix operations using OpenCL.
- Create bindings for Node.js (instead of using FFI).
- Support for CUDA.
- SIMD optimizations.
- Bindings for other runtimes e.g. Deno.
Note This README is dedicated to the core C library (libclaw). If you would like to use it with JavaScript, see the README at claw-js in npm.
- Clone this repo:
git clone https://github.com/tussoftwaredesign/claw-js.git
- Navigate to the project root:
cd claw-js
- Make a build directory:
mkdir build
- Generate the build file:
cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=Release
- Compile:
cmake --build build -j10
- The compiled
libclaw.so
(libclaw.dylib
on Mac) shared object (dynamic link library) file will be insidebuild
Note This README is dedicated to the core C library (libclaw). If you would like to see the documentation for JavaScript, see the README at claw-js in npm.
#include <stdio.h>
#include <claw.h>
int main(int argc, char **argv)
{
// initialize the library
claw_init();
// define three matrices a, b, and c.
struct claw_mat a;
struct claw_mat b;
struct claw_mat c;
// initialize a and b with random values between 0 and 1 and give the shape 1024x1024.
claw_create_matrix_rand_unit(&a, 1024, 1024, CLAW_FLT32);
claw_create_matrix_rand_unit(&b, 1024, 1024, CLAW_FLT32);
// print a and b
claw_print_matrix(stdout, &a);
claw_print_matrix(stdout, &b);
// c = a * b
claw_matmul(&a, &b, &c);
// print c
claw_print_matrix(stdout, &c);
// cleanup
claw_free(a);
claw_free(b);
claw_free(c);
}
Please contact @yvesyil before making any changes.