Build Applications with the AFX SDK#

The SDK includes dependent libraries in external/cuda/lib, which are required to compile and run applications and do not require libraries to be separately installed. Refer to Software Requirements (Windows) or Software Requirements (Linux) for runtime requirements for applications that use the SDK.

Windows#

Add both the core include directory and the selected feature’s include directory to the compiler search path. For Denoiser, these are <AFX_SDK_ROOT>\include and <AFX_SDK_ROOT>\features\nvafxdenoiser\include. The feature header defines selectors such as NVAFX_EFFECT_DENOISER.

To build applications with SDK on Windows, use one of the following methods:

  • Statically link the library in Visual Studio by using the .lib file (NVAudioEffects.lib).

    For more information, refer to Build the Sample Application.

  • Load the SDK DLL at runtime by using LoadLibrary/GetProcAddress.

    For example, NvAFX_CreateEffect can be called in the following way:

    #include <Windows.h>
    #include <nvAudioEffects.h>
    #include <nvAFXDenoiser.h>  // From features/nvafxdenoiser/include
    
    typedef NvAFX_Status (*NVAFX_CREATEEFFECT)(NvAFX_EffectSelector, NvAFX_Handle*);
    HMODULE module = LoadLibraryW(L"NVAudioEffects.dll");
    if (module == nullptr) {
       // Handle DLL load failure.
    }
    NVAFX_CREATEEFFECT create_effect = reinterpret_cast<NVAFX_CREATEEFFECT>(
       GetProcAddress(module, "NvAFX_CreateEffect"));
    if (create_effect == nullptr) {
       FreeLibrary(module);
       // Handle missing API entry point.
    }
    NvAFX_Handle nv_handle = nullptr;
    NvAFX_Status status = create_effect(NVAFX_EFFECT_DENOISER, &nv_handle);
    
    // Similarly for other APIs
    FreeLibrary(module);
    

Previous releases of TensorRT might have a bug where cuBLAS is not unloaded after you unload the SDK DLL, and this issue might cause a memory leak.

To work around this issue, run the following workaround:

int maxLoopCount = 5;

while (maxLoopCount--) {
   HMODULE cublas_handle = GetModuleHandleW(L"cublasLt64_11");
   if (!cublas_handle) break;
   if (FreeLibrary(cublas_handle) == false) break;
}

Linux#

To build applications with SDK on Linux, use one of the following methods:

  • At compile time, link to the core SDK library, libnv_audiofx.so. For example, with gcc:

    gcc -L "../../nvafx/lib" -l "nv_audiofx" -L "../../external/cuda/lib/" -I "../../nvafx/include" source.c
    
  • Dynamically load the core SDK library, libnv_audiofx.so, by using dlopen/dlsym with the correct library paths set (via LD_LIBRARY_PATH or similar). For more information, refer to the dlopen(3)/dlsym(3) man pages.

    For example:

    #include <cassert>
    #include <dlfcn.h>
    #include <nvAudioEffects.h>
    #include <nvAFXDenoiser.h>  // From the downloaded Denoiser feature
    
    // Typedefs for functions; similarly define for other functions required
    
    typedef NvAFX_Status (*fnNvAFX_CreateEffect)(NvAFX_EffectSelector code, NvAFX_Handle* effect);
    
    // Load library and bind
    
    // Note: ensure that external/cuda/lib is in library path, or fix via RPATH/similar
    
    void* handle = dlopen("libnv_audiofx.so", RTLD_LAZY);
    
    assert(handle);
    
    fnNvAFX_CreateEffect f = (fnNvAFX_CreateEffect) dlsym(handle, "NvAFX_CreateEffect");
    
    assert(f);
    
    // Call functions
    
    NvAFX_Handle effect;
    
    auto ret = f(NVAFX_EFFECT_DENOISER, &effect);
    
    assert(ret == NVAFX_STATUS_SUCCESS);