Initialization is the first critical step for an application to begin utilizing the GPU for computation. This phase involves several essential configurations and checks to ensure that subsequent operations, such as data transfers and kernel launches, can proceed smoothly.
The configuration of the HIP runtime is at the heart of the initialization process. This involves a series of intricate steps designed to establish a stable foundation for future GPU computations. Specifically, HIP runtime initialization handles the following tasks:
Reading environment variables set during startup
Applications can influence the behavior of the HIP runtime through environment variables.
Setting up active and visible devices
This determines which GPUs are available for use by HIP applications.
Loading necessary libraries
The HIP runtime relies on underlying libraries to interface with the GPU hardware.
Setting up internal buffers
These buffers support memory operations and advanced features such as cooperative kernel launches.
Initializing the compiler and HSA runtime
HSA (Heterogeneous System Architecture) is a low-level hardware specification that the HIP runtime must work with.
Error checking
During initialization, the system checks for critical errors such as “insufficient resources” or “no available devices,” which may prevent successful startup.
Once the HIP runtime is configured, the next step is typically to detect and query the GPUs available on the system. This allows the application to determine which accelerators are accessible and to retrieve relevant information about each device, such as its name and memory size.
Finally, for each GPU that will be used by the application, a corresponding context must be created. Contexts are essential for managing GPU resources and executing kernels. Each context represents an independent connection between the CPU (host) and a specific GPU (device). All subsequent operations, such as memory allocation, data transfer, and kernel execution on that GPU, must take place within its associated context.
When a HIP API is called for the first time, the HIP runtime is automatically initialized. This means that in most cases, developers do not need to perform explicit initialization.