npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

webgpu-memory

v1.4.2

Published

Tracks WebGPU memory usage

Downloads

1,086

Readme

WebGPU-Memory

This is a WebGPU-Memory tracker. You add the script to your page before you initialize WebGPU and then for a given context you can ask how much WebGPU memory you're using.

Note: This is only a guess as various GPUs have different internal requirements. For example a GPU might have alignment requirements. Still, this is likely to give a reasonable approximation.

Usage

<script src="https://greggman.github.io/webgpu-memory/webgpu-memory.js" crossorigin></script>
<script>
  const {getWebGPUMemoryUsage} = webgpuMemory;

or

import {getWebGPUMemoryUsage} from 'https://greggman.github.io/webgpu-memory/webgpu-memory.js';

Then in your code

  const info = getWebGPUMemoryUsage();

The info returned is

{
  memory: {
    buffer: <bytes used by buffers>
    texture: <bytes used by textures>
    canvas: <bytes used by canvases>
    total: <bytes used in total>
  },
  resources: {
    buffer: <count of buffers>
    texture: <count of textures>
    devices: <count of devices or undefined if none>
    canvas: <count of canvases or undefined if none>
    sampler: <count of samplers or undefined if none>
    bindGroup: <count of bindGroups or undefined if none>
    bindGroupLayout: <count of bindGroupLayouts or undefined if none>
    pipelineLayout: <count of pipelineLayouts or undefined if none>
    shaderModule: <count of shaderModules or undefined if none>
    computePipeline: <count of computePipelines or undefined if none>
    renderPipeline: <count of renderPipelines or undefined if none>
    computePipeline: <count of computePipelines or undefined if none>
    renderPipeline: <count of renderPipelines or undefined if none>
    querySet: <count of querySets or undefined if none>
  },
}

By default getWebGPUMemoryUsage returns info for all devices. You can get info for a single device by passing the device.

const allInfo = getWebGPUMemoryUsage();
const deviceSpecificInfo = getWebGPUMemoryUsage(someDevice);

Caveats

  1. You must have WebGPU error free code.

    If your code is generating WebGPU errors you must fix those first before using this library. That also means it doesn't handle out-of-memory

  2. Most resources in WebGPU are garbage collected

    Only GPUDevice, GPUTexture, GPUBuffer, and GPUQuerySet have a destroy method. All other objects are garbage collected. That means, it's unknown when they will actually be collected. So for example, if you create 50 bind groups and then stop using them and lose all references to them it's undefined how long they will continue to exist.

    The point being, just because the number doesn't go down immediately after you stop using the object, doesn't mean you have a bug.

    One possible thing to try, at least in Chrome, you can pass the flag --js-flags="--expose-gc" and then there should be a global function gc so you could do

    ...release references to objects...
    gc(); 
    const info = getWebGPUMemoryUsage();

    Still, the resource counts are useful info. If you're not expecting to see them increase constantly and they are then you probably have an bug that's not losing all references to them.

  3. It doesn't track render bundles

    it's on the TODO list

  4. Lost contexts are not handled

    it's on the TODO list

Example:

Click here for an Example

Development

git clone https://github.com/greggman/webgpu-memory.git
cd webgpu-memory
npm install

now serve the folder

npx servez

and go to http://localhost:8080/test?src=true

src=true tells the test harness to use the unrolled source from the src folder where as without it uses webgpu-memory.js in the root folder which is built using npm run build.

grep=<some expression> will limit the tests as in ...?src=true&grep=texture only runs the tests with texture in their description.

Live Tests

built version
source version

Licence

MIT