Class TensorContraction
- Namespace
- NVMathNet.Tensor
- Assembly
- NVMath.Net.dll
Stateful cuTENSOR contraction wrapper.
Mirrors the design of nvmath.tensor.TensorContraction:
- Construct with tensor descriptors.
- Call NVMathNet.Tensor.TensorContraction.PlanAsync(System.Threading.CancellationToken) to build the plan and select an algorithm.
- Call NVMathNet.Tensor.TensorContraction.ExecuteAsync(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.Double,System.Double,System.Threading.CancellationToken) to perform the contraction.
- Dispose to release CUDA resources.
Computes: D[modeD] = alpha * A[modeA] * B[modeB] + beta * C[modeC]
public sealed class TensorContraction : IAsyncDisposable, IDisposableInheritance
Implements
Inherited Members
Constructors
TensorContraction(long[], int[], long[], int[], long[], int[], long[], int[], TensorDataType, TensorContractionOptions?, CudaStream?)
Creates a TensorContraction descriptor.
public TensorContraction(long[] extentA, int[] modeA, long[] extentB, int[] modeB, long[] extentC, int[] modeC, long[] extentD, int[] modeD, TensorDataType dataType = TensorDataType.Float32, TensorContractionOptions? options = null, CudaStream? stream = null)Parameters
extentAlong[]-
Sizes of each dimension of A.
modeAint[]-
Mode labels for A (one per dimension).
extentBlong[]-
Sizes of each dimension of B.
modeBint[]-
Mode labels for B.
extentClong[]-
Sizes of each dimension of C.
modeCint[]-
Mode labels for C.
extentDlong[]-
Sizes of each dimension of D (output); often same as extentC.
modeDint[]-
Mode labels for D.
dataTypeTensorDataType-
Element type for all tensors (default: float32).
optionsTensorContractionOptions?-
Operation options;
nulluses defaults. streamCudaStream?-
Optional external stream.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()Returns
- ValueTask
-
A task that represents the asynchronous dispose operation.
Execute(nint, nint, nint, nint, double, double)
Synchronously performs the tensor contraction.
public void Execute(nint pA, nint pB, nint pC, nint pD, double alpha = 1, double beta = 0)Parameters
ExecuteAsync(nint, nint, nint, nint, double, double, CancellationToken)
Asynchronously performs D = alphaAB + beta*C.
Completes when the GPU kernel finishes if NVMathNet.Tensor.TensorContractionOptions.Blocking is true.
public Task ExecuteAsync(nint pA, nint pB, nint pC, nint pD, double alpha = 1, double beta = 0, CancellationToken ct = default)Parameters
Returns
ExecuteAsync<T>(DeviceBuffer<T>, DeviceBuffer<T>, DeviceBuffer<T>, DeviceBuffer<T>, double, double, CancellationToken)
Asynchronously performs D = alphaAB + beta*C.
Completes when the GPU kernel finishes if NVMathNet.Tensor.TensorContractionOptions.Blocking is true.
public Task ExecuteAsync<T>(DeviceBuffer<T> a, DeviceBuffer<T> b, DeviceBuffer<T> c, DeviceBuffer<T> d, double alpha = 1, double beta = 0, CancellationToken ct = default) where T : unmanaged, INumberBase<T>Parameters
aDeviceBuffer<T>bDeviceBuffer<T>cDeviceBuffer<T>dDeviceBuffer<T>alphadoublebetadoublectCancellationToken
Returns
Type Parameters
T
Plan()
Synchronously selects the best contraction algorithm.
public void Plan()PlanAsync(CancellationToken)
Selects the best contraction algorithm on a background thread.
public Task PlanAsync(CancellationToken ct = default)Parameters
Returns
SynchronizeAsync(CancellationToken)
Waits for all work on the internal stream to complete.
public Task SynchronizeAsync(CancellationToken ct = default)