The following code example illustrates how to integrate cuTensorNet functionalities to perform tensor QR operation. The full code can be found in the NVIDIA/cuQuantum repository (here).

Define QR decomposition#

We first define the QR decomposition to perform with the data type, modes partition, and the extents.

Note

cutensornetTensorQR() operates in reduced mode, expecting the shared extent for the output to be the minimum of the combined row extent and the combined column extent.

Allocate memory and initialize data#

Next, we allocate memory for the input and output tensor operands. The input operand is initialized to random values.

Initialize cuTensorNet and create tensor descriptors#

Then we initialize the library handle of cuTensorNet and create cutensorTensorDescriptor_t for input and output tensors.

Query and allocate required workspace#

Once all tensor descriptors are created, we can query the required workspace size with cutensornetWorkspaceComputeQRSizes().

Execution#

At this stage, we can perform the QR decomposition by calling cutensornetTensorQR().

Free resources#

After the computation, we need to free up all resources.