DriveWorks SDK Reference
3.5.78 Release
For Test and Development only

core/docs/usecase5.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
2 
3 @page core_usecase5 Context
4 @tableofcontents
5 
6 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
7 
8 The NVIDIA<sup>&reg;</sup> DriveWorks
9 Context module stores all global components, including:
10 - Pointer logging callbacks.
11 - NvMedia Device instance.
12 - Global timesource.
13 - Platform information.
14 - Virtual file system.
15 
16 Every module requires a handle to a valid context instance. When a module is
17 created within a certain context, it functions only within that context. Outside of this context, it does not exist.
18 
19 @section core_context_initalization Context Initialization
20 
21 The DriveWorks SDK context must be initialized before any other DriveWorks module.
22 A typical context initialization looks like the following:
23 
24 ```{.cpp}
25 #include <dw/core/Context.h>
26 #include <dw/core/VersionCurrent.h>
27 
28 ...
29 
30 // initialize SDK context, using data folder
31 dwContextParameters contextParams = {};
32 contextParams.dataPath = "path/to/location/of/resource.pak/folder";
33 contextParams.eglDisplay = getEGLDisplay(); // on DRIVE platforms this should point to right EGL display, on x86 just nullptr
34 
35 // Initialize DriveWorks context
36 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
37 
38 ...
39 // do processing
40 ...
41 
42 // release SDK context
43 dwRelease(&sdkContext);
44 ```
45 
46 @note If a `nullptr` is passed for `dataPath`, then a data folder is looked for in typical
47 install locations in relation to the current driveworks library install location.
48 If a data directory is still not found then virtual file system will be unavailable.
49 When that happens, modules that use certain DNN networks will not function properly.
50 
51 When modules call dwInitialize(), they usually pass `DW_VERSION` as the argument
52 that specifies the current DriveWorks API version.
53 dwInitialize() uses that argument to ensure the version of the API headers and the library match.
54 After that, the function initializes all context subcomponents.
55 
56 During the initialization phase, DriveWorks initializes:
57 - NVIDIA<sup>&reg;</sup> CUDA<sup>&reg;</sup>
58 - DLA (applies only to NVIDIA DRIVE<sup>&trade;</sup> platforms)
59 - OpenGL extensions, if OpenGL is available
60 - NvMedia components, if running on an NVIDIA DRVE<sup>&trade;</sup> platform
61 
62 
63 @section core_context_currenttime Current System Time
64 
65 An SDK context provides access to the common clock used within all SDK modules.
66 For event timestamps, DriveWorks uses a high-resolution monotonic clock with
67 microseconds precision. Sensor samples are an example of event timestamps. Any
68 module accepting `dwTime_t` as input argument, assumes the time is in the right
69 units and is from the same domain.
70 
71 ```{.cpp}
72 // get current system time
73 dwTime_t now = 0;
74 dwContext_getCurrentTime(&now, sdkContext);
75 
76 printf("Time now is %f [sec]\n", now / 1e6);
77 ```
78 
79 @note The returned time is based on UNIX Epoch time.
80 
81 @section core_context_pva Programmable Vision Accelerator
82 
83 An SDK context provides the possibility to enable PVA (Programmable Vision Accelerator) on
84 NVIDIA DRVE<sup>&trade;</sup> platforms.
85 
86 If PVA is not enabled, modules that execute on PVA will not work properly.
87 PVA can be enabled during context initialization like this:
88 
89 ```{.cpp}
90 
91 ...
92 // other initialization parameters
93 ...
94 
95 // Enable PVA
96 contextParams.enablePVA = true;
97 
98 // Initialize DriveWorks context
99 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
100 
101 ...
102 // do processing
103 ...
104 
105 // release SDK context
106 dwRelease(&sdkContext);
107 ```
108 
109 @note There can be maximum 8 SDK contexts with PVA running simultaneously on
110 an NVIDIA DRVE<sup>&trade;</sup> platform.
111 
112 @section core_context_cuda_task_graph CUDA Task-Graph
113 
114 An SDK context can be initialized with CUDA Task-Graph enabled.
115 
116 If it is enabled, CUDA Task-Graph will be used where applicable; such as, DNN inference for models that support this sort of execution.
117 CUDA Task-Graph can be enabled during context initialization like this:
118 
119 ```{.cpp}
120 
121 ...
122 // other initialization parameters
123 ...
124 
125 // Enable CUDA Task-Graph
126 contextParams.enableCudaTaskGraph = true;
127 
128 // Initialize DriveWorks context
129 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
130 
131 ...
132 // do processing
133 ...
134 
135 // release SDK context
136 dwRelease(&sdkContext);
137 ```
138