Skip to content

setThreadsCount not work. #8513

Open
Open
@MountainAndMorning

Description

@MountainAndMorning

Please make sure that this is a bug. As per our
GitHub Policy,
we only address code/doc bugs, performance issues, feature requests and
build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): No.
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 15 macbook pro m1 max
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: No
  • TensorFlow.js installed from (npm or script link): https://www.npmjs.com/package/@tensorflow/tfjs-backend-wasm
  • TensorFlow.js version (use command below): "^4.22.0"
  • Browser version: "electron": "^30.0.1",
  • Tensorflow.js Converter Version:

Describe the current behavior
This is an electron application. In the fronend main.js file we run:

import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-backend-wasm';
import {setWasmPaths, getThreadsCount, setThreadsCount} from '@tensorflow/tfjs-backend-wasm';
setWasmPaths('/node_modules/@tensorflow/tfjs-backend-wasm/dist/');
tf.env().set('WASM_HAS_SIMD_SUPPORT', true)
setThreadsCount(4);
tf.setBackend('wasm').then(() => {
  console.log(getThreadsCount(), 'threads count');
});

console output:

1 'threads count'

Describe the expected behavior

console output:

4 'threads count'

vite.config.js

import { defineConfig } from 'vite'
import path from 'node:path'
import electron from 'vite-plugin-electron/simple'
import vue from '@vitejs/plugin-vue'
// Vuetify
import vuetify from 'vite-plugin-vuetify'
import { viteStaticCopy } from 'vite-plugin-static-copy'


// https://vitejs.dev/config/
export default defineConfig({
  server: {
    headers: {
      "Cross-Origin-Opener-Policy": "same-origin",
      "Cross-Origin-Embedder-Policy": "require-corp"
    }
  },
  preview: {
    headers: {
      "Cross-Origin-Opener-Policy": "same-origin",
      "Cross-Origin-Embedder-Policy": "require-corp"
    }
  },
  plugins: [
    vue(),
    vuetify({ autoImport: true }),
    electron({
      main: {
        // Shortcut of `build.lib.entry`.
        entry: 'electron/main.ts',
        // External packages that should not be bundled
        external: ['electron', 'bonjour', 'electron-store', 'get-port', 'realm'],
        // Build options
        buildOptions: {
          minify: false,
        },
      },
      preload: {
        // Shortcut of `build.rollupOptions.input`.
        // Preload scripts may contain Web assets, so use the `build.rollupOptions.input` instead `build.lib.entry`.
        input: path.join(__dirname, 'electron/preload.ts'),
      },
      // Ployfill the Electron and Node.js API for Renderer process.
      // If you want use Node.js in Renderer process, the `nodeIntegration` needs to be enabled in the Main process.
      // See https://github.com/electron-vite/vite-plugin-electron-renderer
      renderer: {
        resolve: {
          'realm': { type: 'cjs' }
        }
      },
    }),
    viteStaticCopy({
      targets: [
        { src: 'node_modules/@itk-wasm/image-io/dist/pipelines/*.{js,wasm,wasm.zst}', dest: 'pipelines' },
        { src: 'node_modules/@itk-wasm/dicom/dist/pipelines/*.{js,wasm,wasm.zst}', dest: 'pipelines' },
        { src: 'node_modules/@tensorflow/tfjs-backend-wasm/dist/*.wasm', dest: 'tfjs-backend-wasm' }
      ],
    })
  ],
  worker: {
    format: 'es'
  },
  optimizeDeps: {
    exclude: ['@itk-wasm/dicom', '@itk-wasm/image-io']
  },
})

package.json

{
  "name": "electronvite",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build && electron-builder",
    "preview": "vite preview"
  },
  "dependencies": {
    "@itk-wasm/dicom": "^7.3.0",
    "@itk-wasm/image-io": "^1.4.0",
    "@kitware/vtk.js": "^32.9.0",
    "@tensorflow/tfjs": "^4.22.0",
    "@tensorflow/tfjs-backend-wasm": "^4.22.0",
    "@tensorflow/tfjs-backend-webgpu": "^4.22.0",
    "axios": "^1.7.9",
    "bonjour": "^3.5.0",
    "d3": "^7.9.0",
    "electron-store": "^8.1.0",
    "get-port": "^7.1.0",
    "lodash-es": "^4.17.21",
    "muuri": "^0.9.5",
    "realm": "^12.14.1",
    "uuid": "^11.0.5"
  },
  "devDependencies": {
    "@mdi/js": "^7.4.47",
    "@vitejs/plugin-vue": "^5.0.4",
    "electron": "^30.0.1",
    "electron-builder": "^24.13.3",
    "typescript": "^5.2.2",
    "vite": "^5.1.6",
    "vite-plugin-electron": "^0.28.6",
    "vite-plugin-electron-renderer": "^0.14.5",
    "vite-plugin-static-copy": "^2.2.0",
    "vite-plugin-vuetify": "^2.0.4",
    "vue": "^3.4.21",
    "vue-tsc": "^2.0.26",
    "vuetify": "^3.7.6"
  },
  "main": "dist-electron/main.js"
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions