Loading [MathJax]/jax/output/HTML-CSS/config.js
  • <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>

  • DriveWorks SDK Reference
    5.8.83 Release
    For Test and Development only

    All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    Hello World Application

    The following minimal tutorial will guide through writing and building your first NVIDIA® DriveWorks based application on a Linux desktop machine.

    Coding

    The first thing to do when building an application based on DriveWorks is to initialize its context:

    dwContextParameters sdkParams = {};
    dwVersion sdkVersion;
    dwGetVersion(&sdkVersion);
    dwInitialize(&sdk, sdkVersion, &sdkParams);
    DW_API_PUBLIC dwStatus dwInitialize(dwContextHandle_t *const context, dwVersion const headerVersion, dwContextParameters const *const params)
    Creates and initializes an SDK context.
    struct dwContextObject * dwContextHandle_t
    Context handle.
    Definition: Context.h:82
    A set of parameters that is passed to the SDK to create the context.
    Definition: Context.h:92
    #define DW_NULL_HANDLE
    Definition: Types.h:96
    DW_API_PUBLIC dwStatus dwGetVersion(dwVersion *const version)
    Query the current DriveWorks library version.

    The header for the context can be included as:

    NVIDIA DriveWorks API: Core Methods

    Now we can for example figure out how many GPUs are available on the host machine:

    int32_t gpuCount;
    dwContext_getGPUCount(&gpuCount, sdk);
    std::cout << "Available GPUs: " << gpuCount << std::endl;
    DW_API_PUBLIC dwStatus dwContext_getGPUCount(int32_t *const count, dwContextHandle_t const context)
    Get the available GPU devices count.

    Last thing to do before exiting the program is to release the context:

    dwRelease(sdk);
    DW_API_PUBLIC dwStatus dwRelease(dwContextHandle_t const context)
    Releases the context.

    For your reference this is what the full program will look like:

    #include <iostream>
    int main(int argc, char **argv)
    {
    // instantiate Driveworks SDK context
    dwContextParameters sdkParams = {};
    dwVersion sdkVersion;
    dwGetVersion(&sdkVersion);
    dwInitialize(&sdk, sdkVersion, &sdkParams);
    std::cout << "Context of Driveworks SDK successfully initialized." <<std::endl;
    std::cout << "Version: " << sdkVersion.major << "." << sdkVersion.minor << "." << sdkVersion.patch << std::endl;
    int32_t gpuCount;
    dwContext_getGPUCount(&gpuCount, sdk);
    std::cout << "Available GPUs: " << gpuCount << std::endl;
    // release Driveworks SDK context
    dwRelease(&sdk);
    return 0;
    }
    int32_t major
    Definition: Version.h:63
    int32_t minor
    Definition: Version.h:65
    int32_t patch
    Definition: Version.h:67

    Building and Executing

    This application can be built with gcc using the following command:

        gcc -I/usr/local/driveworks/include/ -I/usr/local/cuda/include helloworld.cpp -ldriveworks -L/usr/local/driveworks/lib/ -lstdc++ -o helloworld
    

    Afterwords when executing ./helloworld you should get an output similiar to:

        Context of Driveworks SDK successfully initialized.
        Version: 1.0.218
        Available GPUs: 1
    
    Note
    An extended version of this hello world application is provided, for more information see Hello World Sample.
    For more complex examples please refer to Samples.
    人人超碰97caoporen国产