DriveWorks SDK Reference
3.0.4260 Release
For Test and Development only

/dvs/git/dirty/gitlab-master_av/dw/sdk/doc/tutorials/helloworld/dwx_hello_world.md
Go to the documentation of this file.
1 # Copyright (c) 2019-2020 NVIDIA CORPORATION. All rights reserved.
2 
3 @page dwx_hello_world Hello World Application
4 
5 @note SW Release Applicability: This tutorial is applicable to modules in both **NVIDIA DriveWorks** and **NVIDIA DRIVE Software** releases.
6 
7 The following minimal tutorial will guide through writing and building your first NVIDIA<sup>&reg;</sup> DriveWorks based application on a Linux desktop machine.
8 
9 ## Coding
10 
11 The first thing to do when building an application based on DriveWorks is to initialize its context:
12 ```{.cpp}
13 dwContextHandle_t sdk = DW_NULL_HANDLE;
14 dwContextParameters sdkParams = {};
15 dwVersion sdkVersion;
16 dwGetVersion(&sdkVersion);
17 dwInitialize(&sdk, sdkVersion, &sdkParams);
18 ```
19 
20 The header for the context can be included as:
21 ```{.cpp}
22 #include <dw/core/Context.h>
23 ```
24 
25 Now we can for example figure out how many GPUs are available on the host machine:
26 ```{.cpp}
27 int32_t gpuCount;
28 dwContext_getGPUCount(&gpuCount, sdk);
29 std::cout << "Available GPUs: " << gpuCount << std::endl;
30 ```
31 
32 Last thing to do before exiting the program is to release the context:
33 ```{.cpp}
34 dwRelease(&sdk);
35 ```
36 
37 For your reference this is what the full program will look like:
38 ```{.cpp}
39 #include <iostream>
40 #include <dw/core/Context.h>
41 
42 int main(int argc, char **argv)
43 {
44 
45  dwContextHandle_t sdk = DW_NULL_HANDLE;
46 
47  // instantiate Driveworks SDK context
48  dwContextParameters sdkParams = {};
49  dwVersion sdkVersion;
50  dwGetVersion(&sdkVersion);
51  dwInitialize(&sdk, sdkVersion, &sdkParams);
52 
53  std::cout << "Context of Driveworks SDK successfully initialized." <<std::endl;
54  std::cout << "Version: " << sdkVersion.major << "." << sdkVersion.minor << "." << sdkVersion.patch << std::endl;
55 
56  int32_t gpuCount;
57  dwContext_getGPUCount(&gpuCount, sdk);
58  std::cout << "Available GPUs: " << gpuCount << std::endl;
59 
60  // release Driveworks SDK context
61  dwRelease(&sdk);
62 
63  return 0;
64 }
65 ```
66 
67 ## Building and Executing
68 
69 This application can be built with gcc using the following command:
70 
71  gcc -I/usr/local/driveworks/include/ -I/usr/local/cuda/include helloworld.cpp -ldriveworks -L/usr/local/driveworks/lib/ -lstdc++ -o helloworld
72 
73 Afterwords when executing <b>./helloworld</b> you should get an output similiar to:
74 
75  Context of Driveworks SDK successfully initialized.
76  Version: 1.0.218
77  Available GPUs: 1
78 
79 @note An extended version of this hello world application is provided, for more information see @ref dwx_hello_world_sample.
80 @note For more complex examples please refer to @ref dwx_samples_section.
81