useGpu method
Copies quantized matrices to the GPU for their linear products. Returns false where the GPU is unavailable or int8Inputs is enabled. Call before starting streams and serialize GPU work across isolates (see GpuLinear). Convolutions, norms and attention stay on the CPU.
Implementation
bool useGpu() {
if (_closed) throw StateError('Audio encoder is closed');
if (_gpu != null) return true;
if (int8Inputs) return false;
if (_streams.isNotEmpty) {
throw StateError(
'Close the audio encoder streams before changing backend',
);
}
final gpu = GpuLinear.start();
if (gpu == null) return false;
try {
for (final e in _matrices.entries) {
gpu.upload(e.key, e.value);
}
} catch (_) {
gpu.dispose();
rethrow;
}
_gpu = gpu;
return true;
}