NVIDIA Tegra
NVIDIA DRIVE OS 5.1 Linux SDK

Developer Guide
5.1.6.0 Release


 
NvSciSync
 
For Additional Information
Definitions
NvSciSync Functions for Specific Imaging Components
Code Examples
The NvMedia APIs provide true hardware acceleration of image processing using hardware engines on Jetson devices.
NvSciSync extends the NvMedia imaging components to support synchronization among the imaging components, NVIDIA® CUDA® components, and NvSciSync-based applications. NvSciSync supports imaging components that are targeted for Advanced Driver Assistance Systems (ADAS) and autonomous application development. They do not support NvMedia video components.
Imaging components that have NvSciSync extensions support:
Accepting an NvSciSyncFence object when the NvMedia engine is used as a waiter
Returning an NvSciSyncFence object when the NvMedia engine is used as a signaler
An NvSciSyncFence object is a snapshot of an NvSciSync object’s state.
For Additional Information
See these sources for additional information about NvSciSync and related topics:
NvSciSync: NvSciSync User Guide
NvMedia image processing and the components of the NvMedia image processing pipeline: the NvMedia Architecture topic in this document
Definitions
This section defines some terms that are specific to NvSciSync operations to NvMedia.
Frame: The smallest unit of data that a hardware engine acceleration API can operate on.
SOF Fence: Start of frame fence, a fence whose expiry indicates the start of engine processing.
EOF Fence: End of frame fence, a fence whose expiry indicates that processing is complete and an output frame is ready to be used.
PRE Fence: A fence on which the start of engine processing is blocked until the expiry of the fence.
NvSciSync Functions for Specific Imaging Components
This section gives an overview of the NvSciSync functions supported for various NvMedia imaging components (2D, ICP, etc.).
NvSciSync supports a group of functions to each of several imaging components: NvMedia2D, NvMediaICP, etc. The groups of functions have parallel names. For example, NvMediaXXRegisterNvSciSyncObj() registers an NvSciSync object with a component, where XX is 2D for NvMedia2D, ICP for NvMediaICP, etc.
NvSciSync supports the following functions for each component, with a few exceptions detailed below:
Query a component’s NvSciSyncObj attributes for waiting or signaling.
Call NvMediaXXFillNvSciSyncAttrList() to query the NvSciSync attributes of component XX. The function sets (fills) the attributes in memory provided by the caller. NvSciSync objects allocated with such NvSciSyncAttrList objects are only accepted by component XX functions.
Register and unregister an NvSciSync object.
Call NvMediaXXRegisterNvSciSyncObj() to register NvSciSyncObj objects with component XX. You must register every NvSciSyncObj that component XX is to use.
During teardown, call NvMediaXXUnRegisterNvSciSyncObj() to unregister the registered NvSciSyncObj objects with component XX.
Set an NvSciSyncObj object for SOF usage with the component.
Call NvMediaXXSetNvSciSyncObjforSOF() to tell component XX to use a particular NvSciSyncObj for signaling start of frame (SOF). You must call this function before you call any of the component’s main image processing functions.
Set an NvSciSyncObj for EOF usage with the component.
Call NvMediaXXSetNvSciSyncObjforEOF() to tell component XX to use a particular NvSciSyncObj for signaling end of frame (EOF). You must call this function before you call any of the component’s main image processing functions.
Wait for an NvSciSyncFence.
Call NvMediaXXInsertPreNvSciSyncFence() to tell component XX to wait on an NvSciSyncFence before actually starting image processing. You must call this function before you call any of the component’s main image processing functions.
Get an NvSciSyncFence SOF.
Call NvMediaXXGetSOFNvSciSyncFence() to get an NvSciSyncFence from component XX whose expiry indicates that the last submitted image processing request has started. You must call this function only after you call the component’s main image processing functions.
Get an NvSciSyncFence EOF.
Call NvMediaXXGetEOFNvSciSyncFence() to get an NvSciSyncFence from component XX whose expiry indicates that the last submitted image processing request has completed. You must call this function only after you call the component’s main image processing functions.
The functions are implemented for each of the following NvMedia imaging components.
Component
Notes
2D
 
LDC
 
ICP
A typical capture use case with SOF Fence is, for example, where ICP output is fed to CUDA engine for processing.
ISP
the ISP hardware engine does not generate any fence to indicate the start of a frame.
IEP
 
OFST
 
Not every function is implemented for every imaging component. The following table the functions that are implemented for each supported component.
Generic function
Description
2D
LDC
ICP
ISP
IEP
OFST
NvMediaXXFillNvSciSyncAttrList()
Fills attributes in an NvSciSyncAttrList.
X
X
X
X
X
X
NvMediaXXRegisterNvSciSyncObj()
Registers an NvSciSyncObj with a component object.
X
X
X
X
X
X
NvMediaXXUnregisterNvSciSyncObj()
Unregisters an NvSciSyncObj with a component object.
X
X
X
X
X
X
NvMediaXXSetNvSciSyncObjforSOF()
Specifies an NvSciSyncObj to use as an SOF NvSciSyncFence.
X
NvMediaXXSetNvSciSyncObjforEOF()
Specifies an NvSciSyncObj to use as an EOF NvSciSyncFence.
X
X
X
X
X
X
NvMediaXXInsertPreNvSciSyncFence()
Sets an NvSciSyncFence as a prefence.
X
X
X
X
X
X
NvMediaXXGetSOFNvSciSyncFence()
Gets an EOF NvSciSyncFence for an NvMediaXXBlitEx() operation.
X
NvMediaXXGetEOFNvSciSyncFence()
Gets an EOF NvSciSyncFence for an NvMediaXXBlitEx() operation.
X
X
X
X
X
X
Code Examples
This section presents example code that illustrates NvSciSync operations for the 2D component. It can also be used as a model for NvSciSync operations in the other imaging components.
/***** Init Time *****/
 
