upload method

void upload(
  1. String name,
  2. CachedMatrix matrix
)

Copies matrix (Q4 or Q8) into a GPU buffer of its own, under name.

Implementation

void upload(String name, CachedMatrix matrix) {
  _checkOpen();
  final qs = matrix.qsBytes, scales = matrix.scaleBytes;
  final scalesAt = (qs.length + 63) ~/ 64 * 64;
  final bytes = scalesAt + scales.length;
  final handle = _Buffer._check(_buffer(bytes), bytes);
  _owned.add(handle);
  final view = _contents(handle).cast<Uint8>().asTypedList(bytes);
  view
    ..setAll(0, qs)
    ..setAll(scalesAt, scales);
  final previous = _matrices[name];
  if (previous != null) {
    _owned.remove(previous.buffer);
    _release(previous.buffer);
  }
  _matrices[name] = _Matrix(
    switch (matrix.format) {
      'q4' => true,
      'q8' => false,
      final f => throw ArgumentError('cannot multiply $f matrices'),
    },
    handle,
    0,
    scalesAt,
    matrix.rows,
    matrix.cols,
  );
}