feat: add comparable localization algorithms
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { computeDasMap } from "../acoustics-core/das.js";
|
||||
import { computeGccPhatMap } from "../acoustics-core/gcc-phat.js";
|
||||
import {
|
||||
isDasAlgorithm,
|
||||
requireLocalizationAlgorithmDefinition,
|
||||
} from "../acoustics-core/localization-algorithms.js";
|
||||
import { computeDasWebGpu } from "./das.js";
|
||||
import { isRecoverableWebGpuError } from "./device.js";
|
||||
|
||||
@@ -17,7 +22,7 @@ function throwIfAborted(signal) {
|
||||
* Execute the requested DAS backend. `auto` falls back only for typed WebGPU
|
||||
* operational errors; invalid inputs and AbortError remain visible to callers.
|
||||
*/
|
||||
export async function computeDasWithBackend(options, dependencies = {}) {
|
||||
async function computeDasBackend(options, dependencies = {}) {
|
||||
const computeGpu = dependencies.computeGpu ?? computeDasWebGpu;
|
||||
const computeCpu = dependencies.computeCpu ?? computeDasMap;
|
||||
const requestedBackend = options?.experiment?.beamforming?.backend ?? "auto";
|
||||
@@ -56,3 +61,48 @@ export async function computeDasWithBackend(options, dependencies = {}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a DAS-family algorithm with the requested CPU/WebGPU policy.
|
||||
* Conventional DAS callers can keep using this backwards-compatible entry.
|
||||
*/
|
||||
export async function computeDasWithBackend(options, dependencies = {}) {
|
||||
const algorithm = requireLocalizationAlgorithmDefinition(
|
||||
options?.experiment?.beamforming?.algorithm,
|
||||
);
|
||||
if (!isDasAlgorithm(algorithm.id)) {
|
||||
throw new RangeError(
|
||||
`computeDasWithBackend does not implement ${algorithm.id}.`,
|
||||
);
|
||||
}
|
||||
return computeDasBackend(options, dependencies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute any registered localization algorithm. GCC-PHAT currently uses its
|
||||
* portable CPU implementation for both `auto` and `cpu`; an explicit WebGPU
|
||||
* request is rejected instead of silently changing the requested backend.
|
||||
*/
|
||||
export async function computeLocalizationWithBackend(options, dependencies = {}) {
|
||||
const algorithm = requireLocalizationAlgorithmDefinition(
|
||||
options?.experiment?.beamforming?.algorithm,
|
||||
);
|
||||
if (isDasAlgorithm(algorithm.id)) {
|
||||
return computeDasBackend(options, dependencies);
|
||||
}
|
||||
|
||||
const requestedBackend = options?.experiment?.beamforming?.backend ?? "auto";
|
||||
if (requestedBackend === "webgpu") {
|
||||
throw new TypeError(
|
||||
`${algorithm.label} currently supports only the CPU backend; choose auto or cpu.`,
|
||||
);
|
||||
}
|
||||
if (requestedBackend !== "auto" && requestedBackend !== "cpu") {
|
||||
throw new TypeError(`unsupported localization backend: ${requestedBackend}`);
|
||||
}
|
||||
const computeCpu =
|
||||
dependencies.computeGccCpu ??
|
||||
dependencies.computeCpu ??
|
||||
computeGccPhatMap;
|
||||
return computeCpu(options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user