1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
3 @page core_usecase5 Context
6 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
8 The NVIDIA<sup>®</sup> DriveWorks
9 Context module stores all global components, including:
10 - Pointer logging callbacks.
11 - NvMedia Device instance.
13 - Platform information.
14 - Virtual file system.
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.
19 @section core_context_initalization Context Initialization
21 The DriveWorks SDK context must be initialized before any other DriveWorks module.
22 A typical context initialization looks like the following:
25 #include <dw/core/Context.h>
26 #include <dw/core/VersionCurrent.h>
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
35 // Initialize DriveWorks context
36 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
42 // release SDK context
43 dwRelease(&sdkContext);
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.
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.
56 During the initialization phase, DriveWorks initializes:
57 - NVIDIA<sup>®</sup> CUDA<sup>®</sup>
58 - DLA (applies only to NVIDIA DRIVE<sup>™</sup> platforms)
59 - OpenGL extensions, if OpenGL is available
60 - NvMedia components, if running on an NVIDIA DRVE<sup>™</sup> platform
63 @section core_context_currenttime Current System Time
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.
72 // get current system time
74 dwContext_getCurrentTime(&now, sdkContext);
76 printf("Time now is %f [sec]\n", now / 1e6);
79 @note The returned time is based on UNIX Epoch time.
81 @section core_context_pva Programmable Vision Accelerator
83 An SDK context provides the possibility to enable PVA (Programmable Vision Accelerator) on
84 NVIDIA DRVE<sup>™</sup> platforms.
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:
92 // other initialization parameters
96 contextParams.enablePVA = true;
98 // Initialize DriveWorks context
99 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
105 // release SDK context
106 dwRelease(&sdkContext);
109 @note There can be maximum 8 SDK contexts with PVA running simultaneously on
110 an NVIDIA DRVE<sup>™</sup> platform.
112 @section core_context_cuda_task_graph CUDA Task-Graph
114 An SDK context can be initialized with CUDA Task-Graph enabled.
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:
122 // other initialization parameters
125 // Enable CUDA Task-Graph
126 contextParams.enableCudaTaskGraph = true;
128 // Initialize DriveWorks context
129 dwInitialize(&sdkContext, DW_VERSION, &contextParams);
135 // release SDK context
136 dwRelease(&sdkContext);