NvSciSyncModule nvscisyncModule;
NvSciError nverr;
NvSciSyncAttrList nvscisyncattr_w;
NvSciSyncAttrList nvscisyncattr_s;
NvSciSyncAttrList nvscisyncattr_unreconciled_h[2];
NvSciSyncAttrList nvscisyncattr_reconciled;
NvSciSyncAttrList ConflictAttrList;
NvSciSyncFence eofnvscisyncfence = NV_SCI_SYNC_FENCE_INITIALIZER;
NvSciSyncObj nvscisyncEOF, nvscisyncpre;
nvm2dhdl = NvMedia2DCreate(nvmdevice);
nverr = NvSciSyncModuleOpen(&nvscisyncModule);
/***** NvMedia 2D as a signaler *****/
nverr = NvSciSyncAttrListCreate(nvscisyncModule, &nvscisyncattr_s);
nvmstatus = NvMedia2DFillNvSciSyncAttrList(nvscisyncattr_s, NVMEDIA_SIGNALER);
nvscisyncattr_unreconciled_h[0] = nvscisyncattr_s;
nvscisyncattr_unreconciled_h[1] = get attribute list from the appropriate waiter;
nverr = NvSciSyncAttrListReconcile(nvscisyncattr_unreconciled_h[],
2 , &nvscisyncattr_reconciled, &ConflictAttrList);
nverr = NvSciSyncObjAlloc(nvscisyncattr_reconciled, &nvscisyncEOF);
/***** NvMedia 2D as a waiter *****/
 
nverr = NvSciSyncAttrListCreate(&nvscisyncattr_w);
nvmstatus = NvMedia2DFillNvSciSyncAttrList(nvscisyncattr_w, NVMEDIA_WAITER);
/*If the signaler is also in the same process as the 2D Waiter, then
NvSciSyncAttrListReconcileAndObjAlloc or NvSciSyncAttrListReconcile and
NvSciSyncObjAlloc API pair has/have to be used to allocate nvscisyncpre NvSciScynObject.
If the signaler is in a different process/VM than the 2D Waiter, then
NvSciSyncAttrList export/import APIs and NvSciSyncObjIpc Export/Import APIs
have to be used allocate a NvSciSyncObject on signaler and waiter sides.
nvscisyncpre is the imported NvSciSyncObject on the waiter side */
/*All the NvSciSyncObjects(NvSciSyncObjects associated with PreFences, EOFFence
) which will be used by NvMedia2D must be registered upfront. */
 
/***** Start of registration of NvSciSync objects *****/
 
nvmstatus = NvMedia2DRegisterNvSciSyncObj(nvm2dhdl, NVMEDIA_EOFSYNCOBJ, nvscisyncEOF);
/* Register all the NvSciSync objects which will be used to generate prefences for
NvMedia2DBlit operation. nvscisyncpre is one such Pre NvSciSync object */
nvmstatus = NvMedia2DRegisterNvSciSyncObj(nvm2dhdl, NVMEDIA_PRESYNCOBJ, nvscisyncpre);
 
/***** End of Registration of NvSciSync Objects *****.
/*Allocate a NvMediaImage for input, say inputimg */
/*Allocate a NvMediaImage for output, say outputimg */
/***** End of init-time and start of run-time *****/
 
nvmstatus = NvMedia2DSetNvSciSyncObjforEOF(nvm2dhdl, nvscisyncEOF);
/*Get a nvscisyncfence from somewhere(maybe a eofnvscisyncfence of
some other engine operation) which neeeds to be inserted as prefence
for 2DBlit operation. prenvscisyncfence is one such NvSciSyncFence. */
nvmstatus = NvMedia2DInsertPreNvSciSyncFence(nvm2dhdl, prenvscisyncfence);
nvmstatus = NvMedia2DBlitEx(nvm2dhdl, outputimg, NULL, inputimg, NULL,
2dblitparams, paramsout);
nvmstatus = NvMedia2DGetEOFNvSciSyncFence(nvm2dhdl, nvscisyncEOF, &eofnvscisyncfence);
/*eofnvscisyncfence may be used as prefence for some other engine operation
or application can decide to wait on CPU till their expiry using NvSciSyncWait API. */
/***** End of Run time *****/
 
/***** Unregister registered NvSciSync objects *****/
 
nvmstatus = NvMedia2DUnRegisterNvSciSyncObj(nvm2dhdl, nvscisyncEOF);
nvmstatus = NvMedia2DUnRegisterNvSciSyncObj(nvm2dhdl, nvscisyncpre);
NvSciSyncAttrListFree(nvscisyncattr_w);
NvSciSyncAttrListFree(nvscisyncattr_s);
NvSciSyncAttrListFree(nvscisyncattr_reconciled);
NvSciSyncObjFree(nvscisyncEOF);
NvSciSyncObjFree(nvscisyncpre);
NvSciSyncModuleClose(nvscisyncModule);