Skip to content

Commit

Permalink
makes a plot i like
Browse files Browse the repository at this point in the history
  • Loading branch information
jowens committed Oct 9, 2024
1 parent 1d97380 commit 4643c55
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions membw.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@
if (!device) {
fail("Fatal error: Device does not support WebGPU.");
}
// [2**0, 2**9)
const workgroupLimit = 1; // 9;
const workgroupSizes = [...Array(workgroupLimit).keys()].map(
(i) => 2 ** i
);
// [2**0, 2**25)
const memsrcSizeLimit = 1; // 25;
const memsrcSizes = [...Array(memsrcSizeLimit).keys()].map((i) => 2 ** i);

const range = (min, max) => [...Array(max - min + 1).keys()].map(i => i + min);

const workgroupSizes = range(0,7).map((i) => 2 ** i);
const memsrcSizes = range(10,25).map((i) => 2 ** i);
for (const workgroupSize of workgroupSizes) {
for (const memsrcSize of memsrcSizes) {
const timingHelper = new TimingHelper(device);
Expand All @@ -63,17 +60,16 @@
const memcpyModule = device.createShaderModule({
label: "copy large chunk of memory from memSrc to memDest",
code: /* wgsl */ `
override wgSize: u32 = 1;
/* output */
@group(0) @binding(0) var<storage, read_write> memDest: array<u32>;
/* input */
@group(0) @binding(1) var<storage, read> memSrc: array<u32>;
@compute @workgroup_size(wgSize) fn memcpyKernel(
@compute @workgroup_size(${workgroupSize}) fn memcpyKernel(
@builtin(global_invocation_id) id: vec3u,
@builtin(num_workgroups) nwg: vec3u,
@builtin(workgroup_id) wgid: vec3u) {
let i = id.y * nwg.x * wgSize + id.x;
let i = id.y * nwg.x * ${workgroupSize} + id.x;
memDest[i] = memSrc[i] + 1;
}
`,
Expand All @@ -84,9 +80,6 @@
layout: "auto",
compute: {
module: memcpyModule,
constants: {
wgSize: workgroupSize,
},
},
});

Expand Down Expand Up @@ -179,10 +172,10 @@
} GB/s`
);
data.push({
time: ns[0],
time: ns,
bytesTransferred: bytesTransferred,
memsrcSize: memsrcSize,
bandwidth: bytesTransferred / ns[0],
bandwidth: bytesTransferred / ns,
workgroupSize: workgroupSize,
});
});
Expand All @@ -196,14 +189,17 @@
}

const plot = Plot.plot({
color: { legend: true },
color: { type: "ordinal", legend: true },
marks: [
Plot.lineY(data, {
x: "memsrcSize",
y: "bandwidth",
stroke: "workgroupSize",
}),
Plot.text(data, Plot.selectLast({x: "memsrcSize", y: "bandwidth", z: "workgroupSize", text: "workgroupSize", textAnchor: "start", dx: 3}))
],
x: {type: "log", label: "Copied array size (B)"},
y: {type: "log", label: "Achieved bandwidth (GB/s)"},
});
const div = document.querySelector("#plot");
div.append(plot);
Expand Down

0 comments on commit 4643c55

Please sign in to comment.