Xpra: Ticket #1414: recognising nvenc 7.1 fails

Hello,

Xpra currently fails for NVENC versions which have a minor number != 0.

In xpra/codecs/nvenc7 the following code checks the version of the NVENC API in init_module() (line 2531):

    if NVENCAPI_VERSION!=0x7:
        raise Exception("unsupported version of NVENC: %#x" % NVENCAPI_VERSION)

NVENCAPI_VERION comes from header file Samples/common/inc/nvEncodeAPI.h of NVIDIAs NVENC SDK. It is defined here like this (line 113):

    #define NVENCAPI_VERSION (NVENCAPI_MAJOR_VERSION | (NVENCAPI_MINOR_VERSION << 24))''

This means that NVENCAPI_VERSION looks like this:

    0x0000007 == 0x7 for 7.0
    0x1000007 != 0x7 for 7.1

=> if NVENCAPI_VERSION!=0x7: fails for version 7.1

nvEncodeAPI.h also defines
    #define NVENCAPI_MAJOR_VERSION 7

A possible fix could be:

    if NVENCAPI_MAJOR_VERSION != 7:
        raise Exception("unsupported version of NVENC: %#x" % NVENCAPI_MAJOR_VERSION)

Best, Jens Henrik



Tue, 17 Jan 2017 15:57:29 GMT - Antoine Martin: status, description changed

Thanks - will fix ASAP.


Tue, 17 Jan 2017 21:05:14 GMT - Jens H. Goebbert: component changed

One more thing in this context:

In xpra/codecs/nvenc7/encoder.py NVENCAPI_VERSION is currently of type 'unsigned int' and therefore not explicitly defined as 32 or 64 bit.

The #define from nvEncoderAPI.h "expects" an uint32 as it shifts the minor version number by 24 bits to the left.


Wed, 18 Jan 2017 03:34:55 GMT - Antoine Martin: owner, status changed

Fixed for trunk in r14809, r14810 for v1.0.x. (only compile tested)

Please close if that works for you.


Wed, 18 Jan 2017 10:17:16 GMT - Jens H. Goebbert:

Hello,

thanks for adding the fix. I tested this on our system and the first problem is fixed!

Anyway, NVIDIA has extended the NV_ENCODE_API_FUNCTION_LIST to version 2 in NVENC_SDK 7.1. This ends up in the following error:

>>xpra/install/lib/python2.7/site-packages/tests/xpra/codecs$ python test_nvenc7.py
2017-01-18 10:24:54,446 CUDA initialization (this may take a few seconds)
2017-01-18 10:24:54,940 CUDA 8.0.0 / PyCUDA 2016.1.2, found 2 devices:
2017-01-18 10:24:54,940   + Tesla K40m @ 0000:02:00.0 (memory: 97% free, compute: 3.5)
2017-01-18 10:24:55,514   + Tesla K40m @ 0000:81:00.0 (memory: 99% free, compute: 3.5)
2017-01-18 10:24:55,757 NVidia driver version 367.48
2017-01-18 10:24:56,106 device matches preferred device id 0: Tesla K40m @ 0000:02:00.0
Traceback (most recent call last):
  File "test_nvenc7.py", line 23, in <module>
    main()
  File "test_nvenc7.py", line 12, in main
    test_nvenc.test_encode_one()
  File "/homeb/zam/goebbert/workspace/xpra/install/lib/python2.7/site-packages/tests/xpra/codecs/test_nvenc.py", line 30, in test_encode_one
    test_encoder(encoder_module)
  File "/homeb/zam/goebbert/workspace/xpra/install/lib/python2.7/site-packages/tests/xpra/codecs/test_encoder.py", line 45, in test_encoder
    encoder_module.init_module()
  File "xpra/codecs/nvenc7/encoder.pyx", line 2577, in xpra.codecs.nvenc7.encoder.init_module (xpra/codecs/nvenc7/encoder.c:36607)
  File "xpra/codecs/nvenc7/encoder.pyx", line 2497, in xpra.codecs.nvenc7.encoder.Encoder.open_encode_session (xpra/codecs/nvenc7/encoder.c:34916)
  File "xpra/codecs/nvenc7/encoder.pyx", line 1319, in xpra.codecs.nvenc7.encoder.raiseNVENC (xpra/codecs/nvenc7/encoder.c:9276)
xpra.codecs.nvenc7.encoder.NVENCException: getting API function list - returned 15: This indicates that an invalid struct version was used by the client.


The new NV_ENCODE_API_FUNCTION_LIST (version 2) looks like this and added three new functions at the end:

ctypedef struct NV_ENCODE_API_FUNCTION_LIST_2:
        uint32_t                        version
        uint32_t                        reserved
        PNVENCOPENENCODESESSION         nvEncOpenEncodeSession
        PNVENCGETENCODEGUIDCOUNT        nvEncGetEncodeGUIDCount
        PNVENCGETENCODEPROFILEGUIDCOUNT nvEncGetEncodeProfileGUIDCount
        PNVENCGETENCODEPROFILEGUIDS     nvEncGetEncodeProfileGUIDs
        PNVENCGETENCODEGUIDS            nvEncGetEncodeGUIDs
        PNVENCGETINPUTFORMATCOUNT       nvEncGetInputFormatCount
        PNVENCGETINPUTFORMATS           nvEncGetInputFormats
        PNVENCGETENCODECAPS             nvEncGetEncodeCaps
        PNVENCGETENCODEPRESETCOUNT      nvEncGetEncodePresetCount
        PNVENCGETENCODEPRESETGUIDS      nvEncGetEncodePresetGUIDs
        PNVENCGETENCODEPRESETCONFIG     nvEncGetEncodePresetConfig
        PNVENCINITIALIZEENCODER         nvEncInitializeEncoder
        PNVENCCREATEINPUTBUFFER         nvEncCreateInputBuffer
        PNVENCDESTROYINPUTBUFFER        nvEncDestroyInputBuffer
        PNVENCCREATEBITSTREAMBUFFER     nvEncCreateBitstreamBuffer
        PNVENCDESTROYBITSTREAMBUFFER    nvEncDestroyBitstreamBuffer
        PNVENCENCODEPICTURE             nvEncEncodePicture
        PNVENCLOCKBITSTREAM             nvEncLockBitstream
        PNVENCUNLOCKBITSTREAM           nvEncUnlockBitstream
        PNVENCLOCKINPUTBUFFER           nvEncLockInputBuffer
        PNVENCUNLOCKINPUTBUFFER         nvEncUnlockInputBuffer
        PNVENCGETENCODESTATS            nvEncGetEncodeStats
        PNVENCGETSEQUENCEPARAMS         nvEncGetSequenceParams
        PNVENCREGISTERASYNCEVENT        nvEncRegisterAsyncEvent
        PNVENCUNREGISTERASYNCEVENT      nvEncUnregisterAsyncEvent
        PNVENCMAPINPUTRESOURCE          nvEncMapInputResource
        PNVENCUNMAPINPUTRESOURCE        nvEncUnmapInputResource
        PNVENCDESTROYENCODER            nvEncDestroyEncoder
        PNVENCINVALIDATEREFFRAMES       nvEncInvalidateRefFrames
        PNVENCOPENENCODESESSIONEX       nvEncOpenEncodeSessionEx
        PNVENCREGISTERRESOURCE          nvEncRegisterResource
        PNVENCUNREGISTERRESOURCE        nvEncUnregisterResource
        PNVENCRECONFIGUREENCODER        nvEncReconfigureEncoder
        void*                           reserved1
        PNVENCCREATEMVBUFFER            nvEncCreateMVBuffer
        PNVENCDESTROYMVBUFFER           nvEncDestroyMVBuffer
        PNVENCRUNMOTIONESTIMATIONONLY   nvEncRunMotionEstimationOnly
        void*                           reserved2[281]


A bug in NVENC_SDK 7.1.9 probably gives some problems right now with this struct and should be fixed first: https://devtalk.nvidia.com/default/topic/988719/video-technologies/bug-report-for-nvenc_sdk-7-1-9-nvencoderapi-h-/

Best, Jens Henrik


Wed, 18 Jan 2017 13:14:50 GMT - Jens H. Goebbert:

The error comes for a version check inside the Nvidia libs. The requested version is not supported by the installed drivers. Our installed NVIDIA driver is too old and does not support the version of the NV_ENCODE_API_FUNCTION_LIST. I have to downgrade the NVENC_SDK and try again.

Anyway, just for completeness: NV_ENCODE_API_FUNCTION_LIST is defined like this:

#define NVENCAPI_STRUCT_VERSION(ver) ((uint32_t)NVENCAPI_VERSION | ((ver)<<16) | (0x7 << 28))

It is not just "2", but includes the NVENCAPI_VERSION, which is expected to be of type uint32_t.


Wed, 18 Jan 2017 13:27:55 GMT - Jens H. Goebbert:

Video Codec SDK 6.0 is supported on R358 drivers and above. Video Codec SDK 7.0 is supported on R367 drivers and above. Video Codec SDK 7.1 is supported on R375 drivers and above.

Reference: http://developer.download.nvidia.com/designworks/video-codec-sdk/secure/7.1/01/NVENC_DA-06209-001_v08.pdf?autho=1484746075_f21894e21eab962eb4cd7bb925c24c21&file=NVENC_DA-06209-001_v08.pdf http://developer.download.nvidia.com/assets/cuda/files/NVENC_DA-06209-001_v07.pdf


Wed, 18 Jan 2017 16:31:06 GMT - Jens H. Goebbert: status changed; resolution set

nvenc with the new patch runs fine for SDK 7.0. It compiles fine for SDK 7.1 and fails in a later stage on our machines, because of an too old driver. This is not a Xpra related bug.

My last comments are just "nice-to-know" but no bugs. The mentioned three extra functions are not listed in Xpra but space is reserved.

Hence -> close ticket.


Wed, 18 Jan 2017 17:47:19 GMT - Antoine Martin:

Nice to see that nvidia has finally started documenting what SDK works with what driver version. (it was a guessing game previously)

FYI: better driver version validation has been added in r14817.


Sat, 23 Jan 2021 05:23:40 GMT - migration script:

this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/1414