Class ElementwiseTrinary
- Namespace
- NVMathNet.Tensor
- Assembly
- NVMath.Net.dll
Stateful cuTENSOR element-wise trinary operation wrapper. Computes: D[modeD] = opABC(alpha * opA(A)[modeA], opAB(beta * opB(B)[modeB], gamma * opC(C)[modeC]))
Common use-cases include fused add/multiply of three same-shape tensors, e.g. D = alpha * A + beta * B + gamma * C (using NVMathNet.Interop.CuTensorOperator.Add for both binary ops).
Workflow:
- Construct with tensor descriptors and operator choices.
- Call NVMathNet.Tensor.ElementwiseTrinary.ExecuteAsync(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.Double,System.Double,System.Double,System.Threading.CancellationToken) to perform the operation.
- Dispose (or use
await using) to free CUDA resources.
public sealed class ElementwiseTrinary : IAsyncDisposable, IDisposableInheritance
Implements
Inherited Members
Constructors
ElementwiseTrinary(long[], int[], long[], int[], long[], int[], long[], int[], TensorDataType, CuTensorOperator, CuTensorOperator, CuTensorOperator, CuTensorOperator, CuTensorOperator, TensorContractionOptions?, CudaStream?)
Creates an element-wise trinary operation descriptor.
public ElementwiseTrinary(long[] extentA, int[] modeA, long[] extentB, int[] modeB, long[] extentC, int[] modeC, long[] extentD, int[] modeD, TensorDataType dataType = TensorDataType.Float32, CuTensorOperator opA = CuTensorOperator.Identity, CuTensorOperator opB = CuTensorOperator.Identity, CuTensorOperator opC = CuTensorOperator.Identity, CuTensorOperator opAB = CuTensorOperator.Add, CuTensorOperator opABC = CuTensorOperator.Add, TensorContractionOptions? options = null, CudaStream? stream = null)Parameters
extentAlong[]-
Sizes of each dimension of A.
modeAint[]-
Mode labels for A.
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).
modeDint[]-
Mode labels for D.
dataTypeTensorDataType-
Element type for all tensors. Default: NVMathNet.Tensor.TensorDataType.Float32.
opACuTensorOperator-
Unary operator applied to A before scaling. Default: identity.
opBCuTensorOperator-
Unary operator applied to B before scaling. Default: identity.
opCCuTensorOperator-
Unary operator applied to C before scaling. Default: identity.
opABCuTensorOperator-
Binary operator combining alphaopA(A) and betaopB(B). Default: NVMathNet.Interop.CuTensorOperator.Add.
opABCCuTensorOperator-
Binary operator combining the prior result with gamma*opC(C). Default: NVMathNet.Interop.CuTensorOperator.Add.
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, double)
Synchronously computes the element-wise trinary operation.
public void Execute(nint pA, nint pB, nint pC, nint pD, double alpha = 1, double beta = 1, double gamma = 1)Parameters
pAnint-
Device pointer to tensor A.
pBnint-
Device pointer to tensor B.
pCnint-
Device pointer to tensor C.
pDnint-
Device pointer to output tensor D.
alphadouble-
Scalar multiplier for A. Default: 1.
betadouble-
Scalar multiplier for B. Default: 1.
gammadouble-
Scalar multiplier for C. Default: 1.
ExecuteAsync(nint, nint, nint, nint, double, double, double, CancellationToken)
Asynchronously computes D = opABC(alphaopA(A), opAB(betaopB(B), gamma*opC(C))).
public Task ExecuteAsync(nint pA, nint pB, nint pC, nint pD, double alpha = 1, double beta = 1, double gamma = 1, CancellationToken ct = default)Parameters
pAnint-
Device pointer to tensor A.
pBnint-
Device pointer to tensor B.
pCnint-
Device pointer to tensor C.
pDnint-
Device pointer to output tensor D.
alphadouble-
Scalar multiplier for A. Default: 1.
betadouble-
Scalar multiplier for B. Default: 1.
gammadouble-
Scalar multiplier for C. Default: 1.
ctCancellationToken-
Cancellation token.
Returns
ExecuteAsync<T>(DeviceBuffer<T>, DeviceBuffer<T>, DeviceBuffer<T>, DeviceBuffer<T>, double, double, double, CancellationToken)
Asynchronously computes D = opABC(alphaopA(A), opAB(betaopB(B), gamma*opC(C))).
public Task ExecuteAsync<T>(DeviceBuffer<T> a, DeviceBuffer<T> b, DeviceBuffer<T> c, DeviceBuffer<T> d, double alpha = 1, double beta = 1, double gamma = 1, CancellationToken ct = default) where T : unmanaged, INumberBase<T>Parameters
aDeviceBuffer<T>bDeviceBuffer<T>cDeviceBuffer<T>dDeviceBuffer<T>alphadouble-
Scalar multiplier for A. Default: 1.
betadouble-
Scalar multiplier for B. Default: 1.
gammadouble-
Scalar multiplier for C. Default: 1.
ctCancellationToken-
Cancellation token.
Returns
Type Parameters
T
SynchronizeAsync(CancellationToken)
Waits for all work on the internal stream to complete.
public Task SynchronizeAsync(CancellationToken ct = default)