DriveWorks SDK Reference
4.0.0 Release
For Test and Development only

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