Gpu 0.1.0 tiledsparsedenseproduct multiply - CyrilB1531/lodestar GitHub Wiki
Lodestar.Gpu 0.1.0. This page is frozen at that release. Read the current documentation for what
mainsays now. A link to a decision or a migration page followsmain, and leaves the archive.
Computes matrix ยท block, row-major.
public double[] Multiply(DeviceSparseMatrix matrix, ReadOnlySpan<double> block, int width)
public DeviceDenseBlock Multiply(DeviceSparseMatrix matrix, DeviceDenseBlock block)Parameters โ matrix is the resident sparse left operand, on both overloads. block is the
dense right operand: on the first overload a host span of matrix.ColumnCount rows by width โ the
same shape CsrMatrix.Multiply takes โ and on the second a resident block, which is the entry
point that chains. width says how many columns the host span holds, and is read from the resident
block instead on the second overload.
Returns โ double[] of matrix.RowCount ร width for the host overload;
DeviceDenseBlock of matrix.RowCount ร block.ColumnCount for the resident one.
Exceptions โ ArgumentNullException when an argument is null;
ArgumentOutOfRangeException when width is below 1; ArgumentException when the operands do not
compose.
Example โ the shape a caller writes.
using Lodestar.Gpu.Compute;
using var context = GpuContext.Create(preferCpu: true);
using var matrix = DeviceSparseMatrix.Upload(
context, [0, 1], [0], [4.0], rowCount: 1, columnCount: 2);
var kernel = new TiledSparseDenseProduct(context);
using var operand = DeviceDenseBlock.Upload(context, [1.0, 2.0, 3.0, 4.0], 2, 2);
using DeviceDenseBlock resident = kernel.Multiply(matrix, operand);
double first = resident.Download()[0]; // => 4Remarks โ the host overload delegates to the resident one, so the convenience entry point and the chaining entry point cannot compute different answers. That the suite's parity tests pass through both unchanged is the evidence for it.
The resident overload is what makes a chain: its result is the type its own operand is, so a second
product consumes it without crossing the bus. The caller ends the chain with
DeviceDenseBlock.Download and pays one copy for however many steps
it held โ measured at 1.24ร to 2.94ร faster than the same steps round-tripped.
The host overload is not a chain of length one. It uploads, multiplies and downloads, so using it twice in a row pays four crossings where the resident overload pays two.
Applies to โ net10.0, netstandard2.1.
See also โ TiledSparseDenseProduct.