Skip to content

Commit 0eb612e

Browse files
committed
Fix Mac issue
1 parent 938d10f commit 0eb612e

5 files changed

Lines changed: 51 additions & 12 deletions

File tree

‎demo/index.js‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import glslangInit from '@webgpu/glslang/dist/web-devel/glslang.onefile';
55
// import * as tf from '@tensorflow/tfjs-core';
66
import * as utils from './utils.js';
77
import * as common from './common.js';
8-
import * as commonmac from './common_mac.js';
98

109
(async () => {
1110
if (!navigator.gpu) {
@@ -17,6 +16,18 @@ import * as commonmac from './common_mac.js';
1716
const enableTimeStamp = false;
1817
const device = await adapter.requestDevice();
1918
const glslang = await glslangInit();
20-
await common.runTestMatmul(device, glslang, 256, 256, 50, 50);
21-
await common.runTestAdd(device, glslang, 4096, 256, 50, 50);
19+
20+
const trials = 50, reps = 50;
21+
var size = 256;
22+
await common.runTestMatmul(device, glslang, size, size, trials, reps);
23+
size = 512;
24+
await common.runTestMatmul(device, glslang, size, size, trials, reps);
25+
size = 1024;
26+
await common.runTestMatmul(device, glslang, size, size, trials, reps);
27+
size = 2048;
28+
await common.runTestMatmul(device, glslang, size, size, trials, reps);
29+
30+
await common.runTestAdd(device, glslang, 4096, 256, trials, reps);
31+
await common.runTestAdd(device, glslang, 4096, 1024, trials, reps);
32+
2233
})();

‎demo/index_matmul.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import * as common from './common.js';
1616
const enableTimeStamp = false;
1717
const device = await adapter.requestDevice();
1818
const glslang = await glslangInit();
19-
const trials = 0, reps = 0;
19+
const trials = 50, reps = 50;
2020
var size = 256;
2121
await common.runTestMatmul(device, glslang, size, size, trials, reps);
2222
size = 384;

‎demo/utils.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function logTimes(name, times, trials, reps) {
1818
const times2 = times.map(function(time) {
1919
return Number(time.toFixed(2));
2020
});
21-
console.log(name + times2);
21+
// console.log(name + times2);
2222
const mean = times.reduce((a, b) => a + b, 0) / trials;
2323
const min = Math.min(...times);
2424
const fmt = (n) => n.toFixed(2);
@@ -56,11 +56,11 @@ export function executeOp(op) {
5656
op.executeSync();
5757
}
5858

59-
const MAXDIFF = 0.1;
59+
const MAXDIFF = 0.01;
6060
function compareThreeFloat32Array(a, b, c, w, h) {
6161
for (let i = 0; i < w * h; i++) {
6262
if (i == 0) {
63-
console.log('item 0=' + a[i] + ', ' + b[i] + ',' + c[i]);
63+
// console.log('item 0=' + a[i] + ', ' + b[i] + ',' + c[i]);
6464
}
6565
if (Math.abs(a[i] - b[i]) > MAXDIFF || Math.abs(b[i] - c[i]) > MAXDIFF ||
6666
Math.abs(a[i] - c[i]) > MAXDIFF) {
@@ -86,7 +86,7 @@ export function compareAddFloat32Array(result, firstMatrix, secondMatrix, w, h)
8686
export function compareFloat32Array(a, b, w, h, name) {
8787
for (let i = 0; i < w * h; i++) {
8888
if (i == 0) {
89-
console.log(name + 'item 0=' + a[i] + ', ' + b[i]);
89+
// console.log(name + 'item 0=' + a[i] + ', ' + b[i]);
9090
}
9191
if (Math.abs(a[i] - b[i]) > 0.01) {
9292
console.error(name + ' mismatch at ' + i + ', ' + a[i] + ',' + b[i]);

‎src/matmul_buffervec4.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,22 @@ export class MatmulBufferVec4Op extends BufferOp {
112112
// M = 32, we have 4 rows of work-items, so we need 32/4 8 results down
113113
// N = 128, we have 16 columns of work-items, so we need 128/16 = 8
114114
// results across = 2 float4s across
115-
vec4 dot00,dot01,dot02,dot03,dot04,dot05,dot06,dot07;
116-
vec4 dot10,dot11,dot12,dot13,dot14,dot15,dot16,dot17;
115+
vec4 dot00 = vec4(0.0, 0.0, 0.0, 0.0);
116+
vec4 dot01 = vec4(0.0, 0.0, 0.0, 0.0);
117+
vec4 dot02 = vec4(0.0, 0.0, 0.0, 0.0);
118+
vec4 dot03 = vec4(0.0, 0.0, 0.0, 0.0);
119+
vec4 dot04 = vec4(0.0, 0.0, 0.0, 0.0);
120+
vec4 dot05 = vec4(0.0, 0.0, 0.0, 0.0);
121+
vec4 dot06 = vec4(0.0, 0.0, 0.0, 0.0);
122+
vec4 dot07 = vec4(0.0, 0.0, 0.0, 0.0);
123+
vec4 dot10 = vec4(0.0, 0.0, 0.0, 0.0);
124+
vec4 dot11 = vec4(0.0, 0.0, 0.0, 0.0);
125+
vec4 dot12 = vec4(0.0, 0.0, 0.0, 0.0);
126+
vec4 dot13 = vec4(0.0, 0.0, 0.0, 0.0);
127+
vec4 dot14 = vec4(0.0, 0.0, 0.0, 0.0);
128+
vec4 dot15 = vec4(0.0, 0.0, 0.0, 0.0);
129+
vec4 dot16 = vec4(0.0, 0.0, 0.0, 0.0);
130+
vec4 dot17 = vec4(0.0, 0.0, 0.0, 0.0);
117131
// Src0 is used to load atile.
118132
// It starts at the left side of src0 and walks across.
119133
// atile is M rows x K columns.

‎src/matmul_texturergba32f.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,22 @@ export class MatmulTextureRGBA32FOp extends TextureOp {
114114
// M = 32, we have 4 rows of work-items, so we need 32/4 8 results down
115115
// N = 128, we have 16 columns of work-items, so we need 128/16 = 8
116116
// results across = 2 float4s across
117-
${this.vectorFormat} dot00,dot01,dot02,dot03,dot04,dot05,dot06,dot07;
118-
${this.vectorFormat} dot10,dot11,dot12,dot13,dot14,dot15,dot16,dot17;
117+
${this.vectorFormat} dot00 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
118+
${this.vectorFormat} dot01 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
119+
${this.vectorFormat} dot02 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
120+
${this.vectorFormat} dot03 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
121+
${this.vectorFormat} dot04 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
122+
${this.vectorFormat} dot05 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
123+
${this.vectorFormat} dot06 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
124+
${this.vectorFormat} dot07 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
125+
${this.vectorFormat} dot10 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
126+
${this.vectorFormat} dot11 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
127+
${this.vectorFormat} dot12 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
128+
${this.vectorFormat} dot13 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
129+
${this.vectorFormat} dot14 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
130+
${this.vectorFormat} dot15 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
131+
${this.vectorFormat} dot16 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
132+
${this.vectorFormat} dot17 = ${this.vectorFormat}(0.0, 0.0, 0.0, 0.0);
119133
// Src0 is used to load atile.
120134
// It starts at the left side of src0 and walks across.
121135
// atile is M rows x K columns.

0 commit comments

Comments
 (0)