Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:NVIDIA DALI TF Plugin Loader

From Leeroopedia


Knowledge Sources
Domains TensorFlow_Integration, Data_Pipeline
Last Updated 2026-02-08 16:00 GMT

Overview

Provides the runtime loader that discovers and loads the appropriate DALI TensorFlow plugin shared library (libdali_tf_*.so) matching the installed TensorFlow version.

Description

This module implements the load_dali_tf_plugin function, which serves as the entry point for dynamically loading the DALI TensorFlow native operation library at runtime. The function uses a singleton pattern with a module-level _dali_tf_module variable to ensure the plugin is loaded only once per process.

The loading process first imports nvidia.dali to ensure the DALI shared library is already loaded in the process (a prerequisite for the plugin). It then discovers all libdali_tf*.so files in the same directory as the loader module using glob. The discovered plugins are sorted into a priority order: first the "current" build (compiled from source for the exact environment), then prebuilt binaries matching the installed TensorFlow major.minor version, and finally prebuilt binaries for other TensorFlow versions. Each candidate is attempted via tf.load_op_library, and the first one that loads successfully is used. If all candidates fail, the first encountered NotFoundError is re-raised to provide the most relevant error message.

Usage

This module is the standard way to load the DALI TensorFlow plugin at runtime. It is called internally by the DALI TF plugin Python API (e.g., nvidia.dali.plugin.tf) and should generally not need to be invoked directly by users.

Code Reference

Source Location

Signature

def load_dali_tf_plugin():
    """Discover and load the DALI TF plugin shared library.

    Returns the loaded TensorFlow op library module. Uses singleton
    pattern - subsequent calls return the cached module.

    Returns:
        module: The loaded TF op library module containing 'Dali' and
                'DALIDataset' ops.

    Raises:
        tf.errors.NotFoundError: If no compatible plugin is found.
        Exception: If no plugin .so files exist at all.
    """
    ...

Import

from nvidia.dali_tf_plugin.dali_tf_plugin import load_dali_tf_plugin

I/O Contract

Inputs

Name Type Required Description
(none) - - No arguments; the function auto-discovers plugins based on file location and TF version

Outputs

Name Type Description
_dali_tf_module TF op library module The loaded TensorFlow module containing the "Dali" and "DALIDataset" custom ops, callable via the module's attributes

Usage Examples

Loading the Plugin

from nvidia.dali_tf_plugin.dali_tf_plugin import load_dali_tf_plugin

# Load the DALI TF native ops
dali_tf = load_dali_tf_plugin()

# The module now contains the registered ops
# dali_tf.dali(...)         - Legacy Dali op
# dali_tf.dali_dataset(...) - DALIDataset op

Plugin Discovery Order

# The loader searches for .so files in its own directory:
#   1. libdali_tf_current.so     (built from source for this environment)
#   2. libdali_tf_2_12.so        (prebuilt matching TF 2.12.x)
#   3. libdali_tf_2_11.so, etc.  (prebuilt for other TF versions)
#
# The first one that loads successfully via tf.load_op_library() is used.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment