Skip to content

Returning array broken with mode:dev #719

Closed

Description

@rotu

What's our vector, Victor?

What is wrong?

Returning an array from a kernel returns data full of NaN instead of the expected values.

Where does it happen?

When the GPU is created with {mode: "dev"} and the kernel code returns an array (e.g. return [1,2,3] instead of a single value return 2)

How do we replicate the issue?

run the tests in return-arrays.js with mode modified to be 'dev'.

Alternatively, see codepen here:
https://codepen.io/rotu-the-bold/pen/LYLwBqy

How important is this (1-5)?

3

Expected behavior (i.e. solution)

In dev mode, the kernel should return the same value as in GPU mode.

Activity

  1. fuzzie360 commented on Jul 22, 2026

    @fuzzie360
    Member

    As part of reviving the project, we're closing stale support questions and version-specific reports from older releases. A lot changed today: 2.17.0–2.19.2 shipped and are on npm (npm install gpu.js), installs work on modern Node, new GPU() works in current browsers, Apple Silicon precision issues are fixed, and CI now guards every change. If this is still relevant on gpu.js@2.19.2, please open a fresh issue with a repro — happy to help. (See #807 for the full status update.)

  2. rotu commented on Jul 23, 2026

    @rotu
    Author

    @fuzzie360 This still fails in exactly the same way. Could you please reopen?

  3. fuzzie360 commented on Jul 24, 2026

    @fuzzie360
    Member

    Reopened — thanks for re-verifying on 2.19.2. Apologies for sweeping this up in the stale batch-close; it's back in the triaged bug queue.

  4. fuzzie360 commented on Jul 24, 2026

    @fuzzie360
    Member

    Fixed upstream in gpu-mock.js v1.4.0 — mode: 'dev' delegates kernels entirely to gpu-mock.js, whose mock loops assigned each thread's return value into a Float32Array slot, so array returns coerced to NaN. Array-returning kernels now yield a Float32Array per thread, matching the real backends. Verified against your exact repro through gpu.js dev mode: [[1,2,3],[1,2,3],[1,2,3],[1,2,3]].

    One step remains before this closes: publishing gpu-mock.js@1.4.0 to npm (maintainer access being sorted, same story as gpu.js's was) and bumping the dependency here. Will update when it ships.

  5. added a commit that references this issue on Jul 26, 2026
    0da8078
  6. fuzzie360 commented on Jul 26, 2026

    @fuzzie360
    Member

    Shipped in 2.19.4, now on npm — npm install gpu.js@2.19.4.

    The fix went upstream into gpu-mock.js 1.4.0 (which mode: 'dev' delegates to) and gpu.js now depends on that release rather than the fork it had been pinned to. Verified from a clean npm install of 2.19.4:

    const { GPU } = require('gpu.js');
    const gpu = new GPU({ mode: 'dev' });
    const kernel = gpu.createKernel(function() { return [1, 2, 3]; }, { output: [4] });
    kernel(); // [[1,2,3], [1,2,3], [1,2,3], [1,2,3]]  — was NaN throughout

    Array returns now match the real backends in one, two and three dimensions, and number returns still come back as a flat Float32Array. test/features/dev-mode.js covers all of that plus explicit parity against cpu mode, so running return-arrays.js under dev — your original suggestion — would pass too.

    Thanks for re-verifying this after the batch-close; both issues you asked to reopen turned out to be real, and this one reached further than gpu.js itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions