denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.98k stars 5.23k forks source link

`WebGPU<-->BigInt`: Tensorflow.js - Initialization of backend webgpu failed TypeError: Cannot convert a BigInt value to a number #22029

Open josephrocca opened 7 months ago

josephrocca commented 7 months ago

Version: Deno 1.39.4

The code below works in Deno with an earlier tfjs-webgpu-backend version (see import_map.json here), but I raised the tfjs version numbers to 4.16.0 as shown below, and that produces the error logs below. I'm guessing that this is because newer versions of tf.js have started using BigInts, and Deno hasn't implemented some WebGPU<-->BigInt stuff.

I've confirmed that the code below works fine on Chrome (Windows).


deno.json

{
  "importMap": "import_map.json"
}

import_map.json

{
  "imports": {
    "@tensorflow/tfjs-core": "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.16.0/dist/tf-core.fesm.js",
    "@tensorflow/tfjs-backend-webgpu": "https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu@4.16.0/dist/tf-backend-webgpu.fesm.js"
  }
}

main.js

import * as tf from "@tensorflow/tfjs-core";
import "@tensorflow/tfjs-backend-webgpu";

await tf.ready();
tf.randomGamma([2, 2], 1).print();

Error Logs

deno run --unstable --allow-net=cdn.jsdelivr.net main.js
Initialization of backend webgpu failed
TypeError: Cannot convert a BigInt value to a number
    at toNumber (ext:deno_webidl/00_webidl.js:98:11)
    at Array.<anonymous> (ext:deno_webidl/00_webidl.js:255:13)
    at webidl.converters.GPUSize64 (ext:deno_webgpu/01_webgpu.js:5173:42)
    at ext:deno_webidl/00_webidl.js:904:28
    at Array.GPUDeviceDescriptor (ext:deno_webidl/00_webidl.js:788:32)
    at GPUAdapter.requestDevice (ext:deno_webgpu/01_webgpu.js:407:36)
    at Object.factory (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgpu@4.16.0/dist/tf-backend-webgpu.fesm.js:2138:38)
    at async Engine.ready (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.16.0/dist/tf-core.fesm.js:4248:29)
    at async file:///home/joe/Downloads/denotfjs/main.js:4:1
error: Uncaught (in promise) Error: Could not initialize any backends, all backend initializations failed.
        throw new Error(`Could not initialize any backends, all backend initializations ` +
              ^
    at Engine.ready (https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core@4.16.0/dist/tf-core.fesm.js:4254:15)
    at async file:///home/joe/Downloads/denotfjs/main.js:4:1
Mutefish0 commented 7 months ago

run into the same problem

petamoriken commented 7 months ago

The spec defines GPUSize64 as unsigned long long, which uses ConvertToInt, so it appears that bigint is not allowed. Is this a spec bug?

mmastrac commented 7 months ago

@josephrocca Could you print the output of this code from your repl in both Chrome and deno?

const adapter = await navigator.gpu.requestAdapter();
console.log(adapter.limits);
josephrocca commented 7 months ago

@mmastrac Sorry for delay - was waiting to get access to the Windows machine again (I have linux, which doesn't support webgpu on chrome). Here are the logs:

Chrome:

maxTextureDimension1D: 16384
maxTextureDimension2D: 16384
maxTextureDimension3D: 2048
maxTextureArrayLayers: 2048
maxBindGroups: 4
maxBindGroupsPlusVertexBuffers: 24
maxBindingsPerBindGroup: 1000
maxDynamicUniformBuffersPerPipelineLayout: 10
maxDynamicStorageBuffersPerPipelineLayout: 8
maxSampledTexturesPerShaderStage: 16
maxSamplersPerShaderStage: 16
maxStorageBuffersPerShaderStage: 10
maxStorageTexturesPerShaderStage: 8
maxUniformBuffersPerShaderStage: 12
maxUniformBufferBindingSize: 65536
maxStorageBufferBindingSize: 2147483644
minUniformBufferOffsetAlignment: 256
minStorageBufferOffsetAlignment: 256
maxVertexBuffers: 8
maxBufferSize: 2147483648
maxVertexAttributes: 16
maxVertexBufferArrayStride: 2048
maxInterStageShaderComponents: 112
maxInterStageShaderVariables: 28
maxColorAttachments: 8
maxColorAttachmentBytesPerSample: 128
maxComputeWorkgroupStorageSize: 32768
maxComputeInvocationsPerWorkgroup: 1024
maxComputeWorkgroupSizeX: 1024
maxComputeWorkgroupSizeY: 1024
maxComputeWorkgroupSizeZ: 64
maxComputeWorkgroupsPerDimension: 65535

Deno:

  maxTextureDimension1D: 16384,
  maxTextureDimension2D: 16384,
  maxTextureDimension3D: 2048,
  maxTextureArrayLayers: 2048,
  maxBindGroups: 8,
  maxBindingsPerBindGroup: 65535,
  maxBufferSize: 2147483647,
  maxDynamicUniformBuffersPerPipelineLayout: 12,
  maxDynamicStorageBuffersPerPipelineLayout: 0,
  maxSampledTexturesPerShaderStage: 16,
  maxSamplersPerShaderStage: 16,
  maxStorageBuffersPerShaderStage: 0,
  maxStorageTexturesPerShaderStage: 0,
  maxUniformBuffersPerShaderStage: 12,
  maxUniformBufferBindingSize: 65536,
  maxStorageBufferBindingSize: 0,
  minUniformBufferOffsetAlignment: 256,
  minStorageBufferOffsetAlignment: 256,
  maxVertexBuffers: 16,
  maxVertexAttributes: 16,
  maxVertexBufferArrayStride: 4294967295,
  maxInterStageShaderComponents: 124,
  maxComputeWorkgroupStorageSize: 0,
  maxComputeInvocationsPerWorkgroup: 0,
  maxComputeWorkgroupSizeX: 0,
  maxComputeWorkgroupSizeY: 0,
  maxComputeWorkgroupSizeZ: 0,
  maxComputeWorkgroupsPerDimension: 0

Edge:

maxTextureDimension1D: 16384
maxTextureDimension2D: 16384
maxTextureDimension3D: 2048
maxTextureArrayLayers: 2048
maxBindGroups: 4
maxBindGroupsPlusVertexBuffers: 24
maxBindingsPerBindGroup: 1000
maxDynamicUniformBuffersPerPipelineLayout: 10
maxDynamicStorageBuffersPerPipelineLayout: 8
maxSampledTexturesPerShaderStage: 16
maxSamplersPerShaderStage: 16
maxStorageBuffersPerShaderStage: 10
maxStorageTexturesPerShaderStage: 8
maxUniformBuffersPerShaderStage: 12
maxUniformBufferBindingSize: 65536
maxStorageBufferBindingSize: 2147483644
minUniformBufferOffsetAlignment: 256
minStorageBufferOffsetAlignment: 256
maxVertexBuffers: 8
maxBufferSize: 2147483648
maxVertexAttributes: 16
maxVertexBufferArrayStride: 2048
maxInterStageShaderComponents: 112
maxInterStageShaderVariables: 28
maxColorAttachments: 8
maxColorAttachmentBytesPerSample: 128
maxComputeWorkgroupStorageSize: 32768
maxComputeInvocationsPerWorkgroup: 1024
maxComputeWorkgroupSizeX: 1024
maxComputeWorkgroupSizeY: 1024
maxComputeWorkgroupSizeZ: 64
maxComputeWorkgroupsPerDimension: 65535