Navigation
πŸ’Ύ Data & StorageΒ· 8 min read

GPU-Accelerated Preprocessing

NVIDIA DALI for vision and multimodal workloads β€” moving data transforms from CPU to GPU to eliminate preprocessing bottlenecks.

daligpu-preprocessingvisiondata-pipelineaugmentation

When CPU-based preprocessing can’t keep up with GPU training speed, NVIDIA DALI moves transforms (decode, resize, augment) to the GPU β€” eliminating the CPU bottleneck entirely.


1. The CPU Preprocessing Bottleneck

For vision and multimodal workloads, preprocessing is expensive:

Standard pipeline (CPU):
  Read JPEG β†’ CPU decode (10ms) β†’ CPU resize (5ms) β†’ CPU augment (3ms)
  → CPU→GPU transfer (1ms) → GPU training step (5ms)
  Total: ~24ms, GPU waits 19ms (79% idle!)

DALI pipeline (GPU):
  Read JPEG β†’ GPU decode (0.5ms) β†’ GPU resize (0.3ms) β†’ GPU augment (0.2ms)
  β†’ Already on GPU! β†’ GPU training step (5ms)
  Total: ~6ms, GPU waits <1ms (~83% utilized)

2. NVIDIA DALI Pipeline

from nvidia.dali.pipeline import pipeline_def
import nvidia.dali.fn as fn
import nvidia.dali.types as types

@pipeline_def(batch_size=64, num_threads=4, device_id=0)
def training_pipeline():
    jpegs, labels = fn.readers.file(
        file_root="/data/imagenet/train",
        random_shuffle=True,
    )
    images = fn.decoders.image(jpegs, device="mixed")  # decode on GPU
    images = fn.resize(images, size=[224, 224])
    images = fn.crop_mirror_normalize(
        images,
        mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
        std=[0.229 * 255, 0.224 * 255, 0.225 * 255],
        mirror=fn.random.coin_flip(),
    )
    return images, labels

pipe = training_pipeline()
pipe.build()

Key Benefits

BenefitDetails
GPU decodeJPEG/video decode on GPU (nvJPEG, nvVideoCodec)
Zero CPU bottleneckTransforms run on GPU, no CPU→GPU transfer
PrefetchingAutomatic pipeline prefetch hides I/O
PyTorch integrationDALIGenericIterator wraps DALI as a PyTorch DataLoader

3. When to Use DALI

WorkloadDALI helps?Why
Vision (ImageNet, detection)βœ… Best use caseHeavy decode + augmentation
Video trainingβœ…GPU video decode is much faster
Multimodal (image + text)βœ… For image partText preprocessing stays on CPU
Pure text (LLM pre-training)❌No image decode, tokenization is CPU-efficient
Audio⚠️ LimitedSome audio ops supported

For text-focused data loading, see PyTorch DataLoader and Streaming Datasets.


Self-Check

  • Explain the CPU preprocessing bottleneck for vision workloads
  • Compare CPU vs GPU decode/resize latency
  • Write a DALI pipeline for ImageNet training
  • Identify when DALI helps vs when it’s unnecessary (text vs vision)

References