From 62807f4d6c1dcc9c5dd7aead6fc397340197dcdb Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 6 Jan 2025 14:31:16 -0800 Subject: [PATCH] Throw more specific error during search call. Revert workload again since research is saying mobile devices should be able to handle workgroups of 256. --- src/lib/workers/powgpu.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib/workers/powgpu.ts b/src/lib/workers/powgpu.ts index 23e3310..42decd5 100644 --- a/src/lib/workers/powgpu.ts +++ b/src/lib/workers/powgpu.ts @@ -33,9 +33,6 @@ export class PowGpu extends WorkerInterface { }) } - // Between 8-256 threads per workgroup based on hardware - static workload: number = Math.min(256, Math.max(64, 2 ** (navigator.hardwareConcurrency / 2))) - // WebGPU Compute Shader static shader = ` struct UBO { @@ -171,7 +168,7 @@ export class PowGpu extends WorkerInterface { * 8-byte work is split into two 4-byte u32. Low 4 bytes are random u32 from * UBO. High 4 bytes are the random value XOR'd with index of each thread. */ - @compute @workgroup_size(${this.workload}) + @compute @workgroup_size(256) fn main( @builtin(workgroup_id) workgroup_id: vec3, @builtin(local_invocation_id) local_id: vec3 @@ -474,7 +471,7 @@ export class PowGpu extends WorkerInterface { * @param {number} [threshold=0xfffffff8] - Difficulty of proof-of-work calculation */ static async search (hashHex: string, callback: (nonce: string | PromiseLike) => any, threshold: number = 0xfffffff8): Promise { - if (!/^[A-Fa-f0-9]{64}$/.test(hashHex)) throw new Error(`Invalid hash ${hashHex}`) + if (!/^[A-Fa-f0-9]{64}$/.test(hashHex)) throw new TypeError(`Invalid hash ${hashHex}`) if (typeof threshold !== 'number') throw new TypeError(`Invalid threshold ${threshold}`) // Ensure WebGPU is initialized before calculating, up to a max time frame -- 2.34.1