HIP (formerly known as Heterogeneous-computing Interface for Portability) is AMD’s GPU programming API that enables portable, CUDA-like development across both AMD and NVIDIA platforms.
- On AMD GPUs, HIP runs natively via the ROCm stack.
- On NVIDIA GPUs, HIP operates as a thin translation layer over the CUDA runtime and driver APIs.
This allows developers to maintain a single codebase that can target multiple GPU vendors with minimal effort.
Where HIP Is Used
HIP has seen adoption in AMD-focused GPU computing workflows, particularly in environments that require CUDA-like programmability. Examples include:
- PyTorch ROCm backend for deep learning workloads
- Select scientific applications like LAMMPS and GROMACS have experimented with HIP backends for AMD GPU support
- GPU-accelerated media processing on systems that leverage AMD hardware
While HIP adoption has been more limited compared to CUDA, its reach continues to expand as support for AMD GPUs grows across a broader range of use cases.
The Challenge: Compile-Time Platform Lock-in
Despite its cross-vendor goal, HIP still has a fundamental constraint at the build level. As of HIP 6.3, HIP requires developers to statically define their target platform at compile time via macros like:
#define __HIP_PLATFORM_AMD__ // for AMD ROCm
#define __HIP_PLATFORM_NVIDIA__ // for CUDA backend
This leads to two key limitations:
- You must compile separate binaries for AMD and NVIDIA
- A single binary cannot support both platforms simultaneously
- HIP does not support runtime backend switching natively
GstHip’s Solution
To overcome this limitation, GstHip uses runtime backend dispatch through:
dlopen()
on LinuxLoadLibrary()
on Windows
Instead of statically linking against a single HIP backend, GstHip loads both the ROCm HIP runtime and the CUDA driver/runtime API at runtime. This makes it possible to:
- Detect available GPUs dynamically
- Choose the appropriate backend per device
- Even support simultaneous use of AMD and NVIDIA GPUs in the same process
Unified Wrapper API
GstHip provides a clean wrapper layer that abstracts backend-specific APIs via a consistent naming scheme:
hipError_t HipFooBar(GstHipVendor vendor, ...);
The Hip
prefix (capital H
) clearly distinguishes the wrapper from native hipFooBar(...)
functions.
The GstHipVendor
enum indicates which backend to target:
GST_HIP_VENDOR_AMD
GST_HIP_VENDOR_NVIDIA
Internally, each HipFooBar(...)
function dispatches to the correct backend by calling either:
hipFooBar(...)
for AMD ROCmcudaFooBar(...)
for NVIDIA CUDA
These symbols are dynamically resolved via dlopen()
/ LoadLibrary()
,
enabling runtime backend selection without GPU vendor-specific builds.
Memory Interop
All memory interop in GstHip is handled through the hipupload
and hipdownload
elements.
While zero-copy is not supported due to backend-specific resource management and
ownership ambiguity, GstHip provides optimized memory transfers between systems:
- System Memory ↔ HIP Memory: Utilizes HIP pinned memory to achieve fast upload/download operations between host and device memory
- GstGL ↔ GstHip: Uses HIP resource interop APIs to perform GPU-to-GPU memory copies between OpenGL and HIP memory
- GstCUDA ↔ GstHip (on NVIDIA platforms): Since both sides use CUDA memory, direct GPU-to-GPU memory copies are performed using CUDA APIs.
GPU-Accelerated Filter Elements
GstHip includes GPU-accelerated filters optimized for real-time media processing:
hipconvertscale
/hipconvert
/hipscale
: Image format conversion and image scalinghipcompositor
: composing multiple video streams into single video stream
These filters use the same unified dispatch system and are compatible with both AMD and NVIDIA platforms.
Application Integration Support
As of Merge Request!9340, GstHip exposes public APIs that allow applications to access HIP resources managed by GStreamer. This also enables applications to implement custom GstHIP-based plugins using the same underlying infrastructure without duplicating resource management.
Summary of GstHip Advantages
- Single plugin/library binary supports both AMD and NVIDIA GPUs
- Compatible with Linux and Windows
- Supports multi-GPU systems, including hybrid AMD + NVIDIA configurations
- Seamless memory interop with System Memory, GstGL, and GstCUDA
- Provides high-performance GPU filters for video processing
- Maintains a clean API layer via HipFooBar(...) wrappers, enabling backend-neutral development