]> zoso.dev Git - nano-pow.git/commitdiff
Catch if nav.gpu does not exist. Make private method private. Fix rate reporting.
authorChris Duncan <chris@zoso.dev>
Fri, 17 Jan 2025 18:38:33 +0000 (10:38 -0800)
committerChris Duncan <chris@zoso.dev>
Fri, 17 Jan 2025 18:38:33 +0000 (10:38 -0800)
src/classes/gpu.ts

index bb079ba21036f0b46852d063256e8cf42a683047..d0a699e1629224d94976896ba910c0960787b45b 100644 (file)
@@ -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')
        }