Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: disallowing users to specify bb min memory allocation #4570

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions barretenberg/ts/src/barretenberg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const debug = createDebug('bb.js:wasm');

export type BackendOptions = {
threads?: number;
memory?: { initial?: number; maximum?: number };
memory?: { maximum: number };
};

/**
Expand All @@ -32,7 +32,7 @@ export class Barretenberg extends BarretenbergApi {
const worker = createMainWorker();
const wasm = getRemoteBarretenbergWasm<BarretenbergWasmMainWorker>(worker);
const { module, threads } = await fetchModuleAndThreads(desiredThreads);
await wasm.init(module, threads, proxy(debug), memory?.initial, memory?.maximum);
await wasm.init(module, threads, proxy(debug), memory?.maximum);
return new Barretenberg(worker, wasm);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class BarretenbergWasmMain extends BarretenbergWasmBase {
module: WebAssembly.Module,
threads = Math.min(getNumCpu(), BarretenbergWasmMain.MAX_THREADS),
logger: (msg: string) => void = debug,
initial = 26,
maximum = 2 ** 16,
initial = 26,
) {
this.logger = logger;

Expand Down
5 changes: 3 additions & 2 deletions noir/tooling/noir_js_backend_barretenberg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Backend, CompiledCircuit, ProofData } from '@noir-lang/types';
import { BackendOptions } from './types.js';
import { deflattenPublicInputs, flattenPublicInputsAsArray } from './public_inputs.js';
import { type Barretenberg } from '@aztec/bb.js';
import { cpus } from 'os';

export { publicInputsToWitnessMap } from './public_inputs.js';

Expand All @@ -24,7 +25,7 @@ export class BarretenbergBackend implements Backend {

constructor(
acirCircuit: CompiledCircuit,
private options: BackendOptions = { threads: 1 },
private options: BackendOptions = { threads: navigator ? navigator.hardwareConcurrency : cpus().length },
) {
const acirBytecodeBase64 = acirCircuit.bytecode;
this.acirUncompressedBytecode = acirToUint8Array(acirBytecodeBase64);
Expand All @@ -34,7 +35,7 @@ export class BarretenbergBackend implements Backend {
async instantiate(): Promise<void> {
if (!this.api) {
const { Barretenberg, RawBuffer, Crs } = await import('@aztec/bb.js');
const api = await Barretenberg.new({ threads: this.options.threads });
const api = await Barretenberg.new(this.options);

const [_exact, _total, subgroupSize] = await api.acirGetCircuitSizes(this.acirUncompressedBytecode);
const crs = await Crs.new(subgroupSize + 1);
Expand Down
2 changes: 2 additions & 0 deletions noir/tooling/noir_js_backend_barretenberg/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
export type BackendOptions = {
/** @description Number of threads */
threads: number;
/** @description Maximum memory to be allocated to the WASM (optional) */
memory?: { maximum: number };
};
Loading