flush method
Flush the contents of the DeviceBuffer to the GPU.
This method can only be used if the DeviceBuffer was created with StorageMode.hostVisible. An exception will be thrown otherwise.
If lengthInBytes
is set to -1, the entire buffer will be flushed.
On devices with coherent host memory (memory shared between the CPU and GPU), this method is a no-op.
Implementation
void flush({int offsetInBytes = 0, int lengthInBytes = -1}) {
if (storageMode != StorageMode.hostVisible) {
throw Exception(
'DeviceBuffer.flush can only be used with DeviceBuffers that are host visible');
}
if (offsetInBytes < 0 || offsetInBytes >= sizeInBytes) {
throw Exception('offsetInBytes must be within the bounds of the buffer');
}
if (lengthInBytes < -1) {
throw Exception('lengthInBytes must be either positive or -1');
}
if (lengthInBytes != -1 && offsetInBytes + lengthInBytes > sizeInBytes) {
throw Exception(
'The provided range must not be too large to fit within the buffer');
}
_flush(offsetInBytes, lengthInBytes);
}