# node-gpgpu

> Node.js library for gpu acceleration using pure javascript

Latest version **0.0.8** (published 2023-03-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-gpgpu
pnpm add node-gpgpu
yarn add node-gpgpu
bun add node-gpgpu
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2023-03-04 |
| First published | 2023-03-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 126.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | JaroslawPokropinski |
| Maintainers | jaroslawpokropinski |

## Links

- npm: https://www.npmjs.com/package/node-gpgpu
- Repository: https://github.com/JaroslawPokropinski/node-gpgpu
- Homepage: https://github.com/JaroslawPokropinski/node-gpgpu#readme
- Issues: https://github.com/JaroslawPokropinski/node-gpgpu/issues
- npm.io page: https://npm.io/package/node-gpgpu

## Dependencies (3)

- [recast](https://npm.io/package/recast.md) ^0.20.5
- [esprima](https://npm.io/package/esprima.md) ^4.0.1
- [prebuild-install](https://npm.io/package/prebuild-install.md) ^7.0.1

## Recent versions

- 0.0.8 (latest) — 2023-03-04
- 0.0.7 — 2023-03-04

## README

# What is node-gpgpu

node-gpgpu is Node.js library for gpu accelerated programming. It allows to write accelerated code using subset of javascript and use it as standard javascript functions.

# Dependencies

To install and use node-gpgpu you will need cmake, opencl library and opencl runtime installed.

# Installation

`npm i node-gpgpu`

# Build

To build node-gpgpu one has to have opencl installed; after that call `npm i` and `npm run test` to verify build.

# Examples

One of examples is numerical ingetration on the gpu. More examples can be found in tests such as test/classes.spec.ts.

```javascript
import { Gpgpu, KernelContext, Types, kernelEntry, kernelFunction } from 'gpgpu';
async function main() {
  const n = 2000;
  const iter = 216;
  const gpgpu = new Gpgpu();

  class PiIntegralKernel extends KernelContext {
    @kernelFunction(Types.number, [Types.number])
    f(x: number) {
      return 2 * this.sqrt(1 - x * x);
    }

    @kernelEntry([
      { type: 'Float32Array', readWrite: 'write' },
      { type: 'Object', readWrite: 'read', shapeObj: { n: Types.number, iter: Types.number } },
    ])
    main(c: Float32Array, opt: { n: number, iter: number }) {
      const id = this.get_global_id(0);

      c[id] = 0.0;
      for (let i = id * opt.iter; i < (id + 1) * opt.iter; i += 1) {
        const dx = 2 / (opt.n * opt.iter);
        const x1 = dx * i - 1;
        const x2 = dx * (i + 1) - 1;

        c[id] += (this.f(x2) + this.f(x1)) * 0.5 * dx;
      }
    }
  }

  const k = gpgpu.createKernel2(PiIntegralKernel).setSize([2000], [10]);
  const c = new Float32Array(n);

  await k(c, { n, iter });
  const res = c.reduce((prev, curr) => prev + curr);
  console.log(`Result: ${res}`);
}
main();
```

---
_Source: https://npm.io/package/node-gpgpu · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
