Samples for NvSci inter thread communication

I am looking into inter thread communication on the DriveAGX Pegasus and found the NvStreams.

I read through the documentation and was wondering if NVIDIA provides any sample program of how to use NvSciStream or NvSciIpc for inter thread communication, as I could not find any.

Hardware Platform: DRIVE AGX Pegasus™ Developer Kit
Software Version: Example: DRIVE Software 10
Host Machine Version: Example: native Ubuntu 18.04
SDK Manager Version: Example: 1.0.1.5538

Hi @klaus.kofler,

After DRIVE Software 10.0 installed, you can find nvscistream_sample source in ~/nvidia/nvidia_sdk/DRIVE_Software_10.0_Linux_OS_DDPX/DRIVEOS/drive-t186ref-linux/samples/nvsci/nvscistream/ on your host system. Thanks!

Thanks. I found the sample. I have tried to run it on the DriveAGX and I get the follwoing output:

Producer:

$ ./nvscistream_sample -p nvscistream_0
NvMedia producer created
Producer channel created
Query max number of sync objects allowed: 4.

Number of waiter sync objects: 1.



 ========================= Producer Connection setup =========================

Connecting over Ipc... waiting for consumer connection

Producer channel connected
========================================= ==================================================


 ========================= Producer Sync requirement setup =========================

Producer creates NvSciSync attributes:

Create signaler's sync attribute list.
Set nvmedia-signaler attribute value.
Create waiter's sync attribute list.
Set nvmedia-waiter attribute value.
Producer sends sync attribute to producer:

Send waiter's sync object requirement.

========================================= ==================================================


 ========================= Producer Packet requirement setup =========================

Producer creates NvSciBuf attributes:

Create NvSciBuf attribute list of element 0.
Set attribute value of element 0.
Producer sends packet requirements to the pool:

Send the number of elements per packet to the pool, 1.

Send buffer attributes of element 0.

========================================= ==================================================


 ========================= Producer finalize requirements and map resources =========================

Pool + Producer receive packet and resource requirements.
and process them once all are received

Receive waiter's sync object requirement.

Producer received producer attributes
Common: Reconcile its signaler attributes and the reveived waiter attributes.

Common: Create NvSciSync object 0 with the reconciled attribute list.

Producer reconciled producer attributes and creates sync object:
	sending sync objects to consumer...
Send number of sync objects, 1.

Send sync object 0.

Pool Receives number of elements per packet from producer: 1.

Receive the number of sync objects, 1.

Pool Receives number of elements per packet from consumer: 1.

Receive sync object 0.

Pool Receives packet capabilities of element 0 from producer.

Pool Receives packet requirements of element 0 from consumer.

Pool received all prod / cons packet Attrs
Query max number of elements per packet allowed: 4.

Determine the number of elements per packet: 1.

Reconcile producer's and consumer's attribute lists of element 0.

Send the reconciled attribute list of element 0 to producer and consumer.

Pool creates a new packet 0:

Create buffer object of element 0 with the reconciled attribute list.

Assign pool cookie 1 to the packet, and
			send this new packet (handle = fffffffffffffffe) to producer and consumer.

Send buffer object of element 0 to producer and consumer.

Pool creates a new packet 1:

Create buffer object of element 0 with the reconciled attribute list.

Assign pool cookie 2 to the packet, and
			send this new packet (handle = fffffffffffffffd) to producer and consumer.

Send buffer object of element 0 to producer and consumer.

Pool creates a new packet 2:

Create buffer object of element 0 with the reconciled attribute list.

Assign pool cookie 3 to the packet, and
			send this new packet (handle = fffffffffffffffc) to producer and consumer.

Send buffer object of element 0 to producer and consumer.

Pool creates a new packet 3:

Create buffer object of element 0 with the reconciled attribute list.

Assign pool cookie 4 to the packet, and
			send this new packet (handle = fffffffffffffffb) to producer and consumer.

Send buffer object of element 0 to producer and consumer.

Receive the number of elements per packet from pool: 1.

Received PacketStatus (cookie = 1) from consumer, total received = 1.

Receive reconciled attributes of element0from pool.
Received PacketStatus (cookie = 2) from consumer, total received = 2.

Receive a new packet (handle = fffffffffffffffe),
			1 packet(s) received.

Assign cookie c00c1e5 to the packet (handle = 0x43e560).

Received PacketStatus (cookie = 1) from producer, total received = 1.

Receive buffer object of element 0.

Received PacketStatus (cookie = 3) from consumer, total received = 3.

Receive a new packet (handle = fffffffffffffffd),
			2 packet(s) received.

Assign cookie c00c1e6 to the packet (handle = 0x43e5a8).

Received PacketStatus (cookie = 2) from producer, total received = 2.

Receive buffer object of element 0.

Received PacketStatus (cookie = 4) from consumer, total received = 4.

Receive a new packet (handle = fffffffffffffffc),
			3 packet(s) received.

Assign cookie c00c1e7 to the packet (handle = 0x43e5f0).

Received PacketStatus (cookie = 3) from producer, total received = 3.

Receive buffer object of element 0.

Received ElementStatus (cookie = 1, idx = 0) from consumer, total received = 1.

Receive a new packet (handle = fffffffffffffffb),
			4 packet(s) received.

Assign cookie c00c1e8 to the packet (handle = 0x43e638).

Producer receives consumer's sync object:

Producer initializes NvSciSyncFence:

Producer maps buffer objects:

Producer Mapping element: 0 of cookie c00c1e5.
Accept elements in packet (handle = fffffffffffffffe).

Producer Mapping element: 0 of cookie c00c1e6.
Accept elements in packet (handle = fffffffffffffffd).

Producer Mapping element: 0 of cookie c00c1e7.
Accept elements in packet (handle = fffffffffffffffc).

Producer Mapping element: 0 of cookie c00c1e8.
[ERROR: NvSciBufObjDup]: Bad parameter supplied to NvSciBufObjDup
[ERROR: NvSciBufObjDup]: bufObj: (nil), dupObj: 0x43e788
/dvs/git/dirty/git-master_linux/tests/nvsci/nvscistream/sample_app/nvmedia_producer.cpp (84), mapBuffers: NvSci error 100

Consumer:

$ ./nvscistream_sample -c nvscistream_1 -q 1
CUDA Consumer Created
Consumer channel created
Query max number of sync objects allowed: 4.

Number of waiter sync objects: 1.



 ========================= Consumer Connection setup =========================

Connecting over Ipc... waiting for producer connection
Consumer channel connected



 ========================= Consumer Sync requirement setup =========================

Consumer creates NvSciSync attributes:

Create signaler's sync attribute list.
Set CUDA-signaler attribute value.
Create waiter's sync attribute list.
Set CUDA-waiter attribute value.
Consumer sends sync attribute to producer:

Send waiter's sync object requirement.

========================================= ==================================================


 ========================= Consumer Packet requirement setup =========================

Consumer creates NvSciBuf attributes:

Create NvSciBuf attribute list of element 0.
Set attribute value of element 0.
Consumer sends packet requirements to the pool:

Send the number of elements per packet to the pool, 1.

Send buffer attributes of element 0.

========================================= ==================================================


 ========================= Consumer finalize requirements and map resources =========================

Receive waiter's sync object requirement.

Consumer received producer attributes
Common: Reconcile its signaler attributes and the reveived waiter attributes.

Common: Create NvSciSync object 0 with the reconciled attribute list.

Consumer reconciled producer attributes and creates sync object:
	sending sync objects to producer...
Send number of sync objects, 1.

Send sync object 0.

Receive the number of sync objects, 1.

Receive sync object 0.

Receive the number of elements per packet from pool: 1.

Receive reconciled attributes of element0from pool.
Receive a new packet (handle = 18446744073709551614),
			1 packet(s) received.

Assign cookie c00c1e5 to the packet (handle = 0x43e340).

Receive buffer object of element 0.

Receive a new packet (handle = fffffffffffffffd),
			2 packet(s) received.

Assign cookie c00c1e6 to the packet (handle = 0x43e388).

Receive buffer object of element 0.

Receive a new packet (handle = fffffffffffffffc),
			3 packet(s) received.

Assign cookie c00c1e7 to the packet (handle = 0x43e3d0).

Receive buffer object of element 0.

Receive a new packet (handle = fffffffffffffffb),
			4 packet(s) received.

Assign cookie c00c1e8 to the packet (handle = 0x43e418).

Consumer maps sync objects:

Consumer initializes NvSciSyncFence:

Consumer maps buffer objects:

Consumer Mapping element: 0 of cookie c00c1e5.
Accept elements in packet (handle = fffffffffffffffe).

Consumer Mapping element: 0 of cookie c00c1e6.
Accept elements in packet (handle = fffffffffffffffd).

Consumer Mapping element: 0 of cookie c00c1e7.
Accept elements in packet (handle = fffffffffffffffc).

Consumer Mapping element: 0 of cookie c00c1e8.
[ERROR: NvSciBufObjGetAttrList]: Bad parameter supplied to NvSciBufObjGetAttrList
[ERROR: NvSciBufObjGetAttrList]: bufObj: (nil), bufAttrList: 0x7ff72208a8
/dvs/git/dirty/git-master_linux/tests/nvsci/nvscistream/sample_app/cuda_consumer.cpp (70), mapBuffers: NvSci error 100

So it seems the message passing works but there happens an error at the end. Futhermore, if I try to run the sample again I do get the following error messages.

Producer:

$ ./nvscistream_sample -p nvscistream_0
!err[L:81]:nvsciipc_ipc_check_end: pid not 0, but process doesn't exist, (pid:2576)
!err[L:614]:nvsciipc_ipc_open_endpoint: init resources is failed: 256
!err[L:286]:NvSciIpcOpenEndpoint: Failed to open nvsciipc [INTER_PROCESS] endpoint: 256
/dvs/git/dirty/git-master_linux/tests/nvsci/nvscistream/sample_app/channel_producer.cpp (56), initIpc: NvSci error 100

Consumer:

$ ./nvscistream_sample -c nvscistream_1 -q 1
!err[L:81]:nvsciipc_ipc_check_end: pid not 0, but process doesn't exist, (pid:2577)
!err[L:614]:nvsciipc_ipc_open_endpoint: init resources is failed: 256
!err[L:286]:NvSciIpcOpenEndpoint: Failed to open nvsciipc [INTER_PROCESS] endpoint: 256
/dvs/git/dirty/git-master_linux/tests/nvsci/nvscistream/sample_app/channel_consumer.cpp (52), initIpc: NvSci error 100

Appearently the channel is broken in some way and won’t work until the system has been rebooted. I assume this is not the expected behavior of this sample. Does somebody have a hint where I should start to look for the error?

I can reproduce the issue and will check if it was already fixed and will be available in the following release.

If the nvscistream_sample application fails to open IPC channel, clean up NvSciIpc resources with below commands may help.

