From: Chris Duncan Date: Fri, 17 Jan 2025 18:38:33 +0000 (-0800) Subject: Catch if nav.gpu does not exist. Make private method private. Fix rate reporting. X-Git-Tag: v2.0.0~30 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=0dd41daf622ac3bdd35a659afe97f8c27e2ca45a;p=nano-pow.git Catch if nav.gpu does not exist. Make private method private. Fix rate reporting. --- diff --git a/src/classes/gpu.ts b/src/classes/gpu.ts index bb079ba..d0a699e 100644 --- a/src/classes/gpu.ts +++ b/src/classes/gpu.ts @@ -24,8 +24,8 @@ export class NanoPowGpu { if (this.#busy) return this.#busy = true // Request device and adapter - if (navigator.gpu == null) throw new Error('WebGPU is not supported in this browser.') try { + if (navigator.gpu == null) throw new Error('WebGPU is not supported in this browser.') const adapter = await navigator.gpu.requestAdapter() if (adapter == null) throw new Error('WebGPU adapter refused by browser.') const device = await adapter.requestDevice() @@ -104,7 +104,7 @@ export class NanoPowGpu { NanoPowGpu.init() } - static logAverages (times: number[]): void { + static #logAverages (times: number[]): void { let count = times.length, sum = 0, reciprocals = 0, logarithms = 0, truncated = 0, min = 0xffff, max = 0, rate = 0 times.sort() for (let i = 0; i < count; i++) { @@ -118,7 +118,7 @@ export class NanoPowGpu { const averages = { "Count (dispatches)": count, "Total (ms)": sum, - "Rate (d/s)": count / sum * 1000, + "Rate (d/s)": 1000 * count / (truncated || sum), "Minimum (ms)": min, "Maximum (ms)": max, "Arithmetic Mean (ms)": sum / count, @@ -241,7 +241,7 @@ export class NanoPowGpu { this.#busy = !data.getUint32(8) times.push(performance.now() - start) } while (this.#busy) - if (debug) this.logAverages(times) + if (debug) this.#logAverages(times) return nonce.toString(16).padStart(16, '0') }