Useful tips#

  • For debugging, one can set the environment variable CUTENSORNET_LOG_LEVEL=n. The level n = 0, 1, …, 5 corresponds to the logger level as described and used in cutensornetLoggerSetLevel(). The environment variable CUTENSORNET_LOG_FILE=<filepath> can be used to redirect the log output to a custom file at <filepath> instead of stdout.

  • After a cuTensorNet API call returns a non-success status, call cutensornetGetLastError() to obtain a human-readable description of the most recent error captured on the calling thread. This is complementary to cutensornetGetErrorString(), which returns only the enum-name form of the status code. A common idiom is to combine both in a single error-handling macro:

    #define HANDLE_ERROR(x)                                                              \
        do {                                                                             \
            const auto err = x;                                                          \
            if (err != CUTENSORNET_STATUS_SUCCESS) {                                     \
                printf("Error: %s in line %d\n",                                         \
                       cutensornetGetErrorString(err), __LINE__);                        \
                const char* details = cutensornetGetLastError();                         \
                if (details != nullptr && details[0] != '\0')                            \
                    printf("Details: %s\n", details);                                    \
                exit(EXIT_FAILURE);                                                      \
            }                                                                            \
        } while (0)
    

    See the tensornet_example.cu sample for the full pattern in context.

    For a continuous diagnostic stream rather than a single message per failure, register a logger callback via cutensornetLoggerSetCallback; the callback fires on every log event at or below the configured level, which is broader (and noisier) than reading cutensornetGetLastError() after a failed call.