This is an automated email from the ASF dual-hosted git repository.
ruihangl pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push:
new c91fde574c [WebGPU] This PR fixes the webgpu runtime when there is no
pod params (#14685)
c91fde574c is described below
commit c91fde574ce24529bec50e07fd04df2c628ebb17
Author: Tianqi Chen <[email protected]>
AuthorDate: Fri Apr 21 02:21:35 2023 -0400
[WebGPU] This PR fixes the webgpu runtime when there is no pod params
(#14685)
This is a hotfix to update webgpu runtime and fix behavior when
there is no pod params.
---
web/src/webgpu.ts | 78 +++++++++++++++++++++++++++----------------------------
1 file changed, 39 insertions(+), 39 deletions(-)
diff --git a/web/src/webgpu.ts b/web/src/webgpu.ts
index fe128421c7..0459e32415 100644
--- a/web/src/webgpu.ts
+++ b/web/src/webgpu.ts
@@ -542,15 +542,13 @@ export class WebGPUContext {
assert(paramWriteAccess.length == bufferArgIndices.length);
// POD arguments are pass in the end
- if (podArgIndices.length != 0) {
- layoutEntries.push({
- binding: bufferArgIndices.length,
- visibility: GPUShaderStage.COMPUTE,
- buffer : {
- type: "uniform"
- }
- });
- }
+ layoutEntries.push({
+ binding: bufferArgIndices.length,
+ visibility: GPUShaderStage.COMPUTE,
+ buffer : {
+ type: "uniform"
+ }
+ });
const bindGroupLayout = this.device.createBindGroupLayout({
entries: layoutEntries
@@ -615,38 +613,36 @@ export class WebGPUContext {
}
// push pod buffer
- if (podArgIndices.length != 0) {
- const sizeOfI32 = 4;
- const podArgBuffer = this.getPodArgsBuffer((podArgIndices.length +
1) * sizeOfI32);
- const i32View = new Int32Array(podArgIndices.length + 1);
- const u32View = new Uint32Array(i32View.buffer);
- const f32View = new Float32Array(i32View.buffer);
-
- for (let i = 0; i < podArgIndices.length; ++i) {
- const value = args[podArgIndices[i]];
- const dtype = finfo.arg_types[podArgIndices[i]];
- if (dtype.startsWith("int")) {
- i32View[i] = value;
- } else if (dtype.startsWith("uint")) {
- u32View[i] = value;
- } else if (dtype.startsWith("float")) {
- f32View[i] = value;
- } else {
- throw Error("Unknown pod dtype " + dtype);
- }
+ const sizeOfI32 = 4;
+ const podArgBuffer = this.getPodArgsBuffer((podArgIndices.length + 1)
* sizeOfI32);
+ const i32View = new Int32Array(podArgIndices.length + 1);
+ const u32View = new Uint32Array(i32View.buffer);
+ const f32View = new Float32Array(i32View.buffer);
+
+ for (let i = 0; i < podArgIndices.length; ++i) {
+ const value = args[podArgIndices[i]];
+ const dtype = finfo.arg_types[podArgIndices[i]];
+ if (dtype.startsWith("int")) {
+ i32View[i] = value;
+ } else if (dtype.startsWith("uint")) {
+ u32View[i] = value;
+ } else if (dtype.startsWith("float")) {
+ f32View[i] = value;
+ } else {
+ throw Error("Unknown pod dtype " + dtype);
}
- // always pass in dim z launching grid size in
- u32View[podArgIndices.length] = packDimX;
- this.device.queue.writeBuffer(podArgBuffer, 0, i32View.buffer);
-
- bindGroupEntries.push({
- binding: bufferArgIndices.length,
- resource: {
- buffer: podArgBuffer,
- size: i32View.buffer.byteLength
- }
- });
}
+ // always pass in dim z launching grid size in
+ u32View[podArgIndices.length] = packDimX;
+ this.device.queue.writeBuffer(podArgBuffer, 0, i32View.buffer);
+
+ bindGroupEntries.push({
+ binding: bufferArgIndices.length,
+ resource: {
+ buffer: podArgBuffer,
+ size: i32View.buffer.byteLength
+ }
+ });
compute.setBindGroup(0, this.device.createBindGroup({
layout: bindGroupLayout,
@@ -749,6 +745,10 @@ export class WebGPUContext {
// DeviceAPI
private deviceAllocDataSpace(nbytes: number): GPUPointer {
+ // allocate 0 bytes buffer as 1 bytes buffer.
+ if (nbytes == 0) {
+ nbytes = 1;
+ }
const buffer = this.device.createBuffer({
size: nbytes,
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC |
GPUBufferUsage.COPY_DST,