Performing tensor SVD using cuTensorNet adopts a very similar workflow as QR example. Here, we highlight the notable differences between the two APIs. The full code can be found in the NVIDIA/cuQuantum repository (here).
Define SVD decomposition#
As with QR decomposition, we first define the SVD decomposition to perform with the data type, modes partition, and the extents.
Note
To perform fixed extent truncation, we directly set maxExtent to half of the full extent corresponding to exact SVD.
Setup SVD truncation parameters#
Once the SVD decomposition is defined, we can follow the same workflow as QR example for data allocation and tensor descriptor initialization.
Before querying workspace, we can choose different SVD options in cutensornetTensorSVDConfig_t.
Meanwhile, we can create cutensornetTensorSVDInfo_t to keep track of runtime truncation information.
Execution#
Next, we can query and allocate the workspace with cutensornetWorkspaceComputeSVDSizes(), which is very similar to its QR counterpart.
At this stage, we can perform the SVD decomposition by calling cutensornetTensorSVD().
Note
Since we turned on weighted truncation options in this example, we need to restore the tensor descriptors for U and V if we wish to perform the same computation multiple times.
After the computation, we still need to free up all resources.