WasmGPU.compute.CPUndarray.uploadToGPU¶
Summary¶
WasmGPU.compute.CPUndarray.uploadToGPU uploads CPU ndarray bytes into a newly created GPU storage-buffer ndarray.
The output is a GPUndarray with copied dtype/layout metadata.
Use this to move prepared CPU arrays into compute pipelines.
Optional storage-buffer descriptor fields control GPU usage flags and labels.
Syntax¶
WasmGPU.compute.CPUndarray.uploadToGPU(ctx: { device: GPUDevice; queue: GPUQueue }, desc?: Omit<StorageBufferDescriptor, "byteLength" | "data">): GPUndarray
const gpuArray = cpuArray.uploadToGPU(wgpu.gpu, desc);
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
ctx |
{ device: GPUDevice; queue: GPUQueue } |
Yes | GPU device/queue context used to allocate and upload the storage buffer. |
desc |
Omit<StorageBufferDescriptor, "byteLength" \| "data"> |
No | Optional storage-buffer flags (label, copySrc, copyDst, usage). |
Returns¶
GPUndarray - GPU-resident ndarray backed by a StorageBuffer.
Example¶
const canvas = document.querySelector("canvas");
const wgpu = await WasmGPU.create(canvas);
const cpu = wgpu.compute.CPUndarray.fromArray("f32", [4], new Float32Array([1, 2, 3, 4]));
const gpu = cpu.uploadToGPU(wgpu.gpu, { copySrc: true, label: "cpu-upload" });
console.log(cpu.residency, gpu.residency);