Table of Contents

Class TensorContraction

Namespace
NVMathNet.Tensor
Assembly
NVMath.Net.dll

Stateful cuTENSOR contraction wrapper. Mirrors the design of nvmath.tensor.TensorContraction:

  1. Construct with tensor descriptors.
  2. Call NVMathNet.Tensor.TensorContraction.PlanAsync(System.Threading.CancellationToken) to build the plan and select an algorithm.
  3. Call NVMathNet.Tensor.TensorContraction.ExecuteAsync(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.Double,System.Double,System.Threading.CancellationToken) to perform the contraction.
  4. Dispose to release CUDA resources.

Computes: D[modeD] = alpha * A[modeA] * B[modeB] + beta * C[modeC]

public sealed class TensorContraction : IAsyncDisposable, IDisposable

Inheritance

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

extentA long[]

Sizes of each dimension of A.

modeA int[]

Mode labels for A (one per dimension).

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); often same as extentC.

modeD int[]

Mode labels for D.

dataType TensorDataType

Element type for all tensors (default: float32).

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)

Synchronously performs the tensor contraction.

public void Execute(nint pA, nint pB, nint pC, nint pD, double alpha = 1, double beta = 0)

Parameters

pA nint
pB nint
pC nint
pD nint
alpha double
beta double

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

pA nint
pB nint
pC nint
pD nint
alpha double
beta double
ct CancellationToken

Returns

Task

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

a DeviceBuffer<T>
b DeviceBuffer<T>
c DeviceBuffer<T>
d DeviceBuffer<T>
alpha double
beta double
ct CancellationToken

Returns

Task

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

ct CancellationToken

Returns

Task

SynchronizeAsync(CancellationToken)

Waits for all work on the internal stream to complete.

public Task SynchronizeAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task