Table of Contents

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:

  1. Construct with tensor descriptors and operator choices.
  2. 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.
  3. Dispose (or use await using) to free CUDA resources.
public sealed class ElementwiseTrinary : IAsyncDisposable, IDisposable

Inheritance

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

extentA long[]

Sizes of each dimension of A.

modeA int[]

Mode labels for A.

extentB long[]

Sizes of each dimension of B.

modeB int[]

Mode labels for B.

extentC long[]

Sizes of each dimension of C.

modeC int[]

Mode labels for C.

extentD long[]

Sizes of each dimension of D (output).

modeD int[]

Mode labels for D.

dataType TensorDataType

Element type for all tensors. Default: NVMathNet.Tensor.TensorDataType.Float32.

opA CuTensorOperator

Unary operator applied to A before scaling. Default: identity.

opB CuTensorOperator

Unary operator applied to B before scaling. Default: identity.

opC CuTensorOperator

Unary operator applied to C before scaling. Default: identity.

opAB CuTensorOperator

Binary operator combining alphaopA(A) and betaopB(B). Default: NVMathNet.Interop.CuTensorOperator.Add.

opABC CuTensorOperator

Binary operator combining the prior result with gamma*opC(C). Default: NVMathNet.Interop.CuTensorOperator.Add.

options TensorContractionOptions?

Operation options; null uses defaults.

stream CudaStream?

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

pA nint

Device pointer to tensor A.

pB nint

Device pointer to tensor B.

pC nint

Device pointer to tensor C.

pD nint

Device pointer to output tensor D.

alpha double

Scalar multiplier for A. Default: 1.

beta double

Scalar multiplier for B. Default: 1.

gamma double

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

pA nint

Device pointer to tensor A.

pB nint

Device pointer to tensor B.

pC nint

Device pointer to tensor C.

pD nint

Device pointer to output tensor D.

alpha double

Scalar multiplier for A. Default: 1.

beta double

Scalar multiplier for B. Default: 1.

gamma double

Scalar multiplier for C. Default: 1.

ct CancellationToken

Cancellation token.

Returns

Task

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

a DeviceBuffer<T>
b DeviceBuffer<T>
c DeviceBuffer<T>
d DeviceBuffer<T>
alpha double

Scalar multiplier for A. Default: 1.

beta double

Scalar multiplier for B. Default: 1.

gamma double

Scalar multiplier for C. Default: 1.

ct CancellationToken

Cancellation token.

Returns

Task

Type Parameters

T

SynchronizeAsync(CancellationToken)

Waits for all work on the internal stream to complete.

public Task SynchronizeAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task