oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.53k stars 2.71k forks source link

Can't import gpu.js #1084

Closed john--kane closed 11 months ago

john--kane commented 2 years ago

Version

0.1.8

Platform

macOS x64

What steps will reproduce the bug?

I'm getting a Seg Fault when I import gpu.js into my script.

I ran:

SegmentationFault at 0x0000000000000000

----- bun meta ----- Bun v0.1.8 macOS x64 RunCommand: Elapsed: 15ms | User: 13ms | Sys: 8ms RSS: 14.48MB | Peak: 14.47MB | Commit: 67.11MB | Faults: 0 ----- bun meta -----

How often does it reproduce? Is there a required condition?

every time, just steps above to reproduce

What is the expected behavior?

console log output with the calculated value (3)

What do you see instead?

Seg Fault

Additional information

Output from bun runtime:

SegmentationFault at 0x0000000000000000

----- bun meta ----- Bun v0.1.8 macOS x64 RunCommand: Elapsed: 16ms | User: 14ms | Sys: 7ms RSS: 14.54MB | Peak: 14.54MB | Commit: 67.11MB | Faults: 0 ----- bun meta -----

Ask for #help in https://bun.sh/discord or go to https://bun.sh/issues

innerop commented 2 years ago

Casual observer here...

AFAIK, you need a GPU<->JS layer like Google's ANGLE (to support WebGL on Node)

https://github.com/tensorflow/tfjs/tree/master/tfjs-backend-nodegl (mentions Node-GLES and ANGLE)

Or jump straight to WebGPU where you can use compute shaders

The gpu.js project currently has an empty folder for webgpu api support: https://github.com/gpujs/webgpu

I think bun has to support either WebGL via ANGLE or a WebGPU implementation or else you won't have any GPU support

john--kane commented 2 years ago

Hi innerop,

Thanks for the insight. Makes sense.

I kind of guessed the js engine under the bunjs hood would have provided that layer.

I ran the gpu.js code on node & demo and worked straight up without explicit angle deps. Is that to imply then that it has some node binding? If the webgl folder is empty, how might I get its bindings in bun?

I tried it on an older version of bun (not a comprehensive test) and it threw an exception around gl Error stacktrace bindings so I'm wondering if it's so low level thing that's not ported yet?

innerop commented 2 years ago

I assume in Node and Deno if the GPU layer is not available GPU.js will default to CPU usage.

However, I am not knowledgeable enough on what comes with Node out of the box as far as GPU support. My assumption is that such a layer is not built-in and has to be added, somehow.

In Node, the dependency for a WebGL backend is node-gles (which depends on ANGLE) ...

I do not know if Deno supports WebGPU out of the box (maybe it does) and I'm not sure what support for WebGPU exists in Node plugins/packages.

AFAIK, WebGPU provides compute shaders which I believe make GPU.js largely redundant.

Bun's author should know a lot more on the topic of Bun's support for GPU compute.

john--kane commented 2 years ago

Thanks for that, definitely helpful.

I'll drop a message on discord as well to see if I can get a lead on gl bindings in bun specifically.

john--kane commented 2 years ago

Is there anyone from the bun team that can help out? Tried discord but no luck. @Jarred-Sumner

innerop commented 2 years ago

@Jarred-Sumner bumping

it's a really simple question (yes/no/depends): does bun support node.js packages that require GPU accress?

Electroid commented 1 year ago

Attempted to run the following code, it looks like gpu.js also depends on Error.prepareStackTrace (#258)

import { GPU, KernelFunction, IKernelRunShortcut } from 'gpu.js';

const gpu = new GPU({ mode: 'gpu' });
const kernelFunction: KernelFunction = function(anInt: number, anArray: number[], aNestedArray: number[][]) {
  const x = .25 + anInt + anArray[this.thread.x] + aNestedArray[this.thread.x][this.thread.y];
  return x;
};
const kernel: IKernelRunShortcut = gpu.createKernel(kernelFunction)
  .setOutput([1]);
const result = kernel(1, [.25], [[1.5]]);
console.log(result[0]); // 3
Electroid commented 11 months ago

Since #258 you can run gpu.js. However, we still need to fix #4959 for you to be able to run bun install gpu.js.