copyBandwidth static method

double copyBandwidth(
  1. int megabytes
)

GPU copy throughput in GB/s, bytes read plus written, over buffers of megabytes: roughly what the matrix products could reach.

Implementation

static double copyBandwidth(int megabytes) {
  final floats = megabytes << 18;
  final from = _Buffer(floats), to = _Buffer(floats);
  var best = 0.0;
  try {
    for (var i = 0; i < 3; i++) {
      _begin();
      _copy(from.handle, 0, to.handle, 0, floats);
      if (_commit(1) != 1) throw StateError('GPU command buffer failed');
      best = math.max(best, 2 * floats * 4 / (_lastGpuMs() / 1000) / 1e9);
    }
  } finally {
    _release(from.handle);
    _release(to.handle);
  }
  return best;
}