Comprehensive GStreamer plugin that can dynamically load and execute CUDA kernels at runtime. This implementation will include the plugin source code, example kernels, and instructions for building and using it.
I've created a comprehensive solution for dynamically loading and executing CUDA kernels within GStreamer pipelines. This implementation allows you to swap CUDA kernels at runtime without rebuilding plugins or applications.
-
GStreamer Plugin (gstcudakernel.c)
- A complete GStreamer plugin that loads and executes CUDA kernels at runtime
- Supports dynamic parameter configuration through JSON
- Compatible with both system memory and CUDA memory buffers
- Automatic kernel hot-reloading when source files change
-
Sample CUDA Kernels (kernels.cu)
- Ready-to-compile collection of common image processing kernels:
- Grayscale conversion
- Brightness adjustment
- Color inversion
- Gaussian blur
- Edge detection
- Chroma key (green screen)
- Ready-to-compile collection of common image processing kernels:
-
Build Instructions
- Step-by-step guide to compile and install the plugin
- Instructions for compiling CUDA kernels into PTX/CUBIN format
- GStreamer pipeline examples for different use cases
The plugin loads kernel code from PTX or CUBIN files, allowing you to:
- Change algorithms without rebuilding the plugin
- Hot-swap kernels during runtime when files are modified
- Support multiple GPU architectures with appropriate compilation flags
- JSON-based parameter passing between GStreamer and CUDA kernels
- Runtime parameter adjustment without pipeline restarts
- Support for various parameter types (integers, floats, booleans)
- Zero-copy integration with GStreamer's CUDA memory system
- Automatic handling of both system and GPU memory
- Stream-based asynchronous execution
- Thread block size configuration for performance tuning
- Compatible with existing NVIDIA GStreamer elements (nvh264dec, cudaupload, etc.)
- Designed for high-performance video processing pipelines
edge_detect
gst-launch-1.0 videotestsrc ! video/x-raw,format=RGBA ! cudakernel kernel-path=kernels.ptx kernel-function=edge_detect kernel-parameters="{\"threshold\": 50}" ! videoconvert ! autovideosinblur
gst-launch-1.0 videotestsrc ! video/x-raw,format=RGBA ! cudakernel kernel-path=kernels.ptx kernel-function=blur kernel-parameters="{\"radius\": 50}" ! videoconvert ! autovideosinkThis implementation bridges the powerful parallel processing capabilities of CUDA with GStreamer's flexible media framework, enabling efficient video processing for a wide range of applications from simple filters to complex computer vision systems.
gst-cudakernel/ # Main project directory
│
├── src/ # Source code directory
│ └── gstcudakernel.c # Plugin implementation code
│
├── meson.build # Meson build configuration
│
├── kernels/ # CUDA kernel directory
│ ├── kernels.cu # Source code for CUDA kernels
│ ├── kernels.ptx # Compiled PTX assembly (platform-independent)
│ └── kernels.cubin # Compiled binary (architecture-specific, optional)
│
├── examples/ # Example applications
│ └── video_processor.py # Sample GTK application with effect switching
│
├── builddir/ # Build output directory (created during build)
│ ├── libgstcudakernel.so # Compiled plugin library
│ └── ... # Other build artifacts
│
└── install/ # Optional local installation directory
└── lib/
└── gstreamer-1.0/
└── libgstcudakernel.so
- src/gstcudakernel.c: The main C source file that implements the GStreamer plugin. It handles loading CUDA kernels, memory management, and integration with GStreamer.
- kernels/kernels.cu: Contains the CUDA kernel implementations (grayscale, blur, edge detection, etc.)
- kernels/kernels.ptx: The compiled PTX assembly output from NVCC (platform-independent intermediate representation)
- kernels/kernels.cubin: Optional architecture-specific binary for optimal performance on specific GPUs
- meson.build: Meson build configuration that defines how to compile the plugin
- examples/video_processor.py: A complete Python+GTK application demonstrating real-time video processing with the plugin
-
Create the directory structure:
mkdir -p gst-cudakernel/src gst-cudakernel/kernels gst-cudakernel/examples
-
Copy the source files into their respective directories:
- Copy gstcudakernel.c to src/
- Copy kernels.cu to kernels/
- Copy video_processor.py to examples/
- Create meson.build in the root directory
-
Compile the CUDA kernels:
cd gst-cudakernel/kernels nvcc -ptx -arch=sm_52 -o kernels.ptx kernels.cu -
Build and install the GStreamer plugin:
cd gst-cudakernel meson setup builddir cd builddir ninja sudo ninja install # System-wide installation