---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/llm/transformers_js/helpers/functions/instrumentGpuBuffers.md
---

# Function: instrumentGpuBuffers()

```ts
function instrumentGpuBuffers(globalScope?: unknown): GpuBufferInstrument;
```

Defined in: [src/batteries/llm/chat\_common/gpu\_budget.ts:187](https://github.com/NHTIO/ADK/blob/v1.20260713.1/src/src/batteries/llm/chat_common/gpu_budget.ts#L187)

Install an OPT-IN live GPU-buffer instrument by wrapping `GPUDevice.prototype.createBuffer`.

## Parameters

| Parameter      | Type      | Description                                            |
| -------------- | --------- | ------------------------------------------------------ |
| `globalScope?` | `unknown` | Injectable global for tests; defaults to `globalThis`. |

## Returns

[`GpuBufferInstrument`](../interfaces/GpuBufferInstrument.md)

A [GpuBufferInstrument](../interfaces/GpuBufferInstrument.md); `sample()` returns zeroes when WebGPU is unavailable.

## Remarks

This is the packaged, productionized form of the diagnostic probe used to PROVE the ORT-web freelist
high-water-mark growth. It wraps `createBuffer` (and the returned buffer's `destroy`) on the device
prototype to tally live/peak GPU bytes, so an application can watch the working-set climb toward the
[GpuBudget](../interfaces/GpuBudget.md) ceiling and surface "you're at X of Y GiB" — turning the invisible cliff into a
gauge the user can act on BEFORE the OOM.

It is **purely observational and strictly opt-in**: nothing in the batteries installs it. Wrapping a
global prototype is intrusive, so this is never on by default — an application enables it consciously
(typically only in a debug/diagnostics build). Always `uninstall()` when done. Returns a no-op
instrument when WebGPU is unavailable (Node / no API).