sudo rm -rf /dev/mqueue/*
sudo rm -rf /dev/shm/*

Thanks, that makes the channels usable again without reboot.

Looking forward to get more information about the other issue from you.

Hi I had a question regarding this sample: in nvmedia_producer class in the creaeBufAttrList method it seems like setupBuffers() duplicates the same work done later in the method. What is the reason for that?

It looks like the NvSciBufAttrLists are created twice.
Also why does setupBuffers() allocate the NvSciBufObj without reconciling the consumers bufatrrlist?

Thanks for your help!

Hi @jaisood,

NvMedia producer client has 2 types of buffers.

  • A shared buffer that is to be shared with other end client over NvSciStream (NvMedia API output)
  • A local buffer which is internal to NvMedia producer (NvMedia API input)

Below code snippet (in nvmedia_producer.cpp) is where UMDs access of the two kinds of buffers.
void NvMediaProducer::processPayload(NvSciStreamCookie cookie)
{

CHECK_NVMEDIAERR(NvMedia2DBlitEx(nvm2d,
nvmimage[id][0],
NULL,
nvmimg_in[id],
NULL,
NULL,
NULL));

}

Steps to create these buffer are different.

  • Shared Buffer creation
  1. NvMedia provides filled buffer attribute list to NvSciStream via createBufAttrList()
  2. NvStreams gets attribute list from other end client also and then reconciles both the attribute lists. Then allocates buffer (NvSciBufObj) using the reconciled attribute list. (in reconcilePacketAttrs() of packet_pool_manager.cpp)
  3. NvMedia gets the NvSciBufObj from NvStreams using which it creates NvMediaImage in mapBuffers (in allocBuffers() of packet_pool_manager.cpp)
  • A local buffer creation (since this buffer is not shared to other end, NvStreams and other end client are not invloved in the buffer creation process )
  1. NvMedia Fills buffer attribute list, Reconciles it and allocates NvSciBufObj
  2. Then Creates NvMediaImage from NvSciBufObj.
    This is done in setupBuffers() which is called from createBufAttrList()

createBufAttrList() performs 2 things:

  1. Allocates local input NvMediaImages by calling SetupBuffers API
  2. Provides filled NvSciBuf attribute list to NvStreams for output shared NvMediaImages.
1 Like

Hi @VickNV ,

Thanks for the info! I am now working on adapting this sample to work with an nvmedia consumer as well as a cuda consumer. I have my nvmedia consumer also receiving the packet ready events so the stream seems to be setup correctly. However I am not sure how I can move the nvmedia image object out of the buffer so my consumer can operate on it. Is the correct approach to do something similar to how we write an image on the producer side and use NvMedia2DBlitEx()?

Any help would be appreciated thanks!

Is there also some sample/documentation available how to use a cuda producer?

You should call NvMediaImageCreateFromNvSciBuf() during the setup to access the NvMediaImage as how the producer has done.

Please check if https://docs.nvidia.com/cuda/cuda-samples/index.html#cuda-nvscibuf-nvscisync-interop is what you’re looking for. Thanks!

The nvscibuf sample does only cover inter thread communication within one thread. It does not seem obvious to me how it can be adapted to use NvSciIpc for inter thread communication or change the nvscistream sample to use CUDA as a producer. NVIDIA does not provide any samples that show how to do that, right?

Furthermore, the nvscisteam sample has this bug that produces an error at the end, as mentioned in previous posts. Did anybody find out how to fix that or if that will be fixed in a future release?

Yes, there is no sample for that. Basically you can use NvSciStreamBlockConnect() to connect NvSciStreamBlock blocks created by NvSciStreamProducerCreate() and NvSciStreamConsumerCreate() respectively and don’t need to call NvSciStreamIpcSrcCreate() and NvSciStreamIpcDstCreate().

The error will be fixed in a future release.

I am now trying to use SIPL and NvSci together. I have looked at the sample but it is very confusing.
I have an instance of INvSIPLCamera in my class.
I get my platform configuration and my sensor id and my output type and set my mask.
Then I make a notifier and a pipeline consumer.
Then I do NvSIPLCamera::GetInstance()
I add my callback, clients, and notifier to my pipeline config and i set my cropcfg.
Then I call setplatformcfg and setpipelineconf
Finally I call Init();
When I try to call FillNvSciSyncAttrList with my sensor id my output type and my attr list i get very unhelpful errors.

: CNvMISPBlock.cpp: 287: FillNvSciSyncAttrList: NvMediaISPFillNvSciSyncAttrList failed. nvmStatus:7
: CNvMSensorPipeline.cpp: 281: FillNvSciSyncAttrList: ISP block NvSciSync attribute fill failed
: CNvMCamera.cpp: 633: FillNvSciSyncAttrList: Pipeline manager NvSciSync attribute fill failed for pipeline:0

what is going on here?

Hi @jaisood,

Please share your source code and the steps of building and reproducing for us to check it easier. Thanks!

Hi Vicky I am using the sample and am getting this error when calling FillNvSciSyncAttrList:

: CNvMISPBlock.cpp: 287: FillNvSciSyncAttrList: NvMediaISPFillNvSciSyncAttrList failed. nvmStatus:7
: CNvMSensorPipeline.cpp: 281: FillNvSciSyncAttrList: ISP block NvSciSync attribute fill failed
: CNvMCamera.cpp: 633: FillNvSciSyncAttrList: Pipeline manager NvSciSync attribute fill failed for pipeline:0

Can you give give me insight as to what is causing this error?

UPDATE: Resolved this issue

1 Like

Hi @VickNV,

I decided to give this version another try and managed to adapt it so it does run without producing any errors. However, I am still facing two issues:

  1. I still have to manually clean up the NvSciIpc resources after each run before I can use them again.
  2. It seems that on the cuda memory on the receiving side does always contain only 1s, independent of what is sent by the other side.

Are these things known bugs in the current implementation or am I doing something wrong?

The fix will be in the next release mentioned in my post.

What’s “1s”? Could you create another topic with the details of how to reproduce and observe the issue? Thanks!

Hi @VickNV

I have a follow up question about combining NvSci and SIPL.
I am attempting to register my image groups using RegisterImageGroups() but I am getting the following error:
: CNvMCamera.cpp: 508: RegisterImageGroups: Number of image groups should be at least :3

Where does this constraint for number of image groups come from?
I understand that I need to setup my image groups after all the packets have been registered by the pool but what if I am only using 1 packet in my stream?

In this case I am still told to make at least 3 image groups and when attempting to register I get the following error:
: CNvMBufferPool.hpp: 101: Init: GetSciBuffer failed
: CNvMSensorPipeline.cpp: 130: RegisterImageGroups: ICP buffer pool initialize failed
: CNvMCamera.cpp: 546: RegisterImageGroups: Pipeline register imagegroups failed for pipeline:0

This is probably because the stream I built only contains 1 packet but what can I do to resolve this? Does my stream have to be minimum 3 packets?

Hi @jaisood,

The original topic is extensive. Please create a new topic for your specific issue and let us know. Thanks!

1 Like