MCPcopy Index your code
hub / github.com/apache/tvm / tryCreateBuffer

Function tryCreateBuffer

web/src/webgpu.ts:165–188  ·  view source on GitHub ↗

* Create GPU buffer with `createBuffer()` but with error catching; destroy if error caught. * @param device The GPUDevice used to create a buffer. * @param descriptor The GPUBufferDescriptor passed to `createBuffer()`. * @returns The buffer created by `createBuffer()`. * * Note: We treat any er

(device: GPUDevice, descriptor: GPUBufferDescriptor)

Source from the content-addressed store, hash-verified

163 * `device.destroy()` with `device.lost.then()`.
164 */
165function tryCreateBuffer(device: GPUDevice, descriptor: GPUBufferDescriptor) {
166 device.pushErrorScope("out-of-memory");
167 device.pushErrorScope("validation");
168 device.pushErrorScope("internal");
169
170 const buffer = device.createBuffer(descriptor);
171
172 // Destroy at most once even if multiple error types fire.
173 Promise.all([
174 device.popErrorScope(),
175 device.popErrorScope(),
176 device.popErrorScope(),
177 ]).then((errors) => {
178 const captured = errors.filter((error): error is GPUError => error !== null);
179 if (captured.length > 0) {
180 device.destroy();
181 captured.forEach((error) => console.error(error));
182 }
183 }).catch((err) => {
184 console.error("Failed to pop error scopes:", err);
185 });
186
187 return buffer;
188}
189
190const canvasRenderWGSL = `
191@group(0) @binding(0) var my_sampler : sampler;

Callers 2

deviceAllocDataSpaceMethod · 0.85

Calls 2

filterMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…