useGpu method

bool useGpu()

Moves the products of the native (Q4 or Q8) matrices to the GPU, copying them into GPU memory; the CPU copies stay as they are. Returns whether it did: false without native matrices or where the GPU does not start. The rest of the encoder stays on the CPU. Outputs then differ from the CPU kernels' in the last bits. Encode only while no other isolate runs a GPU forward pass (see GpuLinear).

Implementation

bool useGpu() {
  if (_closed) throw StateError('vision encoder is closed');
  if (_gpu != null) return true;
  if (_native.isEmpty) return false;
  final gpu = GpuLinear.start();
  if (gpu == null) return false;
  try {
    for (final e in _native.entries) {
      gpu.upload(e.key, e.value);
    }
  } catch (_) {
    gpu.dispose();
    rethrow;
  }
  _gpu = gpu;
  return true;
}