Implementation:NVIDIA DALI CMake Plugin Build
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Custom_Operators, Build_Systems, CMake |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete CMake build configuration provided by the NVIDIA DALI NaiveHistogram example for compiling a custom operator plugin into a shared library (libnaivehistogram.so) that links against the installed DALI package.
Description
The CMakeLists.txt for the NaiveHistogram plugin is the reference build configuration for custom DALI operators. It performs the following steps:
- Sets the minimum CMake version to 3.25.2 and targets CUDA architectures 80 (Ampere) and 90 (Hopper).
- Declares the project with CUDA, CXX, and C language support.
- Enforces C++20 and CUDA 20 standards.
- Adds CUDA toolkit include directories via CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES.
- Discovers DALI's library directory by running python -c "import nvidia.dali as dali; print(dali.sysconfig.get_lib_dir())" and stores it in DALI_LIB_DIR.
- Discovers DALI's compile flags by running python -c "import nvidia.dali as dali; print(' '.join(dali.sysconfig.get_compile_flags()))" and appends them to CMAKE_CXX_FLAGS and CMAKE_CUDA_FLAGS.
- Adds DALI_LIB_DIR to the linker search path via link_directories().
- Defines PLUGIN_SOURCES as the list of .cc and .cu files.
- Creates the shared library target naivehistogram and links it against dali.
Usage
To build the plugin:
cd docs/examples/custom_operations/custom_operator/naive_histogram
cmake -B build
cmake --build build
The resulting libnaivehistogram.so will be in the build/ directory.
Code Reference
Source Location
- Repository: NVIDIA DALI
- File:
docs/examples/custom_operations/custom_operator/naive_histogram/CMakeLists.txt(lines 1-37)
Signature
cmake_minimum_required(VERSION 3.25.2)
set(CMAKE_CUDA_ARCHITECTURES "80;90")
project(naive_histogram_plugin LANGUAGES CUDA CXX C)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_library(naivehistogram SHARED ${PLUGIN_SOURCES})
target_link_libraries(naivehistogram dali)
Import
# No import needed; this is a standalone CMake configuration file.
# Dependencies are resolved at configure time via Python introspection:
execute_process(
COMMAND python -c "import nvidia.dali as dali; print(dali.sysconfig.get_lib_dir())"
OUTPUT_VARIABLE DALI_LIB_DIR)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| PLUGIN_SOURCES | CMake variable (list of file paths) | Yes | List of C++ and CUDA source files to compile. In the example: naive_histogram.cc and naive_histogram.cu. |
| CMAKE_CUDA_ARCHITECTURES | CMake variable (string) | Yes | Semicolon-separated list of CUDA compute capabilities to target (e.g., "80;90"). |
| nvidia.dali (Python package) | Installed package | Yes | Must be importable by Python at configure time. Provides sysconfig.get_lib_dir() and sysconfig.get_compile_flags(). |
| CUDA toolkit | System installation | Yes | Provides nvcc compiler and CUDA runtime headers via CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES. |
Outputs
| Name | Type | Description |
|---|---|---|
| libnaivehistogram.so | Shared library file | Dynamically loadable plugin containing the compiled operator. Contains self-registering static initializers for the operator schema and factory. |
Usage Examples
Example: Complete CMakeLists.txt
cmake_minimum_required(VERSION 3.25.2)
set(CMAKE_CUDA_ARCHITECTURES "80;90")
project(naive_histogram_plugin LANGUAGES CUDA CXX C)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CUDA_STANDARD 20)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
include_directories(SYSTEM "${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}")
execute_process(
COMMAND python -c "import nvidia.dali as dali; print(dali.sysconfig.get_lib_dir())"
OUTPUT_VARIABLE DALI_LIB_DIR)
string(STRIP ${DALI_LIB_DIR} DALI_LIB_DIR)
execute_process(
COMMAND python -c "import nvidia.dali as dali; print(\" \".join(dali.sysconfig.get_compile_flags()))"
OUTPUT_VARIABLE DALI_COMPILE_FLAGS)
string(STRIP ${DALI_COMPILE_FLAGS} DALI_COMPILE_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DALI_COMPILE_FLAGS} ")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${DALI_COMPILE_FLAGS} ")
link_directories("${DALI_LIB_DIR}")
set(PLUGIN_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/naive_histogram.cc
${CMAKE_CURRENT_SOURCE_DIR}/naive_histogram.cu
)
add_library(naivehistogram SHARED ${PLUGIN_SOURCES})
target_link_libraries(naivehistogram dali)
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